From b17031bed0ae81b5f342e0c0591b560f7c8849ed Mon Sep 17 00:00:00 2001 From: Matthew Xie Date: Mon, 8 Sep 2014 22:30:18 -0700 Subject: [PATCH] Do not remove bonded devices from cached device list upon a device scan Bug: 17405122 Change-Id: I3f5cc6ddc8f85d3b6223f9ff60e1d5eeb76c530a --- .../settings/bluetooth/BluetoothSettings.java | 2 +- .../bluetooth/CachedBluetoothDeviceManager.java | 13 +++++++++---- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/src/com/android/settings/bluetooth/BluetoothSettings.java b/src/com/android/settings/bluetooth/BluetoothSettings.java index e29ccc99a53..105bdf22903 100755 --- a/src/com/android/settings/bluetooth/BluetoothSettings.java +++ b/src/com/android/settings/bluetooth/BluetoothSettings.java @@ -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); diff --git a/src/com/android/settings/bluetooth/CachedBluetoothDeviceManager.java b/src/com/android/settings/bluetooth/CachedBluetoothDeviceManager.java index 0b53b1a1e2f..2b0e7f15b93 100755 --- a/src/com/android/settings/bluetooth/CachedBluetoothDeviceManager.java +++ b/src/com/android/settings/bluetooth/CachedBluetoothDeviceManager.java @@ -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