diff --git a/src/com/android/settings/bluetooth/CachedBluetoothDevice.java b/src/com/android/settings/bluetooth/CachedBluetoothDevice.java index 46391d38712..88964e094d5 100644 --- a/src/com/android/settings/bluetooth/CachedBluetoothDevice.java +++ b/src/com/android/settings/bluetooth/CachedBluetoothDevice.java @@ -279,7 +279,7 @@ class CachedBluetoothDevice implements Comparable { } private void connectWithoutResettingTimer(boolean connectAllProfiles) { - // Try to initialize the profiles if there were not. + // Try to initialize the profiles if they were not. if (mProfiles.size() == 0) { if (!updateProfiles()) { // If UUIDs are not available yet, connect will be happen @@ -299,7 +299,6 @@ class CachedBluetoothDevice implements Comparable { .getProfileManager(mLocalManager, profile); if (profileManager.isPreferred(mDevice)) { ++preferredProfiles; - disconnectConnected(this, profile); connectInt(this, profile); } } @@ -322,7 +321,6 @@ class CachedBluetoothDevice implements Comparable { LocalBluetoothProfileManager profileManager = LocalBluetoothProfileManager .getProfileManager(mLocalManager, profile); profileManager.setPreferred(mDevice, true); - disconnectConnected(this, profile); connectInt(this, profile); } } @@ -332,25 +330,9 @@ class CachedBluetoothDevice implements Comparable { mConnectAttempted = SystemClock.elapsedRealtime(); // Reset the only-show-one-error-dialog tracking variable mIsConnectingErrorPossible = true; - disconnectConnected(this, profile); connectInt(this, profile); } - private void disconnectConnected(CachedBluetoothDevice device, Profile profile) { - LocalBluetoothProfileManager profileManager = - LocalBluetoothProfileManager.getProfileManager(mLocalManager, profile); - CachedBluetoothDeviceManager cachedDeviceManager = mLocalManager.getCachedDeviceManager(); - List devices = profileManager.getConnectedDevices(); - if (devices == null) return; - for (BluetoothDevice btDevice : devices) { - CachedBluetoothDevice cachedDevice = cachedDeviceManager.findDevice(btDevice); - - if (cachedDevice != null && !cachedDevice.equals(device)) { - cachedDevice.disconnect(profile); - } - } - } - private boolean connectInt(CachedBluetoothDevice cachedDevice, Profile profile) { if (!cachedDevice.ensurePaired()) return false; diff --git a/src/com/android/settings/bluetooth/LocalBluetoothProfileManager.java b/src/com/android/settings/bluetooth/LocalBluetoothProfileManager.java index 5c8d868178c..a2ac743a052 100644 --- a/src/com/android/settings/bluetooth/LocalBluetoothProfileManager.java +++ b/src/com/android/settings/bluetooth/LocalBluetoothProfileManager.java @@ -471,6 +471,12 @@ abstract class LocalBluetoothProfileManager { @Override public boolean connect(BluetoothDevice device) { + List sinks = getConnectedDevices(); + if (sinks != null) { + for (BluetoothDevice sink : sinks) { + mService.disconnect(sink); + } + } return mService.connect(device); } @@ -727,6 +733,12 @@ abstract class LocalBluetoothProfileManager { @Override public boolean connect(BluetoothDevice device) { + List sinks = getConnectedDevices(); + if (sinks != null) { + for (BluetoothDevice sink : sinks) { + mService.disconnect(sink); + } + } return mService.connect(device); }