Add developer menu to select max number of connected audio devices

The new developer option modifies the system property
"persist.bluetooth.maxconnectedaudiodevices"; it allows testing
multiple connected devices for A2DP, AVRCP, HFP.

Bug: 71603731
Test: Robolectric test
Change-Id: Ie7887065f98193f4f34e0ff4a29959694e417124
This commit is contained in:
Hansong Zhang
2018-01-04 16:38:15 -08:00
parent 27e7280b21
commit b2730b7b10
6 changed files with 274 additions and 0 deletions

View File

@@ -309,6 +309,24 @@
<item>Never time out</item>
</string-array>
<!-- Bluetooth developer settings: Titles for maximum number of connected audio devices -->
<string-array name="bluetooth_max_connected_audio_devices">
<item>1 (Default)</item>
<item>2</item>
<item>3</item>
<item>4</item>
<item>5</item>
</string-array>
<!-- Bluetooth developer settings: Values for maximum number of connected audio devices -->
<string-array name="bluetooth_max_connected_audio_devices_values">
<item>1</item>
<item>2</item>
<item>3</item>
<item>4</item>
<item>5</item>
</string-array>
<!-- Match this with drawable.wifi_signal. --> <skip />
<!-- Wi-Fi settings. The signal strength a Wi-Fi network has. -->
<string-array name="wifi_signal">

View File

@@ -1624,6 +1624,11 @@
<!-- Bluetooth settings. Dock Setting Dialog - Remember setting and don't ask user again -->
<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>
<!-- 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>
<!-- Wifi Display settings. The title of the screen. [CHAR LIMIT=40] -->
<string name="wifi_display_settings_title">Cast</string>
<!-- Wifi Display settings. The title of a menu item to enable wireless display [CHAR LIMIT=40] -->

View File

@@ -286,6 +286,13 @@
android:entries="@array/bluetooth_a2dp_codec_ldac_playback_quality_titles"
android:entryValues="@array/bluetooth_a2dp_codec_ldac_playback_quality_values" />
<ListPreference
android:key="bluetooth_max_connected_audio_devices"
android:title="@string/bluetooth_max_connected_audio_devices_string"
android:dialogTitle="@string/bluetooth_max_connected_audio_devices_dialog_title"
android:entries="@array/bluetooth_max_connected_audio_devices"
android:entryValues="@array/bluetooth_max_connected_audio_devices_values" />
</PreferenceCategory>
<PreferenceCategory android:key="debug_input_category"

View File

@@ -0,0 +1,102 @@
/*
* Copyright (C) 2018 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.android.settings.development;
import android.content.Context;
import android.os.SystemProperties;
import android.support.annotation.VisibleForTesting;
import android.support.v7.preference.ListPreference;
import android.support.v7.preference.Preference;
import android.support.v7.preference.PreferenceScreen;
import android.text.TextUtils;
import com.android.settings.R;
import com.android.settings.core.PreferenceControllerMixin;
import com.android.settingslib.development.DeveloperOptionsPreferenceController;
public class BluetoothMaxConnectedAudioDevicesPreferenceController extends
DeveloperOptionsPreferenceController implements Preference.OnPreferenceChangeListener,
PreferenceControllerMixin {
private static final String BLUETOOTH_MAX_CONNECTED_AUDIO_DEVICES_KEY =
"bluetooth_max_connected_audio_devices";
@VisibleForTesting
static final String BLUETOOTH_MAX_CONNECTED_AUDIO_DEVICES_PROPERTY =
"persist.bluetooth.maxconnectedaudiodevices";
private final String[] mListValues;
private final String[] mListSummaries;
private ListPreference mPreference;
public BluetoothMaxConnectedAudioDevicesPreferenceController(Context context) {
super(context);
mListValues = context.getResources()
.getStringArray(R.array.bluetooth_max_connected_audio_devices_values);
mListSummaries = context.getResources()
.getStringArray(R.array.bluetooth_max_connected_audio_devices);
}
@Override
public String getPreferenceKey() {
return BLUETOOTH_MAX_CONNECTED_AUDIO_DEVICES_KEY;
}
@Override
public void displayPreference(PreferenceScreen screen) {
super.displayPreference(screen);
mPreference = (ListPreference) screen.findPreference(getPreferenceKey());
}
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
SystemProperties.set(BLUETOOTH_MAX_CONNECTED_AUDIO_DEVICES_PROPERTY, newValue.toString());
return true;
}
@Override
public void updateState(Preference preference) {
final String currentValue = SystemProperties.get(
BLUETOOTH_MAX_CONNECTED_AUDIO_DEVICES_PROPERTY);
int index = 0; // Defaults to 1 device
for (int i = 0; i < mListValues.length; i++) {
if (TextUtils.equals(currentValue, mListValues[i])) {
index = i;
break;
}
}
mPreference.setValue(mListValues[index]);
mPreference.setSummary(mListSummaries[index]);
}
@Override
protected void onDeveloperOptionsSwitchEnabled() {
mPreference.setEnabled(true);
mPreference.setValue(mListValues[0]);
mPreference.setSummary(mListSummaries[0]);
}
@Override
protected void onDeveloperOptionsSwitchDisabled() {
mPreference.setEnabled(false);
mPreference.setValue(mListValues[0]);
mPreference.setSummary(mListSummaries[0]);
}
}

View File

@@ -417,6 +417,7 @@ public class DevelopmentSettingsDashboardFragment extends RestrictedDashboardFra
bluetoothA2dpConfigStore));
controllers.add(new BluetoothAudioQualityPreferenceController(context, lifecycle,
bluetoothA2dpConfigStore));
controllers.add(new BluetoothMaxConnectedAudioDevicesPreferenceController(context));
controllers.add(new ShowTapsPreferenceController(context));
controllers.add(new PointerLocationPreferenceController(context));
controllers.add(new ShowSurfaceUpdatesPreferenceController(context));

View File

@@ -0,0 +1,141 @@
/*
* Copyright (C) 2018 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.android.settings.development;
import static com.android.settings.development.BluetoothMaxConnectedAudioDevicesPreferenceController
.BLUETOOTH_MAX_CONNECTED_AUDIO_DEVICES_PROPERTY;
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.Mockito.when;
import android.content.Context;
import android.os.SystemProperties;
import android.support.v7.preference.ListPreference;
import android.support.v7.preference.PreferenceScreen;
import com.android.settings.R;
import com.android.settings.TestConfig;
import com.android.settings.testutils.SettingsRobolectricTestRunner;
import com.android.settings.testutils.shadow.SettingsShadowSystemProperties;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Config;
@RunWith(SettingsRobolectricTestRunner.class)
@Config(manifest = TestConfig.MANIFEST_PATH,
sdk = TestConfig.SDK_VERSION,
shadows = {SettingsShadowSystemProperties.class})
public class BluetoothMaxConnectedAudioDevicesPreferenceControllerTest {
@Mock
private PreferenceScreen mPreferenceScreen;
private Context mContext;
private ListPreference mPreference;
private BluetoothMaxConnectedAudioDevicesPreferenceController mController;
/**
* 0: 1 device maximum (Default)
* 1: 2 devices maximum
* 2: 3 devices maximum
* 3: 4 devices maximum
* 4: 5 devices maximum
*/
private String[] mListValues;
private String[] mListSummaries;
@Before
public void setup() {
MockitoAnnotations.initMocks(this);
mContext = RuntimeEnvironment.application;
mPreference = new ListPreference(mContext);
mListValues = mContext.getResources().getStringArray(
R.array.bluetooth_max_connected_audio_devices_values);
mListSummaries = mContext.getResources().getStringArray(
R.array.bluetooth_max_connected_audio_devices);
mController = new BluetoothMaxConnectedAudioDevicesPreferenceController(mContext);
when(mPreferenceScreen.findPreference(mController.getPreferenceKey())).thenReturn(
mPreference);
mController.displayPreference(mPreferenceScreen);
}
@After
public void teardown() {
SettingsShadowSystemProperties.clear();
}
@Test
public void onPreferenceChange_setNumberOfDevices() {
for (int numberOfDevices = 0; numberOfDevices < mListValues.length; numberOfDevices++) {
mController.onPreferenceChange(mPreference, mListValues[numberOfDevices]);
final String currentValue = SystemProperties.get(
BLUETOOTH_MAX_CONNECTED_AUDIO_DEVICES_PROPERTY);
assertThat(currentValue).isEqualTo(mListValues[numberOfDevices]);
}
}
@Test
public void updateState_NumberOfDevicesUpdated_shouldSetPreference() {
for (int numberOfDevices = 0; numberOfDevices < mListValues.length; numberOfDevices++) {
SystemProperties.set(BLUETOOTH_MAX_CONNECTED_AUDIO_DEVICES_PROPERTY,
mListValues[numberOfDevices]);
mController.updateState(mPreference);
assertThat(mPreference.getValue()).isEqualTo(mListValues[numberOfDevices]);
assertThat(mPreference.getSummary()).isEqualTo(mListSummaries[numberOfDevices]);
}
}
@Test
public void updateState_noValueSet_shouldSetDefaultTo1device() {
SystemProperties.set(BLUETOOTH_MAX_CONNECTED_AUDIO_DEVICES_PROPERTY, "garbage");
mController.updateState(mPreference);
assertThat(mPreference.getValue()).isEqualTo(mListValues[0]);
assertThat(mPreference.getSummary()).isEqualTo(mListSummaries[0]);
}
@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]);
}
@Test
public void onDeveloperOptionsSwitchEnabled_shouldEnablePreference() {
mController.onDeveloperOptionsSwitchEnabled();
mController.updateState(mPreference);
assertThat(mPreference.isEnabled()).isTrue();
assertThat(mPreference.getValue()).isEqualTo(mListValues[0]);
assertThat(mPreference.getSummary()).isEqualTo(mListSummaries[0]);
}
}