diff options
author | Roman Birg <roman@cyngn.com> | 2015-06-17 16:36:29 -0700 |
---|---|---|
committer | Roman Birg <roman@cyngn.com> | 2015-06-17 16:36:29 -0700 |
commit | 030c31561cc5328a48f9d02efd7472a99072c724 (patch) | |
tree | 86123c2827974a92cd5683f146295f073b440ee6 | |
parent | 24d06367336b997cb9ffd02946a97ddaeadbce10 (diff) | |
download | android_packages_apps_Bluetooth-030c31561cc5328a48f9d02efd7472a99072c724.tar.gz android_packages_apps_Bluetooth-030c31561cc5328a48f9d02efd7472a99072c724.tar.bz2 android_packages_apps_Bluetooth-030c31561cc5328a48f9d02efd7472a99072c724.zip |
Bluetooth: request audio focus on incoming call
When the a2dp stream is suspended for an incoming call, request audio
focus from the audio manager so that any playing media will pause/duck
as needed.
Change-Id: I308b697ad998b7167703ebc89c6285034ac1ebf9
Signed-off-by: Roman Birg <roman@cyngn.com>
-rw-r--r-- | src/com/android/bluetooth/hfp/HeadsetStateMachine.java | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/src/com/android/bluetooth/hfp/HeadsetStateMachine.java b/src/com/android/bluetooth/hfp/HeadsetStateMachine.java index f77a613a0..b1bed0fd7 100644 --- a/src/com/android/bluetooth/hfp/HeadsetStateMachine.java +++ b/src/com/android/bluetooth/hfp/HeadsetStateMachine.java @@ -202,6 +202,7 @@ final class HeadsetStateMachine extends StateMachine { private IBluetoothHeadsetPhone mPhoneProxy; private boolean mNativeAvailable; + private boolean mAudioFocused; private boolean mA2dpSuspend; private int mA2dpPlayState; private int mA2dpState; @@ -1736,6 +1737,7 @@ final class HeadsetStateMachine extends StateMachine { log("Audio is closed,Set A2dpSuspended=false"); mAudioManager.setParameters("A2dpSuspended=false"); mA2dpSuspend = false; + releaseAudioFocus(); } } broadcastAudioState(device, BluetoothHeadset.STATE_AUDIO_DISCONNECTED, @@ -2249,6 +2251,7 @@ final class HeadsetStateMachine extends StateMachine { log("Audio is closed,Set A2dpSuspended=false"); mAudioManager.setParameters("A2dpSuspended=false"); mA2dpSuspend = false; + releaseAudioFocus(); } } broadcastAudioState(device, BluetoothHeadset.STATE_AUDIO_DISCONNECTED, @@ -2816,6 +2819,7 @@ final class HeadsetStateMachine extends StateMachine { if (mA2dpPlayState == BluetoothA2dp.STATE_PLAYING) { log("suspending A2DP stream for SCO"); mPendingCiev = true; + requestAudioFocus(); return true; } } @@ -2920,6 +2924,21 @@ final class HeadsetStateMachine extends StateMachine { } } + private void requestAudioFocus() { + if (!mAudioFocused) { + mAudioManager.requestAudioFocusForCall(AudioManager.STREAM_BLUETOOTH_SCO, + AudioManager.AUDIOFOCUS_GAIN_TRANSIENT); + mAudioFocused = true; + } + } + + private void releaseAudioFocus() { + if (mAudioFocused) { + mAudioManager.abandonAudioFocusForCall(); + mAudioFocused = false; + } + } + private void processAnswerCall(BluetoothDevice device) { if(device == null) { Log.w(TAG, "processAnswerCall device is null"); @@ -3123,6 +3142,7 @@ final class HeadsetStateMachine extends StateMachine { if (mA2dpPlayState == BluetoothA2dp.STATE_PLAYING) { Log.d(TAG, "suspending A2DP stream for Call"); mPendingCiev = true; + requestAudioFocus(); return ; } } @@ -3136,6 +3156,7 @@ final class HeadsetStateMachine extends StateMachine { log("Set A2dpSuspended=false to reset the a2dp state to standby"); mAudioManager.setParameters("A2dpSuspended=false"); mA2dpSuspend = false; + releaseAudioFocus(); } } } |