A simple app used to test audio focus handling in apps, especially MediaSession in Chrome. You can perform audio gain/abandon actions, in order to simulate a short ping from an SMS or email, or permanent audio focus gain from other media player apps.
ninja -C out/Debug audio_focus_grabber_apk adb install -r out/Debug/apks/AudioFocusGrabber.apk
You can simulate audio focus actions using the UI, the notification bar or through adb shell. There are three kinds of audio focus actions, corresponding to:
AudioManager.AUDIOFOCUS_GAINAudioManager.AUDIOFOCUS_TRANSIENTAudioManager.AUDIOFOCUS_TRANSIENT_MAY_DUCKFrom the UI, there are three buttons for the three actions. Just click it, and AudioFocusGrabber will perform the audio focus action, and play a ping sound.
However in this way, the app must be in background.
You can also start a notification from the UI, and then you can make controls from the notification.
In this way, the app must be in background or losed window focus.
adb shellFrom the adb shell, which you can do it even if the AudioFocusGrabber is not in foreground. You may use the following three commands:
adb shell am startservice -a AUDIO_FOCUS_GRABBER_GAIN adb shell am startservice -a AUDIO_FOCUS_GRABBER_TRANSIENT_PAUSE adb shell am startservice -a AUDIO_FOCUS_GRABBER_TRANSIENT_DUCK
In this way, the app may be in the foreground, in the background or losed window focus.