Search in sources :

Example 36 with AudioAttributes

use of android.media.AudioAttributes in project robolectric by robolectric.

the class ShadowAudioManager method createAudioPlaybackConfiguration.

protected AudioPlaybackConfiguration createAudioPlaybackConfiguration(AudioAttributes audioAttributes) {
    // use reflection to call package private APIs
    if (RuntimeEnvironment.getApiLevel() >= S) {
        PlayerBase.PlayerIdCard playerIdCard = ReflectionHelpers.callConstructor(PlayerBase.PlayerIdCard.class, ReflectionHelpers.ClassParameter.from(int.class, 0), /* type */
        ReflectionHelpers.ClassParameter.from(AudioAttributes.class, audioAttributes), ReflectionHelpers.ClassParameter.from(IPlayer.class, null), ReflectionHelpers.ClassParameter.from(int.class, 0));
        AudioPlaybackConfiguration config = ReflectionHelpers.callConstructor(AudioPlaybackConfiguration.class, ReflectionHelpers.ClassParameter.from(PlayerBase.PlayerIdCard.class, playerIdCard), ReflectionHelpers.ClassParameter.from(int.class, 0), /* piid */
        ReflectionHelpers.ClassParameter.from(int.class, 0), /* uid */
        ReflectionHelpers.ClassParameter.from(int.class, 0));
        ReflectionHelpers.setField(config, "mPlayerState", AudioPlaybackConfiguration.PLAYER_STATE_STARTED);
        return config;
    } else {
        PlayerBase.PlayerIdCard playerIdCard = ReflectionHelpers.callConstructor(PlayerBase.PlayerIdCard.class, from(int.class, 0), /* type */
        from(AudioAttributes.class, audioAttributes), from(IPlayer.class, null));
        AudioPlaybackConfiguration config = ReflectionHelpers.callConstructor(AudioPlaybackConfiguration.class, from(PlayerBase.PlayerIdCard.class, playerIdCard), from(int.class, 0), /* piid */
        from(int.class, 0), /* uid */
        from(int.class, 0));
        ReflectionHelpers.setField(config, "mPlayerState", AudioPlaybackConfiguration.PLAYER_STATE_STARTED);
        return config;
    }
}
Also used : IPlayer(android.media.IPlayer) AudioPlaybackConfiguration(android.media.AudioPlaybackConfiguration) PlayerBase(android.media.PlayerBase) AudioAttributes(android.media.AudioAttributes)

Example 37 with AudioAttributes

use of android.media.AudioAttributes in project robolectric by robolectric.

the class ShadowAudioManagerTest method getDevicesForAttributes_returnsEmptyListByDefault.

@Test
@Config(minSdk = R)
public void getDevicesForAttributes_returnsEmptyListByDefault() {
    AudioAttributes movieAttribute = new AudioAttributes.Builder().setContentType(AudioAttributes.CONTENT_TYPE_MOVIE).build();
    assertThat(shadowOf(audioManager).getDevicesForAttributes(movieAttribute)).isEmpty();
}
Also used : AudioAttributes(android.media.AudioAttributes) Test(org.junit.Test) Config(org.robolectric.annotation.Config)

Example 38 with AudioAttributes

use of android.media.AudioAttributes in project robolectric by robolectric.

the class ShadowAudioManagerTest method setDevicesForAttributes_overridesSetDefaultDevicesForAttributes.

@Test
@Config(minSdk = R)
public void setDevicesForAttributes_overridesSetDefaultDevicesForAttributes() {
    AudioAttributes movieAttribute = new AudioAttributes.Builder().setContentType(AudioAttributes.CONTENT_TYPE_MOVIE).build();
    shadowOf(audioManager).setDefaultDevicesForAttributes(ImmutableList.of(new Object()));
    ImmutableList<Object> newDevices = ImmutableList.of(new Object(), new Object());
    shadowOf(audioManager).setDevicesForAttributes(movieAttribute, newDevices);
    assertThat(shadowOf(audioManager).getDevicesForAttributes(movieAttribute)).isEqualTo(newDevices);
}
Also used : AudioAttributes(android.media.AudioAttributes) Test(org.junit.Test) Config(org.robolectric.annotation.Config)

Example 39 with AudioAttributes

use of android.media.AudioAttributes in project robolectric by robolectric.

the class ShadowAudioManagerTest method setDevicesForAttributes_updatesDevicesForAttributes.

@Test
@Config(minSdk = R)
public void setDevicesForAttributes_updatesDevicesForAttributes() {
    AudioAttributes movieAttribute = new AudioAttributes.Builder().setContentType(AudioAttributes.CONTENT_TYPE_MOVIE).build();
    ImmutableList<Object> newDevices = ImmutableList.of(new Object());
    shadowOf(audioManager).setDevicesForAttributes(movieAttribute, newDevices);
    assertThat(shadowOf(audioManager).getDevicesForAttributes(movieAttribute)).isEqualTo(newDevices);
}
Also used : AudioAttributes(android.media.AudioAttributes) Test(org.junit.Test) Config(org.robolectric.annotation.Config)

Example 40 with AudioAttributes

use of android.media.AudioAttributes in project robolectric by robolectric.

the class ShadowAudioManagerTest method setDefaultDevicesForAttributes_updatesDevicesForAttributes.

@Test
@Config(minSdk = R)
public void setDefaultDevicesForAttributes_updatesDevicesForAttributes() {
    AudioAttributes movieAttribute = new AudioAttributes.Builder().setContentType(AudioAttributes.CONTENT_TYPE_MOVIE).build();
    ImmutableList<Object> newDevices = ImmutableList.of(new Object());
    shadowOf(audioManager).setDefaultDevicesForAttributes(newDevices);
    assertThat(shadowOf(audioManager).getDevicesForAttributes(movieAttribute)).isEqualTo(newDevices);
}
Also used : AudioAttributes(android.media.AudioAttributes) Test(org.junit.Test) Config(org.robolectric.annotation.Config)

Aggregations

AudioAttributes (android.media.AudioAttributes)46 NotificationChannel (android.app.NotificationChannel)13 Notification (android.app.Notification)11 RemoteException (android.os.RemoteException)10 TargetApi (android.annotation.TargetApi)9 Uri (android.net.Uri)9 NotificationManager (android.app.NotificationManager)6 Test (org.junit.Test)6 Config (org.robolectric.annotation.Config)6 ITransientNotification (android.app.ITransientNotification)5 IRingtonePlayer (android.media.IRingtonePlayer)5 SoundPool (android.media.SoundPool)5 StatusBarNotification (android.service.notification.StatusBarNotification)5 VisibleForTesting (com.android.internal.annotations.VisibleForTesting)5 NotificationChannelGroup (android.app.NotificationChannelGroup)4 PendingIntent (android.app.PendingIntent)3 AudioManager (android.media.AudioManager)3 AudioPlaybackConfiguration (android.media.AudioPlaybackConfiguration)3 RequiresApi (android.support.annotation.RequiresApi)3 Intent (android.content.Intent)2