Move 'Audio Output' to Accessibility hearing device page
* Extract the common part into HearingAidHelper. * Remove abstract getHearingDevice(). Change to get the hearing device when needed. * Move several classes from Bluetooth into Accessibility Bug: 281783079 Test: make RunSettingsRoboTests ROBOTEST_FILTER="(HearingDeviceAudioRoutingBasePreferenceControllerTest|AccessibilityHearingAidPreferenceControllerTest|HearingAidHelperTest|HearingAidAudioRoutingPreferenceControllerTest|HearingDeviceCallRoutingPreferenceControllerTest)" Change-Id: I79049107409b7086c6dcc8d48a6323e171ed1535
This commit is contained in:
@@ -1,92 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2022 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.BluetoothDetailsAudioRoutingController.KEY_AUDIO_ROUTING;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.util.FeatureFlagUtils;
|
||||
|
||||
import androidx.preference.Preference;
|
||||
import androidx.preference.PreferenceCategory;
|
||||
|
||||
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 BluetoothDetailsAudioRoutingController}. */
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
public class BluetoothDetailsAudioRoutingControllerTest extends
|
||||
BluetoothDetailsControllerTestBase {
|
||||
@Rule
|
||||
public final MockitoRule mockito = MockitoJUnit.rule();
|
||||
|
||||
private static final String TEST_ADDRESS = "55:66:77:88:99:AA";
|
||||
|
||||
private BluetoothDetailsAudioRoutingController mController;
|
||||
|
||||
@Override
|
||||
public void setUp() {
|
||||
super.setUp();
|
||||
|
||||
mController = new BluetoothDetailsAudioRoutingController(mContext, mFragment, mCachedDevice,
|
||||
mLifecycle);
|
||||
final PreferenceCategory preferenceCategory = new PreferenceCategory(mContext);
|
||||
preferenceCategory.setKey(mController.getPreferenceKey());
|
||||
mScreen.addPreference(preferenceCategory);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isAvailable_isHearingAidDevice_available() {
|
||||
FeatureFlagUtils.setEnabled(mContext,
|
||||
FeatureFlagUtils.SETTINGS_AUDIO_ROUTING, true);
|
||||
when(mCachedDevice.isHearingAidDevice()).thenReturn(true);
|
||||
|
||||
assertThat(mController.isAvailable()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isAvailable_isNotHearingAidDevice_notAvailable() {
|
||||
FeatureFlagUtils.setEnabled(mContext,
|
||||
FeatureFlagUtils.SETTINGS_AUDIO_ROUTING, true);
|
||||
when(mCachedDevice.isHearingAidDevice()).thenReturn(false);
|
||||
|
||||
assertThat(mController.isAvailable()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void init_isHearingAidDevice_expectedAudioRoutingPreference() {
|
||||
when(mCachedDevice.isHearingAidDevice()).thenReturn(true);
|
||||
when(mCachedDevice.getAddress()).thenReturn(TEST_ADDRESS);
|
||||
|
||||
mController.init(mScreen);
|
||||
final Preference preference = mScreen.findPreference(KEY_AUDIO_ROUTING);
|
||||
final String address = preference.getExtras().getString(
|
||||
BluetoothDeviceDetailsFragment.KEY_DEVICE_ADDRESS);
|
||||
final String fragment = preference.getFragment();
|
||||
|
||||
assertThat(address).isEqualTo(TEST_ADDRESS);
|
||||
assertThat(fragment).isEqualTo(BluetoothDetailsAudioRoutingFragment.class.getName());
|
||||
|
||||
}
|
||||
}
|
@@ -1,96 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2023 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 android.bluetooth.BluetoothDevice;
|
||||
import android.content.Context;
|
||||
import android.os.Bundle;
|
||||
|
||||
import androidx.test.core.app.ApplicationProvider;
|
||||
|
||||
import com.android.settings.testutils.shadow.ShadowBluetoothUtils;
|
||||
import com.android.settingslib.bluetooth.CachedBluetoothDevice;
|
||||
import com.android.settingslib.bluetooth.CachedBluetoothDeviceManager;
|
||||
import com.android.settingslib.bluetooth.LocalBluetoothAdapter;
|
||||
import com.android.settingslib.bluetooth.LocalBluetoothManager;
|
||||
|
||||
import org.junit.Before;
|
||||
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;
|
||||
import org.robolectric.annotation.Config;
|
||||
|
||||
/** Tests for {@link BluetoothDetailsAudioRoutingFragment}. */
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
@Config(shadows = {ShadowBluetoothUtils.class})
|
||||
public class BluetoothDetailsAudioRoutingFragmentTest {
|
||||
|
||||
@Rule
|
||||
public MockitoRule mMockitoRule = MockitoJUnit.rule();
|
||||
|
||||
private static final String TEST_ADDRESS = "55:66:77:88:99:AA";
|
||||
|
||||
private final Context mContext = ApplicationProvider.getApplicationContext();
|
||||
|
||||
private BluetoothDetailsAudioRoutingFragment mFragment;
|
||||
@Mock
|
||||
private LocalBluetoothManager mLocalBluetoothManager;
|
||||
@Mock
|
||||
private CachedBluetoothDeviceManager mCachedDeviceManager;
|
||||
@Mock
|
||||
private LocalBluetoothAdapter mLocalBluetoothAdapter;
|
||||
@Mock
|
||||
private BluetoothDevice mBluetoothDevice;
|
||||
@Mock
|
||||
private CachedBluetoothDevice mCachedDevice;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
setupEnvironment();
|
||||
|
||||
when(mLocalBluetoothAdapter.getRemoteDevice(TEST_ADDRESS)).thenReturn(mBluetoothDevice);
|
||||
when(mCachedDevice.getAddress()).thenReturn(TEST_ADDRESS);
|
||||
when(mCachedDeviceManager.findDevice(mBluetoothDevice)).thenReturn(mCachedDevice);
|
||||
|
||||
mFragment = new BluetoothDetailsAudioRoutingFragment();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onAttach_setArgumentsWithAddress_expectedCachedDeviceWithAddress() {
|
||||
final Bundle args = new Bundle();
|
||||
args.putString(BluetoothDeviceDetailsFragment.KEY_DEVICE_ADDRESS, TEST_ADDRESS);
|
||||
mFragment.setArguments(args);
|
||||
|
||||
mFragment.onAttach(mContext);
|
||||
|
||||
assertThat(mFragment.mCachedDevice.getAddress()).isEqualTo(TEST_ADDRESS);
|
||||
}
|
||||
|
||||
private void setupEnvironment() {
|
||||
ShadowBluetoothUtils.sLocalBluetoothManager = mLocalBluetoothManager;
|
||||
when(mLocalBluetoothManager.getCachedDeviceManager()).thenReturn(mCachedDeviceManager);
|
||||
when(mLocalBluetoothManager.getBluetoothAdapter()).thenReturn(mLocalBluetoothAdapter);
|
||||
}
|
||||
}
|
@@ -1,165 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2023 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.any;
|
||||
import static org.mockito.ArgumentMatchers.anyInt;
|
||||
import static org.mockito.ArgumentMatchers.isNull;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.bluetooth.BluetoothDevice;
|
||||
import android.content.Context;
|
||||
import android.media.AudioAttributes;
|
||||
import android.media.AudioDeviceAttributes;
|
||||
import android.media.AudioDeviceInfo;
|
||||
import android.media.AudioManager;
|
||||
import android.media.audiopolicy.AudioProductStrategy;
|
||||
|
||||
import androidx.preference.ListPreference;
|
||||
import androidx.test.core.app.ApplicationProvider;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settingslib.bluetooth.CachedBluetoothDevice;
|
||||
import com.android.settingslib.bluetooth.HearingAidAudioRoutingConstants;
|
||||
import com.android.settingslib.bluetooth.HearingAidAudioRoutingHelper;
|
||||
|
||||
import org.junit.Before;
|
||||
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.List;
|
||||
|
||||
/** Tests for {@link HearingDeviceAudioRoutingBasePreferenceController}. */
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
public class HearingDeviceAudioRoutingBasePreferenceControllerTest {
|
||||
|
||||
@Rule
|
||||
public MockitoRule mMockitoRule = MockitoJUnit.rule();
|
||||
|
||||
@Spy
|
||||
private final Context mContext = ApplicationProvider.getApplicationContext();
|
||||
private static final String TEST_DEVICE_ADDRESS = "00:A1:A1:A1:A1:A1";
|
||||
private static final String FAKE_KEY = "fake_key";
|
||||
|
||||
@Mock
|
||||
private AudioProductStrategy mAudioProductStrategyMedia;
|
||||
@Mock
|
||||
private CachedBluetoothDevice mCachedBluetoothDevice;
|
||||
@Mock
|
||||
private BluetoothDevice mBluetoothDevice;
|
||||
@Spy
|
||||
private HearingAidAudioRoutingHelper mHelper = new HearingAidAudioRoutingHelper(mContext);
|
||||
private final ListPreference mListPreference = new ListPreference(mContext);
|
||||
private TestHearingDeviceAudioRoutingBasePreferenceController mController;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
final AudioDeviceAttributes hearingDeviceAttribute = new AudioDeviceAttributes(
|
||||
AudioDeviceAttributes.ROLE_OUTPUT,
|
||||
AudioDeviceInfo.TYPE_HEARING_AID,
|
||||
TEST_DEVICE_ADDRESS);
|
||||
|
||||
when(mCachedBluetoothDevice.getDevice()).thenReturn(mBluetoothDevice);
|
||||
when(mBluetoothDevice.getAnonymizedAddress()).thenReturn(TEST_DEVICE_ADDRESS);
|
||||
when(mCachedBluetoothDevice.getAddress()).thenReturn(TEST_DEVICE_ADDRESS);
|
||||
when(mHelper.getMatchedHearingDeviceAttributes(any())).thenReturn(hearingDeviceAttribute);
|
||||
when(mAudioProductStrategyMedia.getAudioAttributesForLegacyStreamType(
|
||||
AudioManager.STREAM_MUSIC))
|
||||
.thenReturn((new AudioAttributes.Builder()).build());
|
||||
when(mHelper.getAudioProductStrategies()).thenReturn(List.of(mAudioProductStrategyMedia));
|
||||
|
||||
mController = new TestHearingDeviceAudioRoutingBasePreferenceController(mContext, FAKE_KEY,
|
||||
mHelper);
|
||||
TestHearingDeviceAudioRoutingBasePreferenceController.setupForTesting(
|
||||
mCachedBluetoothDevice);
|
||||
mListPreference.setEntries(R.array.bluetooth_audio_routing_titles);
|
||||
mListPreference.setEntryValues(R.array.bluetooth_audio_routing_values);
|
||||
mListPreference.setSummary("%s");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updateState_routingValueAuto_expectedSummary() {
|
||||
mController.saveRoutingValue(mContext, HearingAidAudioRoutingConstants.RoutingValue.AUTO);
|
||||
|
||||
mController.updateState(mListPreference);
|
||||
|
||||
assertThat(mListPreference.getSummary().toString()).isEqualTo(
|
||||
mListPreference.getEntries()[0].toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onPreferenceChange_routingValueHearingDevice_restoreSameValue() {
|
||||
mController.onPreferenceChange(mListPreference, String.valueOf(
|
||||
HearingAidAudioRoutingConstants.RoutingValue.HEARING_DEVICE));
|
||||
|
||||
assertThat(mController.restoreRoutingValue(mContext)).isEqualTo(
|
||||
HearingAidAudioRoutingConstants.RoutingValue.HEARING_DEVICE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onPreferenceChange_noMatchedDeviceAttributes_notCallSetStrategies() {
|
||||
when(mHelper.getMatchedHearingDeviceAttributes(any())).thenReturn(null);
|
||||
|
||||
verify(mHelper, never()).setPreferredDeviceRoutingStrategies(any(), isNull(), anyInt());
|
||||
}
|
||||
|
||||
private static class TestHearingDeviceAudioRoutingBasePreferenceController extends
|
||||
HearingDeviceAudioRoutingBasePreferenceController {
|
||||
|
||||
private static CachedBluetoothDevice sCachedBluetoothDevice;
|
||||
private static int sSavedRoutingValue;
|
||||
|
||||
TestHearingDeviceAudioRoutingBasePreferenceController(Context context,
|
||||
String preferenceKey, HearingAidAudioRoutingHelper helper) {
|
||||
super(context, preferenceKey, helper);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int[] getSupportedAttributeList() {
|
||||
return new int[]{AudioAttributes.USAGE_MEDIA};
|
||||
}
|
||||
|
||||
@Override
|
||||
protected CachedBluetoothDevice getHearingDevice() {
|
||||
return sCachedBluetoothDevice;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void saveRoutingValue(Context context, int routingValue) {
|
||||
sSavedRoutingValue = routingValue;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int restoreRoutingValue(Context context) {
|
||||
return sSavedRoutingValue;
|
||||
}
|
||||
|
||||
public static void setupForTesting(CachedBluetoothDevice cachedBluetoothDevice) {
|
||||
sCachedBluetoothDevice = cachedBluetoothDevice;
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,76 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2023 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.core.BasePreferenceController.AVAILABLE;
|
||||
import static com.android.settings.core.BasePreferenceController.UNSUPPORTED_ON_DEVICE;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.content.Context;
|
||||
import android.telephony.TelephonyManager;
|
||||
|
||||
import androidx.test.core.app.ApplicationProvider;
|
||||
|
||||
import org.junit.Before;
|
||||
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;
|
||||
|
||||
/** Tests for {@link HearingDeviceCallRoutingPreferenceController}. */
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
public class HearingDeviceCallRoutingPreferenceControllerTest {
|
||||
|
||||
@Rule
|
||||
public MockitoRule mMockitoRule = MockitoJUnit.rule();
|
||||
|
||||
@Spy
|
||||
private final Context mContext = ApplicationProvider.getApplicationContext();
|
||||
private static final String FAKE_KEY = "fake_key";
|
||||
|
||||
@Mock
|
||||
private TelephonyManager mTelephonyManager;
|
||||
private HearingDeviceCallRoutingPreferenceController mController;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
when(mContext.getSystemService(Context.TELEPHONY_SERVICE)).thenReturn(mTelephonyManager);
|
||||
mController = new HearingDeviceCallRoutingPreferenceController(mContext, FAKE_KEY);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getAvailabilityStatus_hasTelephonyCalling_available() {
|
||||
when(mTelephonyManager.isVoiceCapable()).thenReturn(true);
|
||||
|
||||
assertThat(mController.getAvailabilityStatus()).isEqualTo(AVAILABLE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getAvailabilityStatus_noTelephonyCalling_unsupported() {
|
||||
when(mTelephonyManager.isVoiceCapable()).thenReturn(false);
|
||||
|
||||
|
||||
assertThat(mController.getAvailabilityStatus()).isEqualTo(UNSUPPORTED_ON_DEVICE);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user