Skip to content

Commit

Permalink
Bluetooth: request audio focus on incoming call
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
romanbb authored and Alberto97 committed Jun 24, 2015
1 parent c08f80b commit 3ee0044
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/com/android/bluetooth/hfp/HeadsetStateMachine.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -1736,6 +1737,7 @@ private void processAudioEvent(int state, BluetoothDevice device) {
log("Audio is closed,Set A2dpSuspended=false");
mAudioManager.setParameters("A2dpSuspended=false");
mA2dpSuspend = false;
releaseAudioFocus();
}
}
broadcastAudioState(device, BluetoothHeadset.STATE_AUDIO_DISCONNECTED,
Expand Down Expand Up @@ -2249,6 +2251,7 @@ private void processAudioEvent(int state, BluetoothDevice device) {
log("Audio is closed,Set A2dpSuspended=false");
mAudioManager.setParameters("A2dpSuspended=false");
mA2dpSuspend = false;
releaseAudioFocus();
}
}
broadcastAudioState(device, BluetoothHeadset.STATE_AUDIO_DISCONNECTED,
Expand Down Expand Up @@ -2816,6 +2819,7 @@ synchronized boolean initiateScoUsingVirtualVoiceCall() {
if (mA2dpPlayState == BluetoothA2dp.STATE_PLAYING) {
log("suspending A2DP stream for SCO");
mPendingCiev = true;
requestAudioFocus();
return true;
}
}
Expand Down Expand Up @@ -2920,6 +2924,21 @@ else if (prevState == BluetoothA2dp.STATE_NOT_PLAYING) {
}
}

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");
Expand Down Expand Up @@ -3123,6 +3142,7 @@ private void processA2dpState(HeadsetCallState callState) {
if (mA2dpPlayState == BluetoothA2dp.STATE_PLAYING) {
Log.d(TAG, "suspending A2DP stream for Call");
mPendingCiev = true;
requestAudioFocus();
return ;
}
}
Expand All @@ -3136,6 +3156,7 @@ private void processA2dpState(HeadsetCallState callState) {
log("Set A2dpSuspended=false to reset the a2dp state to standby");
mAudioManager.setParameters("A2dpSuspended=false");
mA2dpSuspend = false;
releaseAudioFocus();
}
}
}
Expand Down

0 comments on commit 3ee0044

Please sign in to comment.