Merge "[HA Input] Add UI to support hearing device microphone change ability in device details page" into main
This commit is contained in:
@@ -108,7 +108,7 @@ public class HearingDeviceAudioRoutingBasePreferenceControllerTest {
|
||||
when(mBluetoothDevice.getAnonymizedAddress()).thenReturn(TEST_DEVICE_ADDRESS);
|
||||
when(mCachedBluetoothDevice.getAddress()).thenReturn(TEST_DEVICE_ADDRESS);
|
||||
doReturn(hearingDeviceAttribute).when(
|
||||
mAudioRoutingHelper).getMatchedHearingDeviceAttributes(any());
|
||||
mAudioRoutingHelper).getMatchedHearingDeviceAttributesForOutput(any());
|
||||
when(mAudioProductStrategyMedia.getAudioAttributesForLegacyStreamType(
|
||||
AudioManager.STREAM_MUSIC)).thenReturn((new AudioAttributes.Builder()).build());
|
||||
when(mAudioRoutingHelper.getAudioProductStrategies()).thenReturn(
|
||||
@@ -143,7 +143,8 @@ public class HearingDeviceAudioRoutingBasePreferenceControllerTest {
|
||||
|
||||
@Test
|
||||
public void onPreferenceChange_noMatchedDeviceAttributes_notCallSetStrategies() {
|
||||
when(mAudioRoutingHelper.getMatchedHearingDeviceAttributes(any())).thenReturn(null);
|
||||
when(mAudioRoutingHelper.getMatchedHearingDeviceAttributesForOutput(any())).thenReturn(
|
||||
null);
|
||||
|
||||
verify(mAudioRoutingHelper, never()).setPreferredDeviceRoutingStrategies(any(), isNull(),
|
||||
anyInt());
|
||||
|
@@ -56,6 +56,8 @@ public class BluetoothDetailsHearingDeviceControllerTest extends
|
||||
private BluetoothDetailsHearingAidsPresetsController mPresetsController;
|
||||
@Mock
|
||||
private BluetoothDetailsHearingDeviceSettingsController mHearingDeviceSettingsController;
|
||||
@Mock
|
||||
private BluetoothDetailsHearingDeviceInputRoutingController mInputRoutingController;
|
||||
|
||||
private BluetoothDetailsHearingDeviceController mHearingDeviceController;
|
||||
|
||||
@@ -67,7 +69,7 @@ public class BluetoothDetailsHearingDeviceControllerTest extends
|
||||
mHearingDeviceController = new BluetoothDetailsHearingDeviceController(mContext,
|
||||
mFragment, mLocalManager, mCachedDevice, mLifecycle);
|
||||
mHearingDeviceController.setSubControllers(mHearingDeviceSettingsController,
|
||||
mPresetsController);
|
||||
mPresetsController, mInputRoutingController);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -84,6 +86,13 @@ public class BluetoothDetailsHearingDeviceControllerTest extends
|
||||
assertThat(mHearingDeviceController.isAvailable()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isAvailable_inputRoutingControllersAvailable_returnFalse() {
|
||||
when(mInputRoutingController.isAvailable()).thenReturn(true);
|
||||
|
||||
assertThat(mHearingDeviceController.isAvailable()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isAvailable_noControllersAvailable_returnFalse() {
|
||||
when(mHearingDeviceSettingsController.isAvailable()).thenReturn(false);
|
||||
@@ -146,4 +155,24 @@ public class BluetoothDetailsHearingDeviceControllerTest extends
|
||||
assertThat(mHearingDeviceController.getSubControllers().stream().anyMatch(
|
||||
c -> c instanceof BluetoothDetailsAmbientVolumePreferenceController)).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
@RequiresFlagsEnabled(
|
||||
com.android.settingslib.flags.Flags.FLAG_HEARING_DEVICES_INPUT_ROUTING_CONTROL)
|
||||
public void initSubControllers_flagEnabled_inputRoutingControllerExist() {
|
||||
mHearingDeviceController.initSubControllers(false);
|
||||
|
||||
assertThat(mHearingDeviceController.getSubControllers().stream().anyMatch(
|
||||
c -> c instanceof BluetoothDetailsHearingDeviceInputRoutingController)).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
@RequiresFlagsDisabled(
|
||||
com.android.settingslib.flags.Flags.FLAG_HEARING_DEVICES_INPUT_ROUTING_CONTROL)
|
||||
public void initSubControllers_flagDisabled_inputRoutingControllerNotExist() {
|
||||
mHearingDeviceController.initSubControllers(false);
|
||||
|
||||
assertThat(mHearingDeviceController.getSubControllers().stream().anyMatch(
|
||||
c -> c instanceof BluetoothDetailsHearingDeviceInputRoutingController)).isFalse();
|
||||
}
|
||||
}
|
||||
|
@@ -0,0 +1,171 @@
|
||||
/*
|
||||
* 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.android.settings.bluetooth.BluetoothDetailsHearingDeviceController.KEY_HEARING_DEVICE_GROUP;
|
||||
import static com.android.settings.bluetooth.BluetoothDetailsHearingDeviceInputRoutingController.KEY_HEARING_DEVICE_INPUT_ROUTING;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.bluetooth.BluetoothDevice;
|
||||
import android.media.AudioDeviceInfo;
|
||||
import android.media.AudioManager;
|
||||
|
||||
import androidx.preference.Preference;
|
||||
import androidx.preference.PreferenceCategory;
|
||||
import androidx.test.core.app.ApplicationProvider;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.bluetooth.HearingDeviceInputRoutingPreference.InputRoutingValue;
|
||||
import com.android.settingslib.bluetooth.HapClientProfile;
|
||||
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.Spy;
|
||||
import org.mockito.junit.MockitoJUnit;
|
||||
import org.mockito.junit.MockitoRule;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
/** Tests for {@link BluetoothDetailsHearingDeviceInputRoutingController}. */
|
||||
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
public class BluetoothDetailsHearingDeviceInputRoutingControllerTest extends
|
||||
BluetoothDetailsControllerTestBase {
|
||||
@Rule
|
||||
public final MockitoRule mockito = MockitoJUnit.rule();
|
||||
|
||||
private static final String TEST_ADDRESS = "55:66:77:88:99:AA";
|
||||
|
||||
@Mock
|
||||
private BluetoothDevice mBluetoothDevice;
|
||||
@Mock
|
||||
private HapClientProfile mHapClientProfile;
|
||||
@Spy
|
||||
private AudioManager mAudioManager;
|
||||
|
||||
private BluetoothDetailsHearingDeviceInputRoutingController mController;
|
||||
|
||||
@Override
|
||||
public void setUp() {
|
||||
super.setUp();
|
||||
|
||||
mContext = spy(ApplicationProvider.getApplicationContext());
|
||||
mAudioManager = spy(mContext.getSystemService(AudioManager.class));
|
||||
when(mContext.getSystemService(AudioManager.class)).thenReturn(mAudioManager);
|
||||
setupDevice(makeDefaultDeviceConfig());
|
||||
when(mCachedDevice.getDevice()).thenReturn(mBluetoothDevice);
|
||||
PreferenceCategory deviceControls = new PreferenceCategory(mContext);
|
||||
deviceControls.setKey(KEY_HEARING_DEVICE_GROUP);
|
||||
mScreen.addPreference(deviceControls);
|
||||
mController = new BluetoothDetailsHearingDeviceInputRoutingController(mContext,
|
||||
mFragment, mCachedDevice, mLifecycle);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void init_getExpectedPreference() {
|
||||
mController.init(mScreen);
|
||||
|
||||
Preference pref = mScreen.findPreference(KEY_HEARING_DEVICE_INPUT_ROUTING);
|
||||
assertThat(pref.getKey()).isEqualTo(KEY_HEARING_DEVICE_INPUT_ROUTING);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void init_setPreferredMicrophoneTrue_expectedSummary() {
|
||||
when(mBluetoothDevice.isMicrophonePreferredForCalls()).thenReturn(true);
|
||||
|
||||
mController.init(mScreen);
|
||||
|
||||
Preference pref = mScreen.findPreference(KEY_HEARING_DEVICE_INPUT_ROUTING);
|
||||
assertThat(pref.getSummary().toString()).isEqualTo(mContext.getString(
|
||||
R.string.bluetooth_hearing_device_input_routing_hearing_device_option));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void init_setPreferredMicrophoneFalse_expectedSummary() {
|
||||
when(mBluetoothDevice.isMicrophonePreferredForCalls()).thenReturn(false);
|
||||
mController.init(mScreen);
|
||||
|
||||
Preference pref = mScreen.findPreference(KEY_HEARING_DEVICE_INPUT_ROUTING);
|
||||
assertThat(pref.getSummary().toString()).isEqualTo(mContext.getString(
|
||||
R.string.bluetooth_hearing_device_input_routing_builtin_option));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onInputRoutingUpdated_hearingDevice_setMicrophonePreferredForCallsTrue() {
|
||||
mController.init(mScreen);
|
||||
|
||||
mController.onInputRoutingUpdated(InputRoutingValue.HEARING_DEVICE);
|
||||
|
||||
verify(mBluetoothDevice).setMicrophonePreferredForCalls(true);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onInputRoutingUpdated_builtin_setMicrophonePreferredForCallsFalse() {
|
||||
mController.init(mScreen);
|
||||
|
||||
mController.onInputRoutingUpdated(InputRoutingValue.BUILTIN_MIC);
|
||||
|
||||
verify(mBluetoothDevice).setMicrophonePreferredForCalls(false);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isAvailable_validInput_supportHapProfile_returnTrue() {
|
||||
when(mCachedDevice.getAddress()).thenReturn(TEST_ADDRESS);
|
||||
AudioDeviceInfo[] mockInfo = new AudioDeviceInfo[] {mockTestAddressInfo(TEST_ADDRESS)};
|
||||
when(mAudioManager.getDevices(AudioManager.GET_DEVICES_INPUTS)).thenReturn(mockInfo);
|
||||
when(mCachedDevice.getProfiles()).thenReturn(List.of(mHapClientProfile));
|
||||
|
||||
assertThat(mController.isAvailable()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isAvailable_notSupportHapProfile_returnFalse() {
|
||||
when(mCachedDevice.getAddress()).thenReturn(TEST_ADDRESS);
|
||||
AudioDeviceInfo[] mockInfo = new AudioDeviceInfo[] {mockTestAddressInfo(TEST_ADDRESS)};
|
||||
when(mAudioManager.getDevices(AudioManager.GET_DEVICES_INPUTS)).thenReturn(mockInfo);
|
||||
when(mCachedDevice.getProfiles()).thenReturn(Collections.emptyList());
|
||||
|
||||
assertThat(mController.isAvailable()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isAvailable_notValidInputDevice_returnFalse() {
|
||||
when(mCachedDevice.getAddress()).thenReturn(TEST_ADDRESS);
|
||||
when(mAudioManager.getDevices(AudioManager.GET_DEVICES_INPUTS)).thenReturn(
|
||||
new AudioDeviceInfo[] {});
|
||||
when(mCachedDevice.getProfiles()).thenReturn(List.of(mHapClientProfile));
|
||||
|
||||
assertThat(mController.isAvailable()).isFalse();
|
||||
}
|
||||
|
||||
private AudioDeviceInfo mockTestAddressInfo(String address) {
|
||||
final AudioDeviceInfo info = mock(AudioDeviceInfo.class);
|
||||
when(info.getType()).thenReturn(AudioDeviceInfo.TYPE_BLE_HEADSET);
|
||||
when(info.getAddress()).thenReturn(address);
|
||||
return info;
|
||||
}
|
||||
}
|
@@ -0,0 +1,114 @@
|
||||
/*
|
||||
* 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.ArgumentMatchers.anyInt;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.verify;
|
||||
|
||||
import android.app.Dialog;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.widget.RadioGroup;
|
||||
|
||||
import androidx.test.core.app.ApplicationProvider;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.bluetooth.HearingDeviceInputRoutingPreference.InputRoutingValue;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.junit.MockitoJUnit;
|
||||
import org.mockito.junit.MockitoRule;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
|
||||
/** Tests for {@link HearingDeviceInputRoutingPreference}. */
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
public class HearingDeviceInputRoutingPreferenceTest {
|
||||
@Rule
|
||||
public final MockitoRule mockito = MockitoJUnit.rule();
|
||||
|
||||
private final Context mContext = ApplicationProvider.getApplicationContext();
|
||||
private HearingDeviceInputRoutingPreference mPreference;
|
||||
private TestInputRoutingCallback mTestInputRoutingCallback;
|
||||
private View mDialogView;
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
mDialogView = LayoutInflater.from(mContext).inflate(
|
||||
R.layout.hearing_device_input_routing_dialog, null);
|
||||
mTestInputRoutingCallback = spy(new TestInputRoutingCallback());
|
||||
mPreference = new HearingDeviceInputRoutingPreference(mContext);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onClick_checkToBuiltinMic_callbackWithBuiltinSpeaker() {
|
||||
mPreference.setChecked(InputRoutingValue.HEARING_DEVICE);
|
||||
mPreference.setInputRoutingCallback(mTestInputRoutingCallback);
|
||||
mPreference.onBindDialogView(mDialogView);
|
||||
RadioGroup radioGroup = mDialogView.requireViewById(R.id.input_routing_group);
|
||||
Dialog dialog = mPreference.getDialog();
|
||||
|
||||
radioGroup.check(R.id.input_from_builtin_mic);
|
||||
mPreference.onClick(dialog, DialogInterface.BUTTON_POSITIVE);
|
||||
|
||||
verify(mTestInputRoutingCallback).onInputRoutingUpdated(InputRoutingValue.BUILTIN_MIC);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setChecked_checkNoChange_noCallback() {
|
||||
mPreference.setChecked(InputRoutingValue.HEARING_DEVICE);
|
||||
mPreference.setInputRoutingCallback(mTestInputRoutingCallback);
|
||||
mPreference.onBindDialogView(mDialogView);
|
||||
Dialog dialog = mPreference.getDialog();
|
||||
|
||||
mPreference.setChecked(InputRoutingValue.HEARING_DEVICE);
|
||||
mPreference.onClick(dialog, DialogInterface.BUTTON_POSITIVE);
|
||||
|
||||
verify(mTestInputRoutingCallback, never()).onInputRoutingUpdated(anyInt());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setChecked_builtinMic_expectedSummary() {
|
||||
mPreference.setChecked(InputRoutingValue.BUILTIN_MIC);
|
||||
|
||||
assertThat(mPreference.getSummary().toString()).isEqualTo(
|
||||
mContext.getString(R.string.bluetooth_hearing_device_input_routing_builtin_option));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setChecked_hearingDevice_expectedSummary() {
|
||||
mPreference.setChecked(InputRoutingValue.HEARING_DEVICE);
|
||||
|
||||
assertThat(mPreference.getSummary().toString()).isEqualTo(mContext.getString(
|
||||
R.string.bluetooth_hearing_device_input_routing_hearing_device_option));
|
||||
}
|
||||
|
||||
private static class TestInputRoutingCallback implements
|
||||
HearingDeviceInputRoutingPreference.InputRoutingCallback {
|
||||
|
||||
@Override
|
||||
public void onInputRoutingUpdated(int selectedInputRoutingUiValue) {}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user