@Implements(value=android.media.AudioManager.class, looseSignatures=true) public class ShadowAudioManager extends Object
Modifier and Type | Class | Description |
---|---|---|
static class |
ShadowAudioManager.AudioFocusRequest |
Modifier and Type | Field | Description |
---|---|---|
static int[] |
ALL_STREAMS |
|
static int |
DEFAULT_MAX_VOLUME |
|
static int |
DEFAULT_VOLUME |
|
static int |
FLAG_NO_ACTION |
|
static int |
INVALID_VOLUME |
|
static int |
MAX_VOLUME_MUSIC_DTMF |
Constructor | Description |
---|---|
ShadowAudioManager() |
Modifier and Type | Method | Description |
---|---|---|
protected int |
abandonAudioFocus(AudioManager.OnAudioFocusChangeListener l) |
|
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.
|
protected void |
adjustStreamVolume(int streamType,
int direction,
int flags) |
Implements
AudioManager.adjustStreamVolume(int, int, int) . |
AudioRecordingConfiguration |
createActiveRecordingConfiguration(int sessionId,
int audioSource,
String clientPackageName) |
Creates simple active recording configuration.
|
protected int |
generateAudioSessionId() |
Provides a mock like interface for the
AudioManager.generateAudioSessionId() method by
returning positive distinct values, or AudioManager.ERROR if all possible values have
already been returned. |
protected List<AudioPlaybackConfiguration> |
getActivePlaybackConfigurations() |
|
protected List<AudioRecordingConfiguration> |
getActiveRecordingConfigurations() |
Returns list of active recording configurations that was set by
setActiveRecordingConfigurations(java.util.List<android.media.AudioRecordingConfiguration>, boolean) or empty list otherwise. |
AudioManager.OnAudioFocusChangeListener |
getLastAbandonedAudioFocusListener() |
|
AudioFocusRequest |
getLastAbandonedAudioFocusRequest() |
|
ShadowAudioManager.AudioFocusRequest |
getLastAudioFocusRequest() |
|
protected int |
getMode() |
|
String |
getParameter(String key) |
Returns a single parameter that was set via
setParameters(String) . |
protected String |
getParameters(String keys) |
The expected composition for keys is not well defined.
|
protected int |
getRingerMode() |
|
protected int |
getStreamMaxVolume(int streamType) |
|
protected int |
getStreamVolume(int streamType) |
|
boolean |
isAnyAudioPolicyRegistered() |
Returns true if at least one audio policy is registered with this manager, and false otherwise.
|
protected boolean |
isBluetoothA2dpOn() |
|
protected boolean |
isBluetoothScoAvailableOffCall() |
|
protected boolean |
isBluetoothScoOn() |
|
protected boolean |
isMicrophoneMute() |
|
protected boolean |
isMusicActive() |
|
protected boolean |
isSpeakerphoneOn() |
|
protected boolean |
isStreamMute(int streamType) |
|
static boolean |
isValidRingerMode(int ringerMode) |
|
protected boolean |
isWiredHeadsetOn() |
|
protected void |
registerAudioPlaybackCallback(AudioManager.AudioPlaybackCallback cb,
Handler handler) |
Registers callback that will receive changes made to the list of active playback configurations
by
setActivePlaybackConfigurationsFor(java.util.List<android.media.AudioAttributes>) . |
protected int |
registerAudioPolicy(Object audioPolicy) |
Registers an
AudioPolicy to allow that policy to control audio routing and audio focus. |
protected void |
registerAudioRecordingCallback(AudioManager.AudioRecordingCallback cb,
Handler handler) |
Registers callback that will receive changes made to the list of active recording
configurations by
setActiveRecordingConfigurations(java.util.List<android.media.AudioRecordingConfiguration>,boolean) . |
protected int |
requestAudioFocus(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 int |
requestAudioFocus(AudioManager.OnAudioFocusChangeListener l,
int streamType,
int durationHint) |
|
void |
setActivePlaybackConfigurationsFor(List<AudioAttributes> audioAttributes) |
Sets active playback configurations that will be served by
AudioManager.getActivePlaybackConfigurations() . |
void |
setActivePlaybackConfigurationsFor(List<AudioAttributes> audioAttributes,
boolean notifyCallbackListeners) |
Same as
setActivePlaybackConfigurationsFor(List) , but also notifies callbacks if
notifyCallbackListeners is true. |
void |
setActiveRecordingConfigurations(List<AudioRecordingConfiguration> activeRecordingConfigurations,
boolean notifyCallbackListeners) |
Sets active recording configurations that will be served by
AudioManager.getActiveRecordingConfigurations() and notifies callback listeners about that
change. |
protected void |
setBluetoothA2dpOn(boolean on) |
|
protected void |
setBluetoothScoOn(boolean isBluetoothScoOn) |
|
void |
setIsBluetoothScoAvailableOffCall(boolean isBluetoothScoAvailableOffCall) |
|
void |
setIsMusicActive(boolean isMusicActive) |
|
void |
setIsStreamMute(int streamType,
boolean isMuted) |
|
protected void |
setMicrophoneMute(boolean on) |
|
protected void |
setMode(int mode) |
|
void |
setNextFocusRequestResponse(int nextResponseValue) |
|
protected void |
setParameters(String keyValuePairs) |
|
protected void |
setRingerMode(int ringerMode) |
|
protected void |
setSpeakerphoneOn(boolean on) |
|
void |
setStreamMaxVolume(int streamMaxVolume) |
|
void |
setStreamVolume(int streamVolume) |
|
protected void |
setStreamVolume(int streamType,
int index,
int flags) |
|
protected void |
setWiredHeadsetOn(boolean on) |
|
protected void |
unregisterAudioPlaybackCallback(AudioManager.AudioPlaybackCallback cb) |
Unregisters callback listening to changes made to list of active playback configurations.
|
protected void |
unregisterAudioPolicy(Object audioPolicy) |
|
protected void |
unregisterAudioRecordingCallback(AudioManager.AudioRecordingCallback cb) |
Unregisters callback listening to changes made to list of active recording configurations.
|
public static final int MAX_VOLUME_MUSIC_DTMF
public static final int DEFAULT_MAX_VOLUME
public static final int DEFAULT_VOLUME
public static final int INVALID_VOLUME
public static final int FLAG_NO_ACTION
public static final int[] ALL_STREAMS
@Implementation protected int getStreamMaxVolume(int streamType)
@Implementation protected int getStreamVolume(int streamType)
@Implementation protected void setStreamVolume(int streamType, int index, int flags)
@Implementation protected boolean isBluetoothScoAvailableOffCall()
@Implementation protected int requestAudioFocus(AudioManager.OnAudioFocusChangeListener l, int streamType, int durationHint)
@Implementation(minSdk=26) protected int requestAudioFocus(AudioFocusRequest audioFocusRequest)
@Implementation protected int abandonAudioFocus(AudioManager.OnAudioFocusChangeListener l)
@Implementation(minSdk=26) protected int abandonAudioFocusRequest(AudioFocusRequest audioFocusRequest)
@Implementation protected int getRingerMode()
@Implementation protected void setRingerMode(int ringerMode)
public static boolean isValidRingerMode(int ringerMode)
@Implementation protected void setMode(int mode)
@Implementation protected int getMode()
public void setStreamMaxVolume(int streamMaxVolume)
public void setStreamVolume(int streamVolume)
@Implementation protected void setWiredHeadsetOn(boolean on)
@Implementation protected boolean isWiredHeadsetOn()
@Implementation protected void setBluetoothA2dpOn(boolean on)
@Implementation protected boolean isBluetoothA2dpOn()
@Implementation protected void setSpeakerphoneOn(boolean on)
@Implementation protected boolean isSpeakerphoneOn()
@Implementation protected void setMicrophoneMute(boolean on)
@Implementation protected boolean isMicrophoneMute()
@Implementation protected boolean isBluetoothScoOn()
@Implementation protected void setBluetoothScoOn(boolean isBluetoothScoOn)
@Implementation protected boolean isMusicActive()
@Implementation(minSdk=26) protected List<AudioPlaybackConfiguration> getActivePlaybackConfigurations()
@Implementation protected void setParameters(String keyValuePairs)
@Implementation protected String getParameters(String keys)
For testing purposes this method call always returns null.
public String getParameter(String key)
setParameters(String)
.@Implementation protected void adjustStreamVolume(int streamType, int direction, int flags)
AudioManager.adjustStreamVolume(int, int, int)
.
Currently supports only the directions AudioManager.ADJUST_MUTE
, AudioManager.ADJUST_UNMUTE
, AudioManager.ADJUST_LOWER
and AudioManager.ADJUST_RAISE
.
@Implementation(minSdk=23) protected boolean isStreamMute(int streamType)
public void setIsBluetoothScoAvailableOffCall(boolean isBluetoothScoAvailableOffCall)
public void setIsStreamMute(int streamType, boolean isMuted)
@Implementation(minSdk=26) protected void registerAudioPlaybackCallback(AudioManager.AudioPlaybackCallback cb, Handler handler)
setActivePlaybackConfigurationsFor(java.util.List<android.media.AudioAttributes>)
.@Implementation(minSdk=26) protected void unregisterAudioPlaybackCallback(AudioManager.AudioPlaybackCallback cb)
public void setActivePlaybackConfigurationsFor(List<AudioAttributes> audioAttributes)
AudioManager.getActivePlaybackConfigurations()
.
Note that there is no public AudioPlaybackConfiguration
constructor, so the
configurations returned are specified by their audio attributes only.
public void setActivePlaybackConfigurationsFor(List<AudioAttributes> audioAttributes, boolean notifyCallbackListeners)
setActivePlaybackConfigurationsFor(List)
, but also notifies callbacks if
notifyCallbackListeners is true.public void setIsMusicActive(boolean isMusicActive)
public ShadowAudioManager.AudioFocusRequest getLastAudioFocusRequest()
public void setNextFocusRequestResponse(int nextResponseValue)
public AudioManager.OnAudioFocusChangeListener getLastAbandonedAudioFocusListener()
public AudioFocusRequest getLastAbandonedAudioFocusRequest()
@Implementation(minSdk=24) protected List<AudioRecordingConfiguration> getActiveRecordingConfigurations()
setActiveRecordingConfigurations(java.util.List<android.media.AudioRecordingConfiguration>, boolean)
or empty list otherwise.@Implementation(minSdk=24) protected void registerAudioRecordingCallback(AudioManager.AudioRecordingCallback cb, Handler handler)
setActiveRecordingConfigurations(java.util.List<android.media.AudioRecordingConfiguration>,boolean)
.@Implementation(minSdk=24) protected void unregisterAudioRecordingCallback(AudioManager.AudioRecordingCallback cb)
public void setActiveRecordingConfigurations(List<AudioRecordingConfiguration> activeRecordingConfigurations, boolean notifyCallbackListeners)
AudioManager.getActiveRecordingConfigurations()
and notifies callback listeners about that
change.public AudioRecordingConfiguration createActiveRecordingConfiguration(int sessionId, int audioSource, String clientPackageName)
null
for AudioRecordingConfiguration.getAudioDevice()
.@HiddenApi @Implementation(minSdk=28) protected int registerAudioPolicy(Object audioPolicy)
AudioPolicy
to 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
.
AudioManager.ERROR
if the given policy has already been registered, and AudioManager.SUCCESS
otherwise.@HiddenApi @Implementation(minSdk=29) protected void unregisterAudioPolicy(Object audioPolicy)
public boolean isAnyAudioPolicyRegistered()
@Implementation(minSdk=21) protected int generateAudioSessionId()
AudioManager.generateAudioSessionId()
method by
returning positive distinct values, or AudioManager.ERROR
if all possible values have
already been returned.