am 356745ec: am 213d579f: Merge "Don\'t disconnect the same device before connecting." into gingerbread

Merge commit '356745ecc63419a2569345186e8612a5b0ced28d'

* commit '356745ecc63419a2569345186e8612a5b0ced28d':
  Don't disconnect the same device before connecting.
diff --git a/src/com/android/settings/bluetooth/CachedBluetoothDevice.java b/src/com/android/settings/bluetooth/CachedBluetoothDevice.java
index 5f374a5..d655f90 100644
--- a/src/com/android/settings/bluetooth/CachedBluetoothDevice.java
+++ b/src/com/android/settings/bluetooth/CachedBluetoothDevice.java
@@ -91,10 +91,10 @@
     // See mConnectAttempted
     private static final long MAX_UUID_DELAY_FOR_AUTO_CONNECT = 5000;
 
-    
+
     /**
      * Describes the current device and profile for logging.
-     * 
+     *
      * @param profile Profile to describe
      * @return Description of the device and profile
      */
@@ -107,7 +107,7 @@
 
         return sb.toString();
     }
-    
+
     private String describe(Profile profile) {
         return describe(this, profile);
     }
@@ -264,7 +264,7 @@
                         .getProfileManager(mLocalManager, profile);
                 if (profileManager.isPreferred(mDevice)) {
                     ++preferredProfiles;
-                    disconnectConnected(profile);
+                    disconnectConnected(this, profile);
                     connectInt(this, profile);
                 }
             }
@@ -287,7 +287,7 @@
                 LocalBluetoothProfileManager profileManager = LocalBluetoothProfileManager
                         .getProfileManager(mLocalManager, profile);
                 profileManager.setPreferred(mDevice, false);
-                disconnectConnected(profile);
+                disconnectConnected(this, profile);
                 connectInt(this, profile);
             }
         }
@@ -297,19 +297,20 @@
         mConnectAttempted = SystemClock.elapsedRealtime();
         // Reset the only-show-one-error-dialog tracking variable
         mIsConnectingErrorPossible = true;
-        disconnectConnected(profile);
+        disconnectConnected(this, profile);
         connectInt(this, profile);
     }
 
-    private void disconnectConnected(Profile profile) {
+    private void disconnectConnected(CachedBluetoothDevice device, Profile profile) {
         LocalBluetoothProfileManager profileManager =
             LocalBluetoothProfileManager.getProfileManager(mLocalManager, profile);
         CachedBluetoothDeviceManager cachedDeviceManager = mLocalManager.getCachedDeviceManager();
         Set<BluetoothDevice> devices = profileManager.getConnectedDevices();
         if (devices == null) return;
-        for (BluetoothDevice device : devices) {
-            CachedBluetoothDevice cachedDevice = cachedDeviceManager.findDevice(device);
-            if (cachedDevice != null) {
+        for (BluetoothDevice btDevice : devices) {
+            CachedBluetoothDevice cachedDevice = cachedDeviceManager.findDevice(btDevice);
+
+            if (cachedDevice != null && !cachedDevice.equals(device)) {
                 disconnectInt(cachedDevice, profile);
             }
         }