Bluetooth MaxConnectedAudioDevices show correct number

* When the preference is changed by the user, it will update the UI
* When the Developer options is enabled, it will set the system property
to default number
* Change string "Maximum number of connected Bluetooth audio devices" to
"Maximum connected Bluetooth audio devices" per discussion with Lindsay

Bug: 71603731
Test: m
ROBOTEST_FILTER="BluetoothMaxConnectedAudioDevicesPreferenceControllerTest"
RunSettingsRoboTests -j40
Change-Id: I3e59534585065c84530da73ffded21894c845ce9
This commit is contained in:
Hansong Zhang
2018-01-05 14:47:26 -08:00
parent de4bef0243
commit de2855abdf
3 changed files with 20 additions and 9 deletions

View File

@@ -1630,7 +1630,7 @@
<string name="bluetooth_dock_settings_remember">Remember settings</string> <string name="bluetooth_dock_settings_remember">Remember settings</string>
<!-- Bluetooth developer settings: Maximum number of connected audio devices --> <!-- Bluetooth developer settings: Maximum number of connected audio devices -->
<string name="bluetooth_max_connected_audio_devices_string">Maximum number of connected Bluetooth audio devices</string> <string name="bluetooth_max_connected_audio_devices_string">Maximum connected Bluetooth audio devices</string>
<!-- Bluetooth developer settings: Maximum number of connected audio devices --> <!-- Bluetooth developer settings: Maximum number of connected audio devices -->
<string name="bluetooth_max_connected_audio_devices_dialog_title">Select maximum number of connected Bluetooth audio devices</string> <string name="bluetooth_max_connected_audio_devices_dialog_title">Select maximum number of connected Bluetooth audio devices</string>

View File

@@ -67,6 +67,7 @@ public class BluetoothMaxConnectedAudioDevicesPreferenceController extends
@Override @Override
public boolean onPreferenceChange(Preference preference, Object newValue) { public boolean onPreferenceChange(Preference preference, Object newValue) {
SystemProperties.set(BLUETOOTH_MAX_CONNECTED_AUDIO_DEVICES_PROPERTY, newValue.toString()); SystemProperties.set(BLUETOOTH_MAX_CONNECTED_AUDIO_DEVICES_PROPERTY, newValue.toString());
updateState(preference);
return true; return true;
} }
@@ -88,13 +89,13 @@ public class BluetoothMaxConnectedAudioDevicesPreferenceController extends
@Override @Override
protected void onDeveloperOptionsSwitchEnabled() { protected void onDeveloperOptionsSwitchEnabled() {
mPreference.setEnabled(true); mPreference.setEnabled(true);
mPreference.setValue(mListValues[0]); updateState(mPreference);
mPreference.setSummary(mListSummaries[0]);
} }
@Override @Override
protected void onDeveloperOptionsSwitchDisabled() { protected void onDeveloperOptionsSwitchDisabled() {
mPreference.setEnabled(false); mPreference.setEnabled(false);
SystemProperties.set(BLUETOOTH_MAX_CONNECTED_AUDIO_DEVICES_PROPERTY, mListValues[0]);
mPreference.setValue(mListValues[0]); mPreference.setValue(mListValues[0]);
mPreference.setSummary(mListSummaries[0]); mPreference.setSummary(mListSummaries[0]);
} }

View File

@@ -94,6 +94,8 @@ public class BluetoothMaxConnectedAudioDevicesPreferenceControllerTest {
BLUETOOTH_MAX_CONNECTED_AUDIO_DEVICES_PROPERTY); BLUETOOTH_MAX_CONNECTED_AUDIO_DEVICES_PROPERTY);
assertThat(currentValue).isEqualTo(mListValues[numberOfDevices]); assertThat(currentValue).isEqualTo(mListValues[numberOfDevices]);
assertThat(mPreference.getValue()).isEqualTo(mListValues[numberOfDevices]);
assertThat(mPreference.getSummary()).isEqualTo(mListSummaries[numberOfDevices]);
} }
} }
@@ -122,20 +124,28 @@ public class BluetoothMaxConnectedAudioDevicesPreferenceControllerTest {
@Test @Test
public void onDeveloperOptionsSwitchDisabled_shouldDisablePreference() { public void onDeveloperOptionsSwitchDisabled_shouldDisablePreference() {
mController.onDeveloperOptionsSwitchDisabled(); mController.onDeveloperOptionsSwitchDisabled();
mController.updateState(mPreference);
assertThat(mPreference.isEnabled()).isFalse(); assertThat(mPreference.isEnabled()).isFalse();
assertThat(mPreference.getValue()).isEqualTo(mListValues[0]); assertThat(mPreference.getValue()).isEqualTo(mListValues[0]);
assertThat(mPreference.getSummary()).isEqualTo(mListSummaries[0]); assertThat(mPreference.getSummary()).isEqualTo(mListSummaries[0]);
final String currentValue = SystemProperties.get(
BLUETOOTH_MAX_CONNECTED_AUDIO_DEVICES_PROPERTY);
assertThat(currentValue).isEqualTo(mListValues[0]);
} }
@Test @Test
public void onDeveloperOptionsSwitchEnabled_shouldEnablePreference() { public void onDeveloperOptionsSwitchEnabled_shouldEnablePreference() {
mController.onDeveloperOptionsSwitchEnabled(); for (int numberOfDevices = 0; numberOfDevices < mListValues.length; numberOfDevices++) {
mController.updateState(mPreference); mController.onDeveloperOptionsSwitchDisabled();
assertThat(mPreference.isEnabled()).isFalse();
assertThat(mPreference.isEnabled()).isTrue(); SystemProperties.set(BLUETOOTH_MAX_CONNECTED_AUDIO_DEVICES_PROPERTY,
assertThat(mPreference.getValue()).isEqualTo(mListValues[0]); mListValues[numberOfDevices]);
assertThat(mPreference.getSummary()).isEqualTo(mListSummaries[0]); mController.onDeveloperOptionsSwitchEnabled();
assertThat(mPreference.isEnabled()).isTrue();
assertThat(mPreference.getValue()).isEqualTo(mListValues[numberOfDevices]);
assertThat(mPreference.getSummary()).isEqualTo(mListSummaries[numberOfDevices]);
}
} }
} }