From 50e0b0cf87f724d25ada10353867f14ebbf644aa Mon Sep 17 00:00:00 2001 From: Jaikumar Ganesh Date: Fri, 4 Mar 2011 10:25:38 -0800 Subject: [PATCH] Fix settings app not showing correct profile connection state message. Bug:3385085 Change-Id: Ie4b7eb6bc9d8c91264cf7f68d7830c110e34496d --- .../bluetooth/BluetoothDevicePreference.java | 2 +- .../bluetooth/CachedBluetoothDevice.java | 20 ++++++++++++++++--- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/src/com/android/settings/bluetooth/BluetoothDevicePreference.java b/src/com/android/settings/bluetooth/BluetoothDevicePreference.java index 5f791d942e4..2dba279b94f 100644 --- a/src/com/android/settings/bluetooth/BluetoothDevicePreference.java +++ b/src/com/android/settings/bluetooth/BluetoothDevicePreference.java @@ -226,7 +226,7 @@ public final class BluetoothDevicePreference extends Preference implements // if any profiles are connected or busy, return that status for (LocalBluetoothProfile profile : cachedDevice.getProfiles()) { - int connectionStatus = profile.getConnectionStatus(device); + int connectionStatus = cachedDevice.getProfileConnectionState(profile); if (connectionStatus != BluetoothProfile.STATE_DISCONNECTED) { return Utils.getConnectionStateSummary(connectionStatus); diff --git a/src/com/android/settings/bluetooth/CachedBluetoothDevice.java b/src/com/android/settings/bluetooth/CachedBluetoothDevice.java index 0bc816c9d8f..56e96b4d003 100644 --- a/src/com/android/settings/bluetooth/CachedBluetoothDevice.java +++ b/src/com/android/settings/bluetooth/CachedBluetoothDevice.java @@ -27,6 +27,7 @@ import android.util.Log; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; +import java.util.HashMap; import java.util.List; /** @@ -45,6 +46,7 @@ final class CachedBluetoothDevice implements Comparable { private String mName; private short mRssi; private BluetoothClass mBtClass; + private HashMap mProfileConnectionState; private final List mProfiles = new ArrayList(); @@ -95,6 +97,7 @@ final class CachedBluetoothDevice implements Comparable { " newProfileState " + newProfileState); } + mProfileConnectionState.put(profile, newProfileState); if (newProfileState == BluetoothProfile.STATE_CONNECTED) { if (!mProfiles.contains(profile)) { mProfiles.add(profile); @@ -108,6 +111,7 @@ final class CachedBluetoothDevice implements Comparable { mLocalAdapter = adapter; mProfileManager = profileManager; mDevice = device; + mProfileConnectionState = new HashMap(); fillData(); } @@ -258,6 +262,16 @@ final class CachedBluetoothDevice implements Comparable { } } + int getProfileConnectionState(LocalBluetoothProfile profile) { + if (mProfileConnectionState == null || + mProfileConnectionState.get(profile) == null) { + // If cache is empty make the binder call to get the state + int state = profile.getConnectionStatus(mDevice); + mProfileConnectionState.put(profile, state); + } + return mProfileConnectionState.get(profile); + } + // TODO: do any of these need to run async on a background thread? private void fillData() { fetchName(); @@ -337,7 +351,7 @@ final class CachedBluetoothDevice implements Comparable { */ boolean isConnected() { for (LocalBluetoothProfile profile : mProfiles) { - int status = profile.getConnectionStatus(mDevice); + int status = getProfileConnectionState(profile); if (status == BluetoothProfile.STATE_CONNECTED) { return true; } @@ -347,14 +361,14 @@ final class CachedBluetoothDevice implements Comparable { } boolean isConnectedProfile(LocalBluetoothProfile profile) { - int status = profile.getConnectionStatus(mDevice); + int status = getProfileConnectionState(profile); return status == BluetoothProfile.STATE_CONNECTED; } boolean isBusy() { for (LocalBluetoothProfile profile : mProfiles) { - int status = profile.getConnectionStatus(mDevice); + int status = getProfileConnectionState(profile); if (status == BluetoothProfile.STATE_CONNECTING || status == BluetoothProfile.STATE_DISCONNECTING) { return true;