Separate category controller out of HearingDeviceControlsController
We're going to add more different device controls (such as hearing aids presets, volume offset controls or microphone volume controls) into "device_controls_general" PreferenceCategory. It's better to keep the category controller separated from the child controller to better maintain the visibility of the whole category and have a clearer stucture of these controllers. Bug: 300015207 Test: atest BluetoothDetailsHearingDeviceControllerTest Test: atest BluetoothDetailsHearingDeviceSettingsControllerTest Test: atest BluetoothDeviceDetailsFragmentTest Change-Id: I7f35b02a1120aefa8307e500f7abfce3b8055fbf
This commit is contained in:
@@ -150,14 +150,10 @@
|
||||
<string name="bluetooth_pair_other_ear_dialog_right_ear_positive_button">Pair right ear</string>
|
||||
<!-- Connected devices settings. Positive button of the dialog to help user to pair left ear of the hearing aid device. Dialog shows when only one of the hearing aid device set is connected. [CHAR LIMIT=20] -->
|
||||
<string name="bluetooth_pair_other_ear_dialog_left_ear_positive_button">Pair left ear</string>
|
||||
<!-- Title for all hearing devices related controls section. [CHAR LIMIT=60] -->
|
||||
<string name="bluetooth_device_controls_general">For all available hearing devices</string>
|
||||
<!-- Connected devices settings. Title of the preference to show the entrance of the hearing device settings related page. [CHAR LIMIT=65] -->
|
||||
<string name="bluetooth_device_controls_title">More hearing device settings</string>
|
||||
<!-- Connected devices settings. Summary of the preference to show the item in the hearing device settings related page. [CHAR LIMIT=120] -->
|
||||
<string name="bluetooth_device_controls_summary">Change cross-device settings like shortcut, and telecoil controls</string>
|
||||
<!-- Title for this device specific controls section. [CHAR LIMIT=30] -->
|
||||
<string name="bluetooth_device_controls_specific">For this device</string>
|
||||
<!-- Connected devices settings. Title of the preference to show the entrance of the hearing device settings page. [CHAR LIMIT=65 BACKUP_MESSAGE_ID=1895676556354697234] -->
|
||||
<string name="bluetooth_hearing_device_settings_title">Hearing device settings</string>
|
||||
<!-- Connected devices settings. Summary of the preference to show the entrance of the hearing device settings page. [CHAR LIMIT=65 BACKUP_MESSAGE_ID=8115767735418425663] -->
|
||||
<string name="bluetooth_hearing_device_settings_summary">Shortcut, hearing aid compatibility</string>
|
||||
<!-- Connected devices settings. Title of the preference to show the entrance of the audio output page. It can change different types of audio are played on phone or other bluetooth devices. [CHAR LIMIT=35] -->
|
||||
<string name="bluetooth_audio_routing_title">Audio output</string>
|
||||
<!-- Title for bluetooth audio routing page footer. [CHAR LIMIT=30] -->
|
||||
|
@@ -69,7 +69,7 @@
|
||||
android:key="device_companion_apps"/>
|
||||
|
||||
<PreferenceCategory
|
||||
android:key="device_controls_general" />
|
||||
android:key="hearing_device_group" />
|
||||
|
||||
<PreferenceCategory
|
||||
android:key="bluetooth_audio_device_type_group"/>
|
||||
|
@@ -0,0 +1,102 @@
|
||||
/*
|
||||
* Copyright (C) 2024 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.bluetooth;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.preference.PreferenceFragmentCompat;
|
||||
import androidx.preference.PreferenceScreen;
|
||||
|
||||
import com.android.settingslib.bluetooth.CachedBluetoothDevice;
|
||||
import com.android.settingslib.core.lifecycle.Lifecycle;
|
||||
|
||||
import com.google.common.annotations.VisibleForTesting;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* The controller of the hearing device controls.
|
||||
*
|
||||
* <p><b>Note:</b> It is responsible for creating the sub-controllers inside this preference
|
||||
* category controller.
|
||||
*/
|
||||
public class BluetoothDetailsHearingDeviceController extends BluetoothDetailsController {
|
||||
static final String KEY_HEARING_DEVICE_GROUP = "hearing_device_group";
|
||||
|
||||
private final List<BluetoothDetailsController> mControllers = new ArrayList<>();
|
||||
private Lifecycle mLifecycle;
|
||||
|
||||
public BluetoothDetailsHearingDeviceController(@NonNull Context context,
|
||||
@NonNull PreferenceFragmentCompat fragment,
|
||||
@NonNull CachedBluetoothDevice device,
|
||||
@NonNull Lifecycle lifecycle) {
|
||||
super(context, fragment, device, lifecycle);
|
||||
mLifecycle = lifecycle;
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
void setSubControllers(
|
||||
BluetoothDetailsHearingDeviceSettingsController hearingDeviceSettingsController) {
|
||||
mControllers.clear();
|
||||
mControllers.add(hearingDeviceSettingsController);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAvailable() {
|
||||
return mControllers.stream().anyMatch(BluetoothDetailsController::isAvailable);
|
||||
}
|
||||
|
||||
@Override
|
||||
@NonNull
|
||||
public String getPreferenceKey() {
|
||||
return KEY_HEARING_DEVICE_GROUP;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void init(PreferenceScreen screen) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void refresh() {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Initiates the sub controllers controlled by this group controller.
|
||||
*
|
||||
* <p><b>Note:</b> The caller must call this method when creating this class.
|
||||
*
|
||||
* @param isLaunchFromHearingDevicePage a boolean that determines if the caller is launch from
|
||||
* hearing device page
|
||||
*/
|
||||
void initSubControllers(boolean isLaunchFromHearingDevicePage) {
|
||||
mControllers.clear();
|
||||
// Don't need to show the entrance to hearing device page when launched from the same page
|
||||
if (!isLaunchFromHearingDevicePage) {
|
||||
mControllers.add(new BluetoothDetailsHearingDeviceSettingsController(mContext,
|
||||
mFragment, mCachedDevice, mLifecycle));
|
||||
}
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public List<BluetoothDetailsController> getSubControllers() {
|
||||
return mControllers;
|
||||
}
|
||||
}
|
@@ -16,6 +16,8 @@
|
||||
|
||||
package com.android.settings.bluetooth;
|
||||
|
||||
import static com.android.settings.bluetooth.BluetoothDetailsHearingDeviceController.KEY_HEARING_DEVICE_GROUP;
|
||||
|
||||
import android.content.Context;
|
||||
import android.text.TextUtils;
|
||||
|
||||
@@ -36,15 +38,13 @@ import com.google.common.annotations.VisibleForTesting;
|
||||
/**
|
||||
* The controller of the hearing device settings to launch Hearing device page.
|
||||
*/
|
||||
public class BluetoothDetailsHearingDeviceControlsController extends BluetoothDetailsController
|
||||
public class BluetoothDetailsHearingDeviceSettingsController extends BluetoothDetailsController
|
||||
implements Preference.OnPreferenceClickListener {
|
||||
|
||||
@VisibleForTesting
|
||||
static final String KEY_DEVICE_CONTROLS_GENERAL_GROUP = "device_controls_general";
|
||||
@VisibleForTesting
|
||||
static final String KEY_HEARING_DEVICE_CONTROLS = "hearing_device_controls";
|
||||
static final String KEY_HEARING_DEVICE_SETTINGS = "hearing_device_settings";
|
||||
|
||||
public BluetoothDetailsHearingDeviceControlsController(Context context,
|
||||
public BluetoothDetailsHearingDeviceSettingsController(Context context,
|
||||
PreferenceFragmentCompat fragment, CachedBluetoothDevice device, Lifecycle lifecycle) {
|
||||
super(context, fragment, device, lifecycle);
|
||||
lifecycle.addObserver(this);
|
||||
@@ -57,37 +57,39 @@ public class BluetoothDetailsHearingDeviceControlsController extends BluetoothDe
|
||||
|
||||
@Override
|
||||
protected void init(PreferenceScreen screen) {
|
||||
if (!mCachedDevice.isHearingAidDevice()) {
|
||||
if (!isAvailable()) {
|
||||
return;
|
||||
}
|
||||
|
||||
final PreferenceCategory prefCategory = screen.findPreference(getPreferenceKey());
|
||||
final Preference pref = createHearingDeviceControlsPreference(prefCategory.getContext());
|
||||
prefCategory.addPreference(pref);
|
||||
final PreferenceCategory group = screen.findPreference(KEY_HEARING_DEVICE_GROUP);
|
||||
final Preference pref = createHearingDeviceSettingsPreference(group.getContext());
|
||||
group.addPreference(pref);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void refresh() {}
|
||||
protected void refresh() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPreferenceKey() {
|
||||
return KEY_DEVICE_CONTROLS_GENERAL_GROUP;
|
||||
return KEY_HEARING_DEVICE_SETTINGS;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onPreferenceClick(Preference preference) {
|
||||
if (TextUtils.equals(preference.getKey(), KEY_HEARING_DEVICE_CONTROLS)) {
|
||||
if (TextUtils.equals(preference.getKey(), KEY_HEARING_DEVICE_SETTINGS)) {
|
||||
launchAccessibilityHearingDeviceSettings();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private Preference createHearingDeviceControlsPreference(Context context) {
|
||||
private Preference createHearingDeviceSettingsPreference(Context context) {
|
||||
final ArrowPreference preference = new ArrowPreference(context);
|
||||
preference.setKey(KEY_HEARING_DEVICE_CONTROLS);
|
||||
preference.setTitle(context.getString(R.string.bluetooth_device_controls_title));
|
||||
preference.setSummary(context.getString(R.string.bluetooth_device_controls_summary));
|
||||
preference.setKey(KEY_HEARING_DEVICE_SETTINGS);
|
||||
preference.setTitle(context.getString(R.string.bluetooth_hearing_device_settings_title));
|
||||
preference.setSummary(
|
||||
context.getString(R.string.bluetooth_hearing_device_settings_summary));
|
||||
preference.setOnPreferenceClickListener(this);
|
||||
|
||||
return preference;
|
@@ -326,16 +326,16 @@ public class BluetoothDeviceDetailsFragment extends RestrictedDashboardFragment
|
||||
lifecycle));
|
||||
controllers.add(new BluetoothDetailsPairOtherController(context, this, mCachedDevice,
|
||||
lifecycle));
|
||||
// Don't need to show hearing device again when launched from the same page.
|
||||
if (!isLaunchFromHearingDevicePage()) {
|
||||
controllers.add(new BluetoothDetailsHearingDeviceControlsController(context, this,
|
||||
mCachedDevice, lifecycle));
|
||||
}
|
||||
controllers.add(new BluetoothDetailsDataSyncController(context, this,
|
||||
mCachedDevice, lifecycle));
|
||||
controllers.add(
|
||||
new BluetoothDetailsExtraOptionsController(
|
||||
context, this, mCachedDevice, lifecycle));
|
||||
controllers.add(new BluetoothDetailsDataSyncController(context, this, mCachedDevice,
|
||||
lifecycle));
|
||||
controllers.add(new BluetoothDetailsExtraOptionsController(context, this, mCachedDevice,
|
||||
lifecycle));
|
||||
BluetoothDetailsHearingDeviceController hearingDeviceController =
|
||||
new BluetoothDetailsHearingDeviceController(context, this, mCachedDevice,
|
||||
lifecycle);
|
||||
controllers.add(hearingDeviceController);
|
||||
hearingDeviceController.initSubControllers(isLaunchFromHearingDevicePage());
|
||||
controllers.addAll(hearingDeviceController.getSubControllers());
|
||||
}
|
||||
return controllers;
|
||||
}
|
||||
|
@@ -0,0 +1,83 @@
|
||||
/*
|
||||
* Copyright (C) 2024 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.bluetooth;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.junit.MockitoJUnit;
|
||||
import org.mockito.junit.MockitoRule;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
|
||||
/** Tests for {@link BluetoothDetailsHearingDeviceController}. */
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
public class BluetoothDetailsHearingDeviceControllerTest extends
|
||||
BluetoothDetailsControllerTestBase {
|
||||
|
||||
@Rule
|
||||
public final MockitoRule mockito = MockitoJUnit.rule();
|
||||
|
||||
private BluetoothDetailsHearingDeviceController mHearingDeviceController;
|
||||
|
||||
@Mock
|
||||
private BluetoothDetailsHearingDeviceSettingsController mHearingDeviceSettingsController;
|
||||
|
||||
@Override
|
||||
public void setUp() {
|
||||
super.setUp();
|
||||
|
||||
mHearingDeviceController = new BluetoothDetailsHearingDeviceController(mContext,
|
||||
mFragment, mCachedDevice, mLifecycle);
|
||||
mHearingDeviceController.setSubControllers(mHearingDeviceSettingsController);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isAvailable_hearingDeviceSettingsAvailable_returnTrue() {
|
||||
when(mHearingDeviceSettingsController.isAvailable()).thenReturn(true);
|
||||
|
||||
assertThat(mHearingDeviceController.isAvailable()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isAvailable_noControllersAvailable_returnFalse() {
|
||||
when(mHearingDeviceSettingsController.isAvailable()).thenReturn(false);
|
||||
|
||||
assertThat(mHearingDeviceController.isAvailable()).isFalse();
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void initSubControllers_launchFromHearingDevicePage_hearingDeviceSettingsNotExist() {
|
||||
mHearingDeviceController.initSubControllers(true);
|
||||
|
||||
assertThat(mHearingDeviceController.getSubControllers().stream().anyMatch(
|
||||
c -> c instanceof BluetoothDetailsHearingDeviceSettingsController)).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void initSubControllers_notLaunchFromHearingDevicePage_hearingDeviceSettingsExist() {
|
||||
mHearingDeviceController.initSubControllers(false);
|
||||
|
||||
assertThat(mHearingDeviceController.getSubControllers().stream().anyMatch(
|
||||
c -> c instanceof BluetoothDetailsHearingDeviceSettingsController)).isTrue();
|
||||
}
|
||||
}
|
@@ -39,23 +39,24 @@ import org.mockito.junit.MockitoJUnit;
|
||||
import org.mockito.junit.MockitoRule;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
|
||||
/** Tests for {@link BluetoothDetailsHearingDeviceControlsController}. */
|
||||
/** Tests for {@link BluetoothDetailsHearingDeviceSettingsController}. */
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
public class BluetoothDetailsHearingDeviceControlsControllerTest extends
|
||||
public class BluetoothDetailsHearingDeviceSettingsControllerTest extends
|
||||
BluetoothDetailsControllerTestBase {
|
||||
|
||||
@Rule
|
||||
public final MockitoRule mockito = MockitoJUnit.rule();
|
||||
|
||||
@Captor
|
||||
private ArgumentCaptor<Intent> mIntentArgumentCaptor;
|
||||
private BluetoothDetailsHearingDeviceControlsController mController;
|
||||
private BluetoothDetailsHearingDeviceSettingsController mController;
|
||||
|
||||
@Override
|
||||
public void setUp() {
|
||||
super.setUp();
|
||||
|
||||
FakeFeatureFactory.setupForTest();
|
||||
mController = new BluetoothDetailsHearingDeviceControlsController(mActivity, mFragment,
|
||||
mController = new BluetoothDetailsHearingDeviceSettingsController(mActivity, mFragment,
|
||||
mCachedDevice, mLifecycle);
|
||||
when(mCachedDevice.isHearingAidDevice()).thenReturn(true);
|
||||
}
|
||||
@@ -75,12 +76,12 @@ public class BluetoothDetailsHearingDeviceControlsControllerTest extends
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onPreferenceClick_hearingDeviceControlsKey_LaunchExpectedFragment() {
|
||||
final Preference hearingControlsKeyPreference = new Preference(mContext);
|
||||
hearingControlsKeyPreference.setKey(
|
||||
BluetoothDetailsHearingDeviceControlsController.KEY_HEARING_DEVICE_CONTROLS);
|
||||
public void onPreferenceClick_hearingDeviceSettingsKey_launchExpectedFragment() {
|
||||
final Preference hearingDeviceSettingsPreference = new Preference(mContext);
|
||||
hearingDeviceSettingsPreference.setKey(
|
||||
BluetoothDetailsHearingDeviceSettingsController.KEY_HEARING_DEVICE_SETTINGS);
|
||||
|
||||
mController.onPreferenceClick(hearingControlsKeyPreference);
|
||||
mController.onPreferenceClick(hearingDeviceSettingsPreference);
|
||||
|
||||
assertStartActivityWithExpectedFragment(mActivity,
|
||||
AccessibilityHearingAidsFragment.class.getName());
|
@@ -18,7 +18,7 @@ package com.android.settings.bluetooth;
|
||||
|
||||
import static android.bluetooth.BluetoothDevice.BOND_NONE;
|
||||
|
||||
import static com.android.settings.bluetooth.BluetoothDetailsHearingDeviceControlsController.KEY_DEVICE_CONTROLS_GENERAL_GROUP;
|
||||
import static com.android.settings.bluetooth.BluetoothDetailsHearingDeviceSettingsController.KEY_HEARING_DEVICE_SETTINGS;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
@@ -237,7 +237,7 @@ public class BluetoothDeviceDetailsFragmentTest {
|
||||
|
||||
assertThat(controllerList.stream()
|
||||
.anyMatch(controller -> controller.getPreferenceKey().equals(
|
||||
KEY_DEVICE_CONTROLS_GENERAL_GROUP))).isFalse();
|
||||
KEY_HEARING_DEVICE_SETTINGS))).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -253,7 +253,7 @@ public class BluetoothDeviceDetailsFragmentTest {
|
||||
|
||||
assertThat(controllerList.stream()
|
||||
.anyMatch(controller -> controller.getPreferenceKey().equals(
|
||||
KEY_DEVICE_CONTROLS_GENERAL_GROUP))).isTrue();
|
||||
KEY_HEARING_DEVICE_SETTINGS))).isTrue();
|
||||
}
|
||||
|
||||
private InputDevice createInputDeviceWithMatchingBluetoothAddress() {
|
||||
|
Reference in New Issue
Block a user