OSDN Git Service

Do not remove bonded devices from cached device list upon a device scan
authorMatthew Xie <mattx@google.com>
Tue, 9 Sep 2014 05:30:18 +0000 (22:30 -0700)
committerMatthew Xie <mattx@google.com>
Tue, 9 Sep 2014 22:12:43 +0000 (15:12 -0700)
Bug: 17405122

Change-Id: I3f5cc6ddc8f85d3b6223f9ff60e1d5eeb76c530a

src/com/android/settings/bluetooth/BluetoothSettings.java
src/com/android/settings/bluetooth/CachedBluetoothDeviceManager.java

index e29ccc9..105bdf2 100755 (executable)
@@ -244,7 +244,7 @@ public final class BluetoothSettings extends DeviceListPreferenceFragment implem
             removeAllDevices();
         }
 
-        mLocalManager.getCachedDeviceManager().clearCachedDevices();
+        mLocalManager.getCachedDeviceManager().clearNonBondedDevices();
         mAvailableDevicesCategory.removeAll();
         mInitialScanStarted = true;
         mLocalAdapter.startScanning(true);
index 0b53b1a..2b0e7f1 100755 (executable)
@@ -112,8 +112,13 @@ final class CachedBluetoothDeviceManager {
         return device.getAddress();
     }
 
-    public synchronized void clearCachedDevices() {
-        mCachedDevices.clear();
+    public synchronized void clearNonBondedDevices() {
+        for (int i = mCachedDevices.size() - 1; i >= 0; i--) {
+            CachedBluetoothDevice cachedDevice = mCachedDevices.get(i);
+            if (cachedDevice.getBondState() != BluetoothDevice.BOND_BONDED) {
+                mCachedDevices.remove(i);
+            }
+        }
     }
 
     public synchronized void onScanningStateChanged(boolean started) {
@@ -148,8 +153,8 @@ final class CachedBluetoothDeviceManager {
             for (int i = mCachedDevices.size() - 1; i >= 0; i--) {
                 CachedBluetoothDevice cachedDevice = mCachedDevices.get(i);
                 if (cachedDevice.getBondState() != BluetoothDevice.BOND_BONDED) {
-                   cachedDevice.setVisible(false);
-                   mCachedDevices.remove(i);
+                    cachedDevice.setVisible(false);
+                    mCachedDevices.remove(i);
                 } else {
                     // For bonded devices, we need to clear the connection status so that
                     // when BT is enabled next time, device connection status shall be retrieved