From 7951b43bd9a759b01ea994b341c102b03011ca3c Mon Sep 17 00:00:00 2001 From: Ganesh Ganapathi Batta Date: Wed, 29 Aug 2012 14:32:26 -0700 Subject: [PATCH] Clear profile connnection status of bonded devices when BT is turned off When BT is turned off in mid of a profile connection, sometimes profile connection status change message with status= DISCONNECTED does not reach Settings app which results in stale connection status for the device when BT is enabled next time. Fixed the issue By explicitly clearing the connection status for all paired devices when BT is turning OFF Change-Id: I5d0c158636f3b62eff9094821abe2ef3a7cab16e --- .../settings/bluetooth/CachedBluetoothDevice.java | 15 +++++++++++++++ .../bluetooth/CachedBluetoothDeviceManager.java | 5 +++++ 2 files changed, 20 insertions(+) mode change 100644 => 100755 src/com/android/settings/bluetooth/CachedBluetoothDeviceManager.java diff --git a/src/com/android/settings/bluetooth/CachedBluetoothDevice.java b/src/com/android/settings/bluetooth/CachedBluetoothDevice.java index ef223d5cf06..4b19b9c1172 100755 --- a/src/com/android/settings/bluetooth/CachedBluetoothDevice.java +++ b/src/com/android/settings/bluetooth/CachedBluetoothDevice.java @@ -119,6 +119,11 @@ final class CachedBluetoothDevice implements Comparable { Log.d(TAG, "onProfileStateChanged: profile " + profile + " newProfileState " + newProfileState); } + if (mLocalAdapter.getBluetoothState() == BluetoothAdapter.STATE_TURNING_OFF) + { + if (Utils.D) Log.d(TAG, " BT Turninig Off...Profile conn state change ignored..."); + return; + } mProfileConnectionState.put(profile, newProfileState); if (newProfileState == BluetoothProfile.STATE_CONNECTED) { if (!mProfiles.contains(profile)) { @@ -328,6 +333,16 @@ final class CachedBluetoothDevice implements Comparable { return mProfileConnectionState.get(profile); } + public void clearProfileConnectionState () + { + if (Utils.D) { + Log.d(TAG," Clearing all connection state for dev:" + mDevice.getName()); + } + for (LocalBluetoothProfile profile :getProfiles()) { + mProfileConnectionState.put(profile, BluetoothProfile.STATE_DISCONNECTED); + } + } + // TODO: do any of these need to run async on a background thread? private void fillData() { fetchName(); diff --git a/src/com/android/settings/bluetooth/CachedBluetoothDeviceManager.java b/src/com/android/settings/bluetooth/CachedBluetoothDeviceManager.java old mode 100644 new mode 100755 index 06be3c42743..ff282cc67c9 --- a/src/com/android/settings/bluetooth/CachedBluetoothDeviceManager.java +++ b/src/com/android/settings/bluetooth/CachedBluetoothDeviceManager.java @@ -144,6 +144,11 @@ final class CachedBluetoothDeviceManager { if (cachedDevice.getBondState() != BluetoothDevice.BOND_BONDED) { 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 + // by making a binder call. + cachedDevice.clearProfileConnectionState(); } } }