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:
Angela Wang
2024-02-27 13:39:37 +00:00
parent c59c3a3d4f
commit 4af270b231
8 changed files with 232 additions and 48 deletions

View File

@@ -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();
}
}

View File

@@ -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());

View File

@@ -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() {