Snap for 6699052 from 40f99cab940a29592ea551b74d665fe77f98bb07 to q-keystone-qcom-release
Change-Id: I3190fe7c8bbaf45c67f8f832b9dcf38d27577426
diff --git a/src/com/android/bluetooth/a2dp/A2dpService.java b/src/com/android/bluetooth/a2dp/A2dpService.java
index 38ba2d6..d722e67 100755
--- a/src/com/android/bluetooth/a2dp/A2dpService.java
+++ b/src/com/android/bluetooth/a2dp/A2dpService.java
@@ -575,6 +575,7 @@
private boolean connectionAllowedCheckMaxDevices(BluetoothDevice device) {
int connected = 0;
int tws_device = 0;
+
// Count devices that are in the process of connecting or already connected
synchronized (mBtA2dpLock) {
for (A2dpStateMachine sm : mStateMachines.values()) {
@@ -597,14 +598,16 @@
}
Log.d(TAG,"connectionAllowedCheckMaxDevices connected = " + connected +
"tws connected = " + tws_device);
- synchronized (mVariableLock) {
- if (mAdapterService != null && mAdapterService.isVendorIntfEnabled() &&
- ((tws_device > 0) || mAdapterService.isTwsPlusDevice(device) ||
- ((tws_device > 0) && connected == mMaxConnectedAudioDevices &&
- !mAdapterService.isTwsPlusDevice(device)))) {
- return isConnectionAllowed(device, tws_device, connected);
+ synchronized (mBtA2dpLock) {
+ Log.d(TAG, "Going to acquire mVariableLock");
+ synchronized (mVariableLock) {
+ if (mAdapterService != null && mAdapterService.isVendorIntfEnabled() &&
+ ((tws_device > 0) || mAdapterService.isTwsPlusDevice(device))) {
+ return isConnectionAllowed(device, tws_device, connected);
+ }
}
}
+
if (mSetMaxConnectedAudioDevices == 1 &&
connected == mSetMaxConnectedAudioDevices) {
disconnectExisting = true;