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;
}
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);
}
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);
}
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);
}
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();
}
Aggregations