Search in sources :

Example 1 with AudioPolicy

use of android.media.audiopolicy.AudioPolicy in project robolectric by robolectric.

the class ShadowAudioManager method registerAudioPolicy.

/**
 * Registers an {@link AudioPolicy} to allow that policy to control audio routing and audio focus.
 *
 * <p>Note: this implementation does NOT ensure that we have the permissions necessary to register
 * the given {@link AudioPolicy}.
 *
 * @return {@link AudioManager.ERROR} if the given policy has already been registered, and {@link
 *     AudioManager.SUCCESS} otherwise.
 */
@HiddenApi
@Implementation(minSdk = P)
@RequiresPermission(android.Manifest.permission.MODIFY_AUDIO_ROUTING)
protected int registerAudioPolicy(@NonNull Object audioPolicy) {
    Preconditions.checkNotNull(audioPolicy, "Illegal null AudioPolicy argument");
    AudioPolicy policy = (AudioPolicy) audioPolicy;
    String id = getIdForAudioPolicy(audioPolicy);
    if (registeredAudioPolicies.containsKey(id)) {
        return AudioManager.ERROR;
    }
    registeredAudioPolicies.put(id, policy);
    policy.setRegistration(id);
    return AudioManager.SUCCESS;
}
Also used : AudioPolicy(android.media.audiopolicy.AudioPolicy) HiddenApi(org.robolectric.annotation.HiddenApi) RequiresPermission(android.annotation.RequiresPermission) Implementation(org.robolectric.annotation.Implementation)

Example 2 with AudioPolicy

use of android.media.audiopolicy.AudioPolicy in project robolectric by robolectric.

the class ShadowAudioManager method unregisterAudioPolicy.

@HiddenApi
@Implementation(minSdk = Q)
protected void unregisterAudioPolicy(@NonNull Object audioPolicy) {
    Preconditions.checkNotNull(audioPolicy, "Illegal null AudioPolicy argument");
    AudioPolicy policy = (AudioPolicy) audioPolicy;
    registeredAudioPolicies.remove(getIdForAudioPolicy(policy));
    policy.setRegistration(null);
}
Also used : AudioPolicy(android.media.audiopolicy.AudioPolicy) HiddenApi(org.robolectric.annotation.HiddenApi) Implementation(org.robolectric.annotation.Implementation)

Example 3 with AudioPolicy

use of android.media.audiopolicy.AudioPolicy in project robolectric by robolectric.

the class ShadowAudioManagerTest method registerAudioPolicy_alreadyRegistered_returnsError.

@Test
@Config(minSdk = P)
public void registerAudioPolicy_alreadyRegistered_returnsError() {
    AudioPolicy audioPolicy = new AudioPolicy.Builder(appContext).build();
    audioManager.registerAudioPolicy(audioPolicy);
    assertThat(audioManager.registerAudioPolicy(audioPolicy)).isEqualTo(AudioManager.ERROR);
}
Also used : AudioPolicy(android.media.audiopolicy.AudioPolicy) Test(org.junit.Test) Config(org.robolectric.annotation.Config)

Example 4 with AudioPolicy

use of android.media.audiopolicy.AudioPolicy in project robolectric by robolectric.

the class ShadowAudioManagerTest method registerAudioPolicy_noPreviouslyRegistered_returnsSuccess.

@Test
@Config(minSdk = P)
public void registerAudioPolicy_noPreviouslyRegistered_returnsSuccess() {
    AudioPolicy audioPolicy = new AudioPolicy.Builder(appContext).build();
    assertThat(audioManager.registerAudioPolicy(audioPolicy)).isEqualTo(AudioManager.SUCCESS);
}
Also used : AudioPolicy(android.media.audiopolicy.AudioPolicy) Test(org.junit.Test) Config(org.robolectric.annotation.Config)

Example 5 with AudioPolicy

use of android.media.audiopolicy.AudioPolicy in project robolectric by robolectric.

the class ShadowAudioManagerTest method isAnyAudioPolicyRegistered_afterPolicyRegisteredAndUnregistered_returnsFalse.

@Test
@Config(minSdk = Q)
public void isAnyAudioPolicyRegistered_afterPolicyRegisteredAndUnregistered_returnsFalse() {
    AudioPolicy audioPolicy = new AudioPolicy.Builder(appContext).build();
    audioManager.registerAudioPolicy(audioPolicy);
    audioManager.unregisterAudioPolicy(audioPolicy);
    assertThat(shadowOf(audioManager).isAnyAudioPolicyRegistered()).isFalse();
}
Also used : AudioPolicy(android.media.audiopolicy.AudioPolicy) Test(org.junit.Test) Config(org.robolectric.annotation.Config)

Aggregations

AudioPolicy (android.media.audiopolicy.AudioPolicy)6 Test (org.junit.Test)4 Config (org.robolectric.annotation.Config)4 HiddenApi (org.robolectric.annotation.HiddenApi)2 Implementation (org.robolectric.annotation.Implementation)2 RequiresPermission (android.annotation.RequiresPermission)1