Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit de2855ab authored by Hansong Zhang's avatar Hansong Zhang
Browse files

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
parent de4bef02
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -1630,7 +1630,7 @@
    <string name="bluetooth_dock_settings_remember">Remember settings</string>
    <!-- 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 -->
    <string name="bluetooth_max_connected_audio_devices_dialog_title">Select maximum number of connected Bluetooth audio devices</string>
+3 −2
Original line number Diff line number Diff line
@@ -67,6 +67,7 @@ public class BluetoothMaxConnectedAudioDevicesPreferenceController extends
    @Override
    public boolean onPreferenceChange(Preference preference, Object newValue) {
        SystemProperties.set(BLUETOOTH_MAX_CONNECTED_AUDIO_DEVICES_PROPERTY, newValue.toString());
        updateState(preference);
        return true;
    }

@@ -88,13 +89,13 @@ public class BluetoothMaxConnectedAudioDevicesPreferenceController extends
    @Override
    protected void onDeveloperOptionsSwitchEnabled() {
        mPreference.setEnabled(true);
        mPreference.setValue(mListValues[0]);
        mPreference.setSummary(mListSummaries[0]);
        updateState(mPreference);
    }

    @Override
    protected void onDeveloperOptionsSwitchDisabled() {
        mPreference.setEnabled(false);
        SystemProperties.set(BLUETOOTH_MAX_CONNECTED_AUDIO_DEVICES_PROPERTY, mListValues[0]);
        mPreference.setValue(mListValues[0]);
        mPreference.setSummary(mListSummaries[0]);
    }
+16 −6
Original line number Diff line number Diff line
@@ -94,6 +94,8 @@ public class BluetoothMaxConnectedAudioDevicesPreferenceControllerTest {
                    BLUETOOTH_MAX_CONNECTED_AUDIO_DEVICES_PROPERTY);

            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
    public void onDeveloperOptionsSwitchDisabled_shouldDisablePreference() {
        mController.onDeveloperOptionsSwitchDisabled();
        mController.updateState(mPreference);

        assertThat(mPreference.isEnabled()).isFalse();
        assertThat(mPreference.getValue()).isEqualTo(mListValues[0]);
        assertThat(mPreference.getSummary()).isEqualTo(mListSummaries[0]);
        final String currentValue = SystemProperties.get(
                BLUETOOTH_MAX_CONNECTED_AUDIO_DEVICES_PROPERTY);
        assertThat(currentValue).isEqualTo(mListValues[0]);
    }

    @Test
    public void onDeveloperOptionsSwitchEnabled_shouldEnablePreference() {
        for (int numberOfDevices = 0; numberOfDevices < mListValues.length; numberOfDevices++) {
            mController.onDeveloperOptionsSwitchDisabled();
            assertThat(mPreference.isEnabled()).isFalse();

            SystemProperties.set(BLUETOOTH_MAX_CONNECTED_AUDIO_DEVICES_PROPERTY,
                    mListValues[numberOfDevices]);
            mController.onDeveloperOptionsSwitchEnabled();
        mController.updateState(mPreference);

            assertThat(mPreference.isEnabled()).isTrue();
        assertThat(mPreference.getValue()).isEqualTo(mListValues[0]);
        assertThat(mPreference.getSummary()).isEqualTo(mListSummaries[0]);
            assertThat(mPreference.getValue()).isEqualTo(mListValues[numberOfDevices]);
            assertThat(mPreference.getSummary()).isEqualTo(mListSummaries[numberOfDevices]);
        }
    }
}