Fix settings app not showing correct profile connection state message.

Bug:3385085
Change-Id: Ie4b7eb6bc9d8c91264cf7f68d7830c110e34496d
This commit is contained in:
Jaikumar Ganesh
2011-03-04 10:25:38 -08:00
parent d61737b560
commit 50e0b0cf87
2 changed files with 18 additions and 4 deletions

View File

@@ -226,7 +226,7 @@ public final class BluetoothDevicePreference extends Preference implements
// if any profiles are connected or busy, return that status // if any profiles are connected or busy, return that status
for (LocalBluetoothProfile profile : cachedDevice.getProfiles()) { for (LocalBluetoothProfile profile : cachedDevice.getProfiles()) {
int connectionStatus = profile.getConnectionStatus(device); int connectionStatus = cachedDevice.getProfileConnectionState(profile);
if (connectionStatus != BluetoothProfile.STATE_DISCONNECTED) { if (connectionStatus != BluetoothProfile.STATE_DISCONNECTED) {
return Utils.getConnectionStateSummary(connectionStatus); return Utils.getConnectionStateSummary(connectionStatus);

View File

@@ -27,6 +27,7 @@ import android.util.Log;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.Collections; import java.util.Collections;
import java.util.HashMap;
import java.util.List; import java.util.List;
/** /**
@@ -45,6 +46,7 @@ final class CachedBluetoothDevice implements Comparable<CachedBluetoothDevice> {
private String mName; private String mName;
private short mRssi; private short mRssi;
private BluetoothClass mBtClass; private BluetoothClass mBtClass;
private HashMap<LocalBluetoothProfile, Integer> mProfileConnectionState;
private final List<LocalBluetoothProfile> mProfiles = private final List<LocalBluetoothProfile> mProfiles =
new ArrayList<LocalBluetoothProfile>(); new ArrayList<LocalBluetoothProfile>();
@@ -95,6 +97,7 @@ final class CachedBluetoothDevice implements Comparable<CachedBluetoothDevice> {
" newProfileState " + newProfileState); " newProfileState " + newProfileState);
} }
mProfileConnectionState.put(profile, newProfileState);
if (newProfileState == BluetoothProfile.STATE_CONNECTED) { if (newProfileState == BluetoothProfile.STATE_CONNECTED) {
if (!mProfiles.contains(profile)) { if (!mProfiles.contains(profile)) {
mProfiles.add(profile); mProfiles.add(profile);
@@ -108,6 +111,7 @@ final class CachedBluetoothDevice implements Comparable<CachedBluetoothDevice> {
mLocalAdapter = adapter; mLocalAdapter = adapter;
mProfileManager = profileManager; mProfileManager = profileManager;
mDevice = device; mDevice = device;
mProfileConnectionState = new HashMap<LocalBluetoothProfile, Integer>();
fillData(); fillData();
} }
@@ -258,6 +262,16 @@ final class CachedBluetoothDevice implements Comparable<CachedBluetoothDevice> {
} }
} }
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? // TODO: do any of these need to run async on a background thread?
private void fillData() { private void fillData() {
fetchName(); fetchName();
@@ -337,7 +351,7 @@ final class CachedBluetoothDevice implements Comparable<CachedBluetoothDevice> {
*/ */
boolean isConnected() { boolean isConnected() {
for (LocalBluetoothProfile profile : mProfiles) { for (LocalBluetoothProfile profile : mProfiles) {
int status = profile.getConnectionStatus(mDevice); int status = getProfileConnectionState(profile);
if (status == BluetoothProfile.STATE_CONNECTED) { if (status == BluetoothProfile.STATE_CONNECTED) {
return true; return true;
} }
@@ -347,14 +361,14 @@ final class CachedBluetoothDevice implements Comparable<CachedBluetoothDevice> {
} }
boolean isConnectedProfile(LocalBluetoothProfile profile) { boolean isConnectedProfile(LocalBluetoothProfile profile) {
int status = profile.getConnectionStatus(mDevice); int status = getProfileConnectionState(profile);
return status == BluetoothProfile.STATE_CONNECTED; return status == BluetoothProfile.STATE_CONNECTED;
} }
boolean isBusy() { boolean isBusy() {
for (LocalBluetoothProfile profile : mProfiles) { for (LocalBluetoothProfile profile : mProfiles) {
int status = profile.getConnectionStatus(mDevice); int status = getProfileConnectionState(profile);
if (status == BluetoothProfile.STATE_CONNECTING if (status == BluetoothProfile.STATE_CONNECTING
|| status == BluetoothProfile.STATE_DISCONNECTING) { || status == BluetoothProfile.STATE_DISCONNECTING) {
return true; return true;