diff --git a/src/com/android/settings/bluetooth/BluetoothEventManager.java b/src/com/android/settings/bluetooth/BluetoothEventManager.java index a6d9bcfcefa..a23e0aa973a 100644 --- a/src/com/android/settings/bluetooth/BluetoothEventManager.java +++ b/src/com/android/settings/bluetooth/BluetoothEventManager.java @@ -163,6 +163,8 @@ final class BluetoothEventManager { callback.onBluetoothStateChanged(state); } } + // Inform CachedDeviceManager that the adapter state has changed + mDeviceManager.onBluetoothStateChanged(state); } } diff --git a/src/com/android/settings/bluetooth/CachedBluetoothDeviceManager.java b/src/com/android/settings/bluetooth/CachedBluetoothDeviceManager.java index 77f6b2cba95..423821534a1 100644 --- a/src/com/android/settings/bluetooth/CachedBluetoothDeviceManager.java +++ b/src/com/android/settings/bluetooth/CachedBluetoothDeviceManager.java @@ -16,6 +16,7 @@ package com.android.settings.bluetooth; +import android.bluetooth.BluetoothAdapter; import android.bluetooth.BluetoothDevice; import android.content.Context; import android.util.Log; @@ -134,6 +135,19 @@ final class CachedBluetoothDeviceManager { } } + public synchronized void onBluetoothStateChanged(int bluetoothState) { + // When Bluetooth is turning off, we need to clear the non-bonded devices + // Otherwise, they end up showing up on the next BT enable + if (bluetoothState == BluetoothAdapter.STATE_TURNING_OFF) { + for (int i = mCachedDevices.size() - 1; i >= 0; i--) { + CachedBluetoothDevice cachedDevice = mCachedDevices.get(i); + if (cachedDevice.getBondState() == BluetoothDevice.BOND_NONE) { + cachedDevice.setVisible(false); + mCachedDevices.remove(i); + } + } + } + } private void log(String msg) { if (DEBUG) { Log.d(TAG, msg);