Package org.robolectric.shadows
Class ShadowAudioManager
java.lang.Object
org.robolectric.shadows.ShadowAudioManager
@Implements(value=android.media.AudioManager.class, looseSignatures=true) public class ShadowAudioManager extends Object
- 
Nested Class Summary
Nested Classes Modifier and Type Class Description static classShadowAudioManager.AudioFocusRequest - 
Field Summary
Fields Modifier and Type Field Description static com.google.common.collect.ImmutableList<Integer>ALL_STREAMSstatic intDEFAULT_MAX_VOLUMEstatic intDEFAULT_VOLUMEstatic intFLAG_NO_ACTIONstatic intINVALID_VOLUMEstatic intMAX_VOLUME_MUSIC_DTMFstatic intMIN_VOLUME - 
Constructor Summary
Constructors Constructor Description ShadowAudioManager() - 
Method Summary
Modifier and Type Method Description protected intabandonAudioFocus(AudioManager.OnAudioFocusChangeListener l)protected intabandonAudioFocusRequest(AudioFocusRequest audioFocusRequest)Provides a mock like interface for the abandonAudioFocusRequest method by storing the request object for later inspection and returning the value specified in setNextFocusRequestResponse.protected voidadjustStreamVolume(int streamType, int direction, int flags)ImplementsAudioManager.adjustStreamVolume(int, int, int).protected voidclearCommunicationDevice()AudioRecordingConfigurationcreateActiveRecordingConfiguration(int sessionId, int audioSource, String clientPackageName)Creates simple active recording configuration.protected AudioPlaybackConfigurationcreateAudioPlaybackConfiguration(AudioAttributes audioAttributes)protected intgenerateAudioSessionId()Provides a mock like interface for theAudioManager.generateAudioSessionId()method by returning positive distinct values, orAudioManager.ERRORif all possible values have already been returned.protected List<AudioPlaybackConfiguration>getActivePlaybackConfigurations()protected List<AudioRecordingConfiguration>getActiveRecordingConfigurations()Returns list of active recording configurations that was set bysetActiveRecordingConfigurations(java.util.List<android.media.AudioRecordingConfiguration>, boolean)or empty list otherwise.protected AudioDeviceInfogetCommunicationDevice()AudioDeviceInfo[]getDevices(int flags)protected List<Object>getDevicesForAttributes(AudioAttributes attributes)Returns the devices associated with the given audio stream.AudioManager.OnAudioFocusChangeListenergetLastAbandonedAudioFocusListener()AudioFocusRequestgetLastAbandonedAudioFocusRequest()ShadowAudioManager.AudioFocusRequestgetLastAudioFocusRequest()protected intgetMode()StringgetParameter(String key)Returns a single parameter that was set viasetParameters(String).protected StringgetParameters(String keys)The expected composition for keys is not well defined.protected intgetRingerMode()protected intgetStreamMaxVolume(int streamType)protected intgetStreamVolume(int streamType)protected floatgetStreamVolumeDb(int streamType, int index, int deviceType)booleanisAnyAudioPolicyRegistered()Returns true if at least one audio policy is registered with this manager, and false otherwise.protected booleanisBluetoothA2dpOn()protected booleanisBluetoothScoAvailableOffCall()protected booleanisBluetoothScoOn()protected booleanisMicrophoneMute()protected booleanisMusicActive()protected booleanisSpeakerphoneOn()protected booleanisStreamMute(int streamType)static booleanisValidRingerMode(int ringerMode)protected booleanisWiredHeadsetOn()protected voidregisterAudioPlaybackCallback(AudioManager.AudioPlaybackCallback cb, Handler handler)Registers callback that will receive changes made to the list of active playback configurations bysetActivePlaybackConfigurationsFor(java.util.List<android.media.AudioAttributes>).protected intregisterAudioPolicy(Object audioPolicy)Registers anAudioPolicyto allow that policy to control audio routing and audio focus.protected voidregisterAudioRecordingCallback(AudioManager.AudioRecordingCallback cb, Handler handler)Registers callback that will receive changes made to the list of active recording configurations bysetActiveRecordingConfigurations(java.util.List<android.media.AudioRecordingConfiguration>,boolean).protected intrequestAudioFocus(AudioFocusRequest audioFocusRequest)Provides a mock like interface for the requestAudioFocus method by storing the request object for later inspection and returning the value specified in setNextFocusRequestResponse.protected intrequestAudioFocus(AudioManager.OnAudioFocusChangeListener l, int streamType, int durationHint)voidsetActivePlaybackConfigurationsFor(List<AudioAttributes> audioAttributes)Sets active playback configurations that will be served byAudioManager.getActivePlaybackConfigurations().voidsetActivePlaybackConfigurationsFor(List<AudioAttributes> audioAttributes, boolean notifyCallbackListeners)Same assetActivePlaybackConfigurationsFor(List), but also notifies callbacks if notifyCallbackListeners is true.voidsetActiveRecordingConfigurations(List<AudioRecordingConfiguration> activeRecordingConfigurations, boolean notifyCallbackListeners)Sets active recording configurations that will be served byAudioManager.getActiveRecordingConfigurations()and notifies callback listeners about that change.protected voidsetBluetoothA2dpOn(boolean on)protected voidsetBluetoothScoOn(boolean isBluetoothScoOn)protected booleansetCommunicationDevice(AudioDeviceInfo communicationDevice)voidsetDefaultDevicesForAttributes(com.google.common.collect.ImmutableList<Object> devices)Sets the devices to use as default for all audio streams.voidsetDevicesForAttributes(AudioAttributes attributes, com.google.common.collect.ImmutableList<Object> devices)Sets the devices associated with the given audio stream.voidsetInputDevices(List<AudioDeviceInfo> inputDevices)voidsetIsBluetoothScoAvailableOffCall(boolean isBluetoothScoAvailableOffCall)voidsetIsMusicActive(boolean isMusicActive)voidsetIsStreamMute(int streamType, boolean isMuted)protected voidsetMicrophoneMute(boolean on)protected voidsetMode(int mode)voidsetNextFocusRequestResponse(int nextResponseValue)voidsetOutputDevices(List<AudioDeviceInfo> outputDevices)protected voidsetParameters(String keyValuePairs)protected voidsetRingerMode(int ringerMode)protected voidsetSpeakerphoneOn(boolean on)voidsetStreamMaxVolume(int streamMaxVolume)voidsetStreamVolume(int streamVolume)protected voidsetStreamVolume(int streamType, int index, int flags)protected voidsetWiredHeadsetOn(boolean on)protected voidunregisterAudioPlaybackCallback(AudioManager.AudioPlaybackCallback cb)Unregisters callback listening to changes made to list of active playback configurations.protected voidunregisterAudioPolicy(Object audioPolicy)protected voidunregisterAudioRecordingCallback(AudioManager.AudioRecordingCallback cb)Unregisters callback listening to changes made to list of active recording configurations. 
- 
Field Details
- 
MAX_VOLUME_MUSIC_DTMF
public static final int MAX_VOLUME_MUSIC_DTMF- See Also:
 - Constant Field Values
 
 - 
DEFAULT_MAX_VOLUME
public static final int DEFAULT_MAX_VOLUME- See Also:
 - Constant Field Values
 
 - 
MIN_VOLUME
public static final int MIN_VOLUME- See Also:
 - Constant Field Values
 
 - 
DEFAULT_VOLUME
public static final int DEFAULT_VOLUME- See Also:
 - Constant Field Values
 
 - 
INVALID_VOLUME
public static final int INVALID_VOLUME- See Also:
 - Constant Field Values
 
 - 
FLAG_NO_ACTION
public static final int FLAG_NO_ACTION- See Also:
 - Constant Field Values
 
 - 
ALL_STREAMS
 
 - 
 - 
Constructor Details
- 
ShadowAudioManager
public ShadowAudioManager() 
 - 
 - 
Method Details
- 
getStreamMaxVolume
 - 
getStreamVolume
 - 
getStreamVolumeDb
@Implementation(minSdk=28) protected float getStreamVolumeDb(int streamType, int index, int deviceType) - 
setStreamVolume
 - 
isBluetoothScoAvailableOffCall
 - 
requestAudioFocus
@Implementation protected int requestAudioFocus(AudioManager.OnAudioFocusChangeListener l, int streamType, int durationHint) - 
requestAudioFocus
Provides a mock like interface for the requestAudioFocus method by storing the request object for later inspection and returning the value specified in setNextFocusRequestResponse. - 
abandonAudioFocus
 - 
abandonAudioFocusRequest
@Implementation(minSdk=26) protected int abandonAudioFocusRequest(AudioFocusRequest audioFocusRequest)Provides a mock like interface for the abandonAudioFocusRequest method by storing the request object for later inspection and returning the value specified in setNextFocusRequestResponse. - 
getRingerMode
 - 
setRingerMode
 - 
isValidRingerMode
 - 
setMode
 - 
getMode
 - 
setStreamMaxVolume
public void setStreamMaxVolume(int streamMaxVolume) - 
setStreamVolume
public void setStreamVolume(int streamVolume) - 
setWiredHeadsetOn
 - 
isWiredHeadsetOn
 - 
setBluetoothA2dpOn
 - 
isBluetoothA2dpOn
 - 
setSpeakerphoneOn
 - 
isSpeakerphoneOn
 - 
setMicrophoneMute
 - 
isMicrophoneMute
 - 
isBluetoothScoOn
 - 
setBluetoothScoOn
 - 
isMusicActive
 - 
getActivePlaybackConfigurations
@Implementation(minSdk=26) protected List<AudioPlaybackConfiguration> getActivePlaybackConfigurations() - 
setParameters
 - 
getParameters
The expected composition for keys is not well defined.For testing purposes this method call always returns null.
 - 
getParameter
Returns a single parameter that was set viasetParameters(String). - 
adjustStreamVolume
ImplementsAudioManager.adjustStreamVolume(int, int, int).Currently supports only the directions
AudioManager.ADJUST_MUTE,AudioManager.ADJUST_UNMUTE,AudioManager.ADJUST_LOWERandAudioManager.ADJUST_RAISE. - 
isStreamMute
 - 
setIsBluetoothScoAvailableOffCall
public void setIsBluetoothScoAvailableOffCall(boolean isBluetoothScoAvailableOffCall) - 
setIsStreamMute
public void setIsStreamMute(int streamType, boolean isMuted) - 
registerAudioPlaybackCallback
@Implementation(minSdk=26) protected void registerAudioPlaybackCallback(AudioManager.AudioPlaybackCallback cb, Handler handler)Registers callback that will receive changes made to the list of active playback configurations bysetActivePlaybackConfigurationsFor(java.util.List<android.media.AudioAttributes>). - 
unregisterAudioPlaybackCallback
@Implementation(minSdk=26) protected void unregisterAudioPlaybackCallback(AudioManager.AudioPlaybackCallback cb)Unregisters callback listening to changes made to list of active playback configurations. - 
getDevicesForAttributes
@Implementation(minSdk=30) protected List<Object> getDevicesForAttributes(AudioAttributes attributes)Returns the devices associated with the given audio stream.In this shadow-implementation the devices returned are either
- devices set through 
setDevicesForAttributes(android.media.AudioAttributes, com.google.common.collect.ImmutableList<java.lang.Object>), or - devices set through 
setDefaultDevicesForAttributes(com.google.common.collect.ImmutableList<java.lang.Object>), or - an empty list.
 
 - devices set through 
 - 
setDevicesForAttributes
public void setDevicesForAttributes(AudioAttributes attributes, com.google.common.collect.ImmutableList<Object> devices)Sets the devices associated with the given audio stream. - 
setDefaultDevicesForAttributes
public void setDefaultDevicesForAttributes(com.google.common.collect.ImmutableList<Object> devices)Sets the devices to use as default for all audio streams. - 
setInputDevices
 - 
setOutputDevices
 - 
setCommunicationDevice
@Implementation(minSdk=31) protected boolean setCommunicationDevice(AudioDeviceInfo communicationDevice) - 
getCommunicationDevice
 - 
clearCommunicationDevice
 - 
getDevices
 - 
setActivePlaybackConfigurationsFor
Sets active playback configurations that will be served byAudioManager.getActivePlaybackConfigurations().Note that there is no public
AudioPlaybackConfigurationconstructor, so the configurations returned are specified by their audio attributes only. - 
setActivePlaybackConfigurationsFor
public void setActivePlaybackConfigurationsFor(List<AudioAttributes> audioAttributes, boolean notifyCallbackListeners)Same assetActivePlaybackConfigurationsFor(List), but also notifies callbacks if notifyCallbackListeners is true. - 
createAudioPlaybackConfiguration
protected AudioPlaybackConfiguration createAudioPlaybackConfiguration(AudioAttributes audioAttributes) - 
setIsMusicActive
public void setIsMusicActive(boolean isMusicActive) - 
getLastAudioFocusRequest
 - 
setNextFocusRequestResponse
public void setNextFocusRequestResponse(int nextResponseValue) - 
getLastAbandonedAudioFocusListener
 - 
getLastAbandonedAudioFocusRequest
 - 
getActiveRecordingConfigurations
@Implementation(minSdk=24) protected List<AudioRecordingConfiguration> getActiveRecordingConfigurations()Returns list of active recording configurations that was set bysetActiveRecordingConfigurations(java.util.List<android.media.AudioRecordingConfiguration>, boolean)or empty list otherwise. - 
registerAudioRecordingCallback
@Implementation(minSdk=24) protected void registerAudioRecordingCallback(AudioManager.AudioRecordingCallback cb, Handler handler)Registers callback that will receive changes made to the list of active recording configurations bysetActiveRecordingConfigurations(java.util.List<android.media.AudioRecordingConfiguration>,boolean). - 
unregisterAudioRecordingCallback
@Implementation(minSdk=24) protected void unregisterAudioRecordingCallback(AudioManager.AudioRecordingCallback cb)Unregisters callback listening to changes made to list of active recording configurations. - 
setActiveRecordingConfigurations
public void setActiveRecordingConfigurations(List<AudioRecordingConfiguration> activeRecordingConfigurations, boolean notifyCallbackListeners)Sets active recording configurations that will be served byAudioManager.getActiveRecordingConfigurations()and notifies callback listeners about that change. - 
createActiveRecordingConfiguration
public AudioRecordingConfiguration createActiveRecordingConfiguration(int sessionId, int audioSource, String clientPackageName)Creates simple active recording configuration. The resulting configuration will returnnullforAudioRecordingConfiguration.getAudioDevice(). - 
registerAudioPolicy
Registers anAudioPolicyto allow that policy to control audio routing and audio focus.Note: this implementation does NOT ensure that we have the permissions necessary to register the given
AudioPolicy.- Returns:
 AudioManager.ERRORif the given policy has already been registered, andAudioManager.SUCCESSotherwise.
 - 
unregisterAudioPolicy
 - 
isAnyAudioPolicyRegistered
public boolean isAnyAudioPolicyRegistered()Returns true if at least one audio policy is registered with this manager, and false otherwise. - 
generateAudioSessionId
Provides a mock like interface for theAudioManager.generateAudioSessionId()method by returning positive distinct values, orAudioManager.ERRORif all possible values have already been returned. 
 -