Merge "BT: Don't switch devices when one of the connected BT headsets disconnects"
am: 0bebfe76fc
Change-Id: Ibd4c4f9defec469bb14a282c53d64932123d4905
diff --git a/services/core/java/com/android/server/audio/AudioService.java b/services/core/java/com/android/server/audio/AudioService.java
index a9277ce..7fe6c3e 100644
--- a/services/core/java/com/android/server/audio/AudioService.java
+++ b/services/core/java/com/android/server/audio/AudioService.java
@@ -3100,14 +3100,28 @@
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();
}
}
}
@@ -5253,7 +5267,6 @@
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;