From 77ee7ea00dc388750b4b1cc0b9f592eb5c446fbd Mon Sep 17 00:00:00 2001 From: Jack He Date: Mon, 26 Feb 2018 22:58:56 -0800 Subject: [PATCH] Bluetooth: Use config value for default max connected audio devices * The first option in Bluetooth max connected audio devices preference should be using system default * Added template based string array to show system default in the list preference and in preference summary when default is chosen * Reset max connected audio devices property to empty string when development setting is disabled or when system default is chosen * Fix a bug by saving selected value to list preference so that it persists when user re-opens development settings Bug: 64767509 Test: Enable and disable multi-device mode in development settings Change-Id: I4915f12df0ac0e6f715e44e0df4a3707dde8d1a4 Merged-In: I4915f12df0ac0e6f715e44e0df4a3707dde8d1a4 --- res/values/arrays.xml | 6 ++- .../development/DevelopmentSettings.java | 54 +++++++++++++------ 2 files changed, 43 insertions(+), 17 deletions(-) diff --git a/res/values/arrays.xml b/res/values/arrays.xml index 3984c214bf7..2e4738bdfcb 100644 --- a/res/values/arrays.xml +++ b/res/values/arrays.xml @@ -318,7 +318,8 @@ - 1 (Default) + Use System Default: %1$d + 1 2 3 4 @@ -326,7 +327,8 @@ - + + 1 2 3 diff --git a/src/com/android/settings/development/DevelopmentSettings.java b/src/com/android/settings/development/DevelopmentSettings.java index 2912e174b60..078489efeb9 100644 --- a/src/com/android/settings/development/DevelopmentSettings.java +++ b/src/com/android/settings/development/DevelopmentSettings.java @@ -901,6 +901,7 @@ public class DevelopmentSettings extends RestrictedSettingsFragment } writeOverlayDisplayDevicesOptions(null); writeAppProcessLimitOptions(null); + writeBluetoothMaxConnectedAudioDevices(""); mHaveDebugSettings = false; updateAllOptions(); mDontPokeProperties = false; @@ -1884,12 +1885,44 @@ public class DevelopmentSettings extends RestrictedSettingsFragment mBluetoothSelectA2dpLdacPlaybackQuality.setValue(values[index]); mBluetoothSelectA2dpLdacPlaybackQuality.setSummary(summaries[index]); - // Init the maximum connected devices - Default - values = getResources().getStringArray(R.array.bluetooth_max_connected_audio_devices_values); - summaries = getResources().getStringArray(R.array.bluetooth_max_connected_audio_devices); - index = 0; - mBluetoothSelectMaxConnectedAudioDevices.setValue(values[index]); - mBluetoothSelectMaxConnectedAudioDevices.setSummary(summaries[index]); + // Init the maximum connected devices + initBluetoothMaxConnectedAudioDevicesPreference(); + updateBluetoothMaxConnectedAudioDevicesPreference(); + } + + private void initBluetoothMaxConnectedAudioDevicesPreference() { + int defaultMaxConnectedAudioDevices = getResources().getInteger( + com.android.internal.R.integer.config_bluetooth_max_connected_audio_devices); + final CharSequence[] entries = mBluetoothSelectMaxConnectedAudioDevices.getEntries(); + entries[0] = String.format(entries[0].toString(), defaultMaxConnectedAudioDevices); + mBluetoothSelectMaxConnectedAudioDevices.setEntries(entries); + } + + private void updateBluetoothMaxConnectedAudioDevicesPreference() { + final CharSequence[] entries = mBluetoothSelectMaxConnectedAudioDevices.getEntries(); + final String currentValue = + SystemProperties.get(BLUETOOTH_MAX_CONNECTED_AUDIO_DEVICES_PROPERTY); + int index = 0; + if (!currentValue.isEmpty()) { + index = mBluetoothSelectMaxConnectedAudioDevices.findIndexOfValue(currentValue); + if (index < 0) { + // Reset property value when value is illegal + SystemProperties.set(BLUETOOTH_MAX_CONNECTED_AUDIO_DEVICES_PROPERTY, ""); + index = 0; + } + } + mBluetoothSelectMaxConnectedAudioDevices.setValueIndex(index); + mBluetoothSelectMaxConnectedAudioDevices.setSummary(entries[index]); + } + + private void writeBluetoothMaxConnectedAudioDevices(Object newValue) { + String newValueString = newValue.toString(); + if (mBluetoothSelectMaxConnectedAudioDevices.findIndexOfValue(newValueString) <= 0) { + // Reset property value when default is chosen or when value is illegal + newValueString = ""; + } + SystemProperties.set(BLUETOOTH_MAX_CONNECTED_AUDIO_DEVICES_PROPERTY, newValueString); + updateBluetoothMaxConnectedAudioDevicesPreference(); } private void writeBluetoothAvrcpVersion(Object newValue) { @@ -2058,15 +2091,6 @@ public class DevelopmentSettings extends RestrictedSettingsFragment } } - private void writeBluetoothMaxConnectedAudioDevices(Object newValue) { - SystemProperties.set(BLUETOOTH_MAX_CONNECTED_AUDIO_DEVICES_PROPERTY, newValue.toString()); - int index = mBluetoothSelectMaxConnectedAudioDevices.findIndexOfValue(newValue.toString()); - if (index >= 0) { - String[] titles = getResources().getStringArray(R.array.bluetooth_max_connected_audio_devices); - mBluetoothSelectMaxConnectedAudioDevices.setSummary(titles[index]); - } - } - private void writeBluetoothConfigurationOption(Preference preference, Object newValue) { String[] summaries;