From 737a30f593300a9731adfe899144af64b1d71057 Mon Sep 17 00:00:00 2001 From: Kausik Sinnaswamy Date: Wed, 16 May 2012 14:31:45 +0530 Subject: [PATCH] Clear the Available (unbonded devices) from the CachedDevices List during BT disable. Change-Id: I576237a4165759fe952690f19fde59ce78cd1d29 --- .../settings/bluetooth/BluetoothEventManager.java | 2 ++ .../bluetooth/CachedBluetoothDeviceManager.java | 14 ++++++++++++++ 2 files changed, 16 insertions(+) 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);