Allow disconnected BT profiles to be unchecked in Settings.

In the Bluetooth profile list, the checkbox indicates whether the
profile is preferred (we should auto connect). If the profile is
not connected, selecting it will try to connect the profile and set
it to preferred. If the profile can't be connected, then the user
could not turn off the preferred setting for the profile.

Change the behavior so that when a profile is not connected,
but is marked as preferred, selecting the profile will turn off the
preferred setting (no auto connect) instead of trying to connect.
This enables the user to turn off auto connect for a profile when
it can't be connected. Tapping a second time will try to connect
the profile and set it as preferred, as usual.

Also change PanProfile to return the current connection status for
isPreferred() instead of always returning true. Currently, the
PAN profile is always checked, which is confusing because it looks
like PAN is always connected. Also, because of the new behavior
when a profile is selected, it's now necessary to return false for
isPreferred() when PAN isn't connected, so that we will try to
connect when the user selects it, instead of trying to turn off
the preferred setting, which isn't supported for PAN.

Bug: 7007641
Change-Id: Ifb0f51a15379bc254933168c43bdfc8b22f26051
This commit is contained in:
Jake Hamby
2012-10-04 17:42:38 -07:00
parent 27636444a4
commit 904d3726d4
2 changed files with 12 additions and 9 deletions

View File

@@ -241,7 +241,7 @@ public final class DeviceProfilesSettings extends SettingsPreferenceFragment
mCachedDevice.setName((String) newValue);
} else if (preference instanceof CheckBoxPreference) {
LocalBluetoothProfile prof = getProfileOf(preference);
onProfileClicked(prof);
onProfileClicked(prof, (CheckBoxPreference) preference);
return false; // checkbox will update from onDeviceAttributesChanged() callback
} else {
return false;
@@ -250,7 +250,7 @@ public final class DeviceProfilesSettings extends SettingsPreferenceFragment
return true;
}
private void onProfileClicked(LocalBluetoothProfile profile) {
private void onProfileClicked(LocalBluetoothProfile profile, CheckBoxPreference profilePref) {
BluetoothDevice device = mCachedDevice.getDevice();
int status = profile.getConnectionStatus(device);
@@ -260,8 +260,14 @@ public final class DeviceProfilesSettings extends SettingsPreferenceFragment
if (isConnected) {
askDisconnect(getActivity(), profile);
} else {
profile.setPreferred(device, true);
mCachedDevice.connectProfile(profile);
if (profile.isPreferred(device)) {
// profile is preferred but not connected: disable auto-connect
profile.setPreferred(device, false);
refreshProfilePreference(profilePref, profile);
} else {
profile.setPreferred(device, true);
mCachedDevice.connectProfile(profile);
}
}
}
@@ -357,8 +363,4 @@ public final class DeviceProfilesSettings extends SettingsPreferenceFragment
private void unpairDevice() {
mCachedDevice.unpair();
}
private boolean getAutoConnect(LocalBluetoothProfile prof) {
return prof.isPreferred(mCachedDevice.getDevice());
}
}