OSDN Git Service

BT: Don't switch devices when one of the connected BT headsets disconnects
authorSatish Kodishala <skodisha@codeaurora.org>
Mon, 18 Jan 2016 08:53:12 +0000 (14:23 +0530)
committerAjay Panicker <apanicke@google.com>
Thu, 3 Nov 2016 20:57:56 +0000 (20:57 +0000)
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

services/core/java/com/android/server/audio/AudioService.java

index 7777ae2..027c722 100644 (file)
@@ -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;