From 2980980a75a0066273683aed8b12a58b212a0487 Mon Sep 17 00:00:00 2001 From: Satish Kodishala Date: Mon, 18 Jan 2016 14:23:12 +0530 Subject: [PATCH] BT: Don't switch devices when one of the connected BT headsets disconnects Usecase: 1. Enable multi-hf. 2. Connect to HS1. 3. Connect to HS2. 4. Make a call on AG. Here call audio is present on HS2. 5. Now disconnect HS1 from AG. Failure: When HS1 is disconnected, call audio is routed to handset/speaker. Root cause: When hs1 disconnection intent is received, SCO path is cleared and audio is routed to handset/speaker. Fix: Check if the device being disconnected is same as the device call audio is present before clearing SCO path. Change-Id: If83325679b70b5893e44e8d844000ee028d0246c --- .../android/server/audio/AudioService.java | 31 +++++++++++++------ 1 file changed, 22 insertions(+), 9 deletions(-) diff --git a/services/core/java/com/android/server/audio/AudioService.java b/services/core/java/com/android/server/audio/AudioService.java index 7777ae23ff29c..027c72264a352 100644 --- a/services/core/java/com/android/server/audio/AudioService.java +++ b/services/core/java/com/android/server/audio/AudioService.java @@ -3097,14 +3097,28 @@ public class AudioService extends IAudioService.Stub { boolean success = handleDeviceConnection(connected, outDevice, address, btDeviceName) && handleDeviceConnection(connected, inDevice, address, btDeviceName); - if (success) { - synchronized (mScoClients) { - if (connected) { - mBluetoothHeadsetDevice = btDevice; - } else { - mBluetoothHeadsetDevice = null; - resetBluetoothSco(); - } + + if (!success) { + return; + } + + /* When one BT headset is disconnected while another BT headset + * is connected, don't mess with the headset device. + */ + if ((state == BluetoothProfile.STATE_DISCONNECTED || + state == BluetoothProfile.STATE_DISCONNECTING) && + mBluetoothHeadset != null && + mBluetoothHeadset.getAudioState(btDevice) == BluetoothHeadset.STATE_AUDIO_CONNECTED) { + Log.w(TAG, "SCO connected through another device, returning"); + return; + } + + synchronized (mScoClients) { + if (connected) { + mBluetoothHeadsetDevice = btDevice; + } else { + mBluetoothHeadsetDevice = null; + resetBluetoothSco(); } } } @@ -5250,7 +5264,6 @@ public class AudioService extends IAudioService.Stub { state = intent.getIntExtra(BluetoothProfile.EXTRA_STATE, BluetoothProfile.STATE_DISCONNECTED); BluetoothDevice btDevice = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE); - setBtScoDeviceConnectionState(btDevice, state); } else if (action.equals(BluetoothHeadset.ACTION_AUDIO_STATE_CHANGED)) { boolean broadcast = false;