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:
jasonwshsu
2023-05-11 20:25:10 +08:00
parent 6619994919
commit 212470d0a6
25 changed files with 542 additions and 619 deletions

View File

@@ -24,25 +24,22 @@ import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import android.app.Activity;
import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothHapClient;
import android.bluetooth.BluetoothHearingAid;
import android.bluetooth.BluetoothProfile;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import androidx.appcompat.app.AlertDialog;
import androidx.fragment.app.FragmentActivity;
import androidx.preference.Preference;
import androidx.test.core.app.ApplicationProvider;
import com.android.settings.R;
import com.android.settings.bluetooth.Utils;
import com.android.settings.testutils.shadow.ShadowAlertDialogCompat;
import com.android.settings.testutils.shadow.ShadowBluetoothAdapter;
import com.android.settings.testutils.shadow.ShadowBluetoothUtils;
import com.android.settings.utils.ActivityControllerWrapper;
import com.android.settingslib.bluetooth.BluetoothEventManager;
import com.android.settingslib.bluetooth.CachedBluetoothDevice;
import com.android.settingslib.bluetooth.CachedBluetoothDeviceManager;
@@ -55,11 +52,12 @@ import com.android.settingslib.bluetooth.LocalBluetoothProfileManager;
import org.junit.After;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.robolectric.Robolectric;
import org.mockito.junit.MockitoJUnit;
import org.mockito.junit.MockitoRule;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.annotation.Config;
import org.robolectric.shadow.api.Shadow;
@@ -74,6 +72,9 @@ import java.util.Set;
@RunWith(RobolectricTestRunner.class)
@Config(shadows = {ShadowBluetoothAdapter.class, ShadowBluetoothUtils.class})
public class AccessibilityHearingAidPreferenceControllerTest {
@Rule
public final MockitoRule mockito = MockitoJUnit.rule();
private static final String TEST_DEVICE_ADDRESS = "00:A1:A1:A1:A1:A1";
private static final String TEST_DEVICE_ADDRESS_2 = "00:A2:A2:A2:A2:A2";
private static final String TEST_DEVICE_NAME = "TEST_HEARING_AID_BT_DEVICE_NAME";
@@ -82,7 +83,8 @@ public class AccessibilityHearingAidPreferenceControllerTest {
private BluetoothAdapter mBluetoothAdapter;
private ShadowBluetoothAdapter mShadowBluetoothAdapter;
private BluetoothDevice mBluetoothDevice;
private Activity mContext;
private final Context mContext = ApplicationProvider.getApplicationContext();
private Preference mHearingAidPreference;
private AccessibilityHearingAidPreferenceController mPreferenceController;
private ShadowApplication mShadowApplication;
@@ -106,11 +108,7 @@ public class AccessibilityHearingAidPreferenceControllerTest {
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
mShadowApplication = ShadowApplication.getInstance();
mContext = spy((Activity) ActivityControllerWrapper.setup(
Robolectric.buildActivity(Activity.class)).get());
setupEnvironment();
mHearingAidPreference = new Preference(mContext);
@@ -274,65 +272,6 @@ public class AccessibilityHearingAidPreferenceControllerTest {
verify(mPreferenceController).launchBluetoothDeviceDetailSetting(mCachedBluetoothDevice);
}
@Test
public void onSupportHearingAidProfile_isAvailable() {
mShadowBluetoothAdapter.clearSupportedProfiles();
mShadowBluetoothAdapter.addSupportedProfiles(BluetoothProfile.HEARING_AID);
mPreferenceController = new AccessibilityHearingAidPreferenceController(mContext,
HEARING_AID_PREFERENCE);
mPreferenceController.setPreference(mHearingAidPreference);
assertThat(mPreferenceController.isAvailable()).isTrue();
}
@Test
public void onSupportHapClientProfile_isAvailable() {
mShadowBluetoothAdapter.clearSupportedProfiles();
mShadowBluetoothAdapter.addSupportedProfiles(BluetoothProfile.HAP_CLIENT);
mPreferenceController = new AccessibilityHearingAidPreferenceController(mContext,
HEARING_AID_PREFERENCE);
mPreferenceController.setPreference(mHearingAidPreference);
assertThat(mPreferenceController.isAvailable()).isTrue();
}
@Test
public void onNotSupportAnyHearingAidRelatedProfile_isNotAvailable() {
mShadowBluetoothAdapter.clearSupportedProfiles();
mPreferenceController = new AccessibilityHearingAidPreferenceController(mContext,
HEARING_AID_PREFERENCE);
mPreferenceController.setPreference(mHearingAidPreference);
assertThat(mPreferenceController.isAvailable()).isFalse();
}
@Test
public void getConnectedHearingAidDevice_doNotReturnSubDevice() {
when(mHearingAidProfile.getConnectedDevices()).thenReturn(generateHearingAidDeviceList());
when(mLocalBluetoothManager.getCachedDeviceManager().isSubDevice(mBluetoothDevice))
.thenReturn(true);
assertThat(mPreferenceController.getConnectedHearingAidDevice()).isNull();
}
@Test
@Config(shadows = ShadowAlertDialogCompat.class)
public void onActiveDeviceChanged_hearingAidProfile_launchHearingAidPairingDialog() {
final FragmentActivity mActivity = Robolectric.setupActivity(FragmentActivity.class);
when(mCachedBluetoothDevice.isConnectedAshaHearingAidDevice()).thenReturn(true);
when(mCachedBluetoothDevice.getDeviceMode()).thenReturn(
HearingAidInfo.DeviceMode.MODE_BINAURAL);
when(mCachedBluetoothDevice.getDeviceSide()).thenReturn(
HearingAidInfo.DeviceSide.SIDE_LEFT);
mPreferenceController.setFragmentManager(mActivity.getSupportFragmentManager());
mPreferenceController.onActiveDeviceChanged(mCachedBluetoothDevice,
BluetoothProfile.HEARING_AID);
final AlertDialog dialog = ShadowAlertDialogCompat.getLatestAlertDialog();
assertThat(dialog.isShowing()).isTrue();
}
@Test
public void onServiceConnected_onHearingAidProfileConnected_updateSummary() {
when(mCachedBluetoothDevice.getDeviceSide()).thenReturn(

View File

@@ -0,0 +1,67 @@
/*
* 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.accessibility;
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 android.content.Context;
import android.util.FeatureFlagUtils;
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.junit.MockitoJUnit;
import org.mockito.junit.MockitoRule;
import org.robolectric.RobolectricTestRunner;
/** Tests for {@link HearingAidAudioRoutingPreferenceController}. */
@RunWith(RobolectricTestRunner.class)
public class HearingAidAudioRoutingPreferenceControllerTest {
@Rule
public final MockitoRule mockito = MockitoJUnit.rule();
private final Context mContext = ApplicationProvider.getApplicationContext();
private HearingAidAudioRoutingPreferenceController mController;
@Before
public void setUp() {
mController = new HearingAidAudioRoutingPreferenceController(mContext, "test_key");
}
@Test
public void getAvailabilityStatus_audioRoutingNotSupported_returnUnsupported() {
FeatureFlagUtils.setEnabled(mContext,
FeatureFlagUtils.SETTINGS_AUDIO_ROUTING, false);
assertThat(mController.getAvailabilityStatus()).isEqualTo(UNSUPPORTED_ON_DEVICE);
}
@Test
public void getAvailabilityStatus_audioRoutingNotSupported_available() {
FeatureFlagUtils.setEnabled(mContext,
FeatureFlagUtils.SETTINGS_AUDIO_ROUTING, true);
assertThat(mController.getAvailabilityStatus()).isEqualTo(AVAILABLE);
}
}

View File

@@ -0,0 +1,167 @@
/*
* 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.accessibility;
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.Mockito.when;
import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothProfile;
import android.content.Context;
import androidx.test.core.app.ApplicationProvider;
import com.android.settings.bluetooth.Utils;
import com.android.settings.testutils.shadow.ShadowBluetoothAdapter;
import com.android.settings.testutils.shadow.ShadowBluetoothUtils;
import com.android.settingslib.bluetooth.CachedBluetoothDevice;
import com.android.settingslib.bluetooth.CachedBluetoothDeviceManager;
import com.android.settingslib.bluetooth.HapClientProfile;
import com.android.settingslib.bluetooth.HearingAidProfile;
import com.android.settingslib.bluetooth.LocalBluetoothManager;
import com.android.settingslib.bluetooth.LocalBluetoothProfileManager;
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;
import org.robolectric.shadow.api.Shadow;
import java.util.ArrayList;
import java.util.Collections;
/** Tests for {@link HearingAidHelper}. */
@RunWith(RobolectricTestRunner.class)
@Config(shadows = {ShadowBluetoothAdapter.class, ShadowBluetoothUtils.class})
public class HearingAidHelperTest {
@Rule
public final MockitoRule mockito = MockitoJUnit.rule();
private final Context mContext = ApplicationProvider.getApplicationContext();
private static final String TEST_DEVICE_ADDRESS = "00:A1:A1:A1:A1:A1";
@Mock
private LocalBluetoothManager mLocalBluetoothManager;
@Mock
private LocalBluetoothProfileManager mLocalBluetoothProfileManager;
@Mock
private CachedBluetoothDeviceManager mCachedDeviceManager;
@Mock
private CachedBluetoothDevice mCachedBluetoothDevice;
@Mock
private HearingAidProfile mHearingAidProfile;
@Mock
private HapClientProfile mHapClientProfile;
private ShadowBluetoothAdapter mShadowBluetoothAdapter;
private BluetoothAdapter mBluetoothAdapter;
private BluetoothDevice mBluetoothDevice;
private HearingAidHelper mHelper;
@Before
public void setUp() {
ShadowBluetoothUtils.sLocalBluetoothManager = mLocalBluetoothManager;
mLocalBluetoothManager = Utils.getLocalBtManager(mContext);
mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
mShadowBluetoothAdapter = Shadow.extract(mBluetoothAdapter);
mBluetoothDevice = mBluetoothAdapter.getRemoteDevice(TEST_DEVICE_ADDRESS);
when(mCachedBluetoothDevice.getAddress()).thenReturn(TEST_DEVICE_ADDRESS);
when(mLocalBluetoothManager.getCachedDeviceManager()).thenReturn(mCachedDeviceManager);
when(mCachedDeviceManager.findDevice(mBluetoothDevice)).thenReturn(mCachedBluetoothDevice);
when(mLocalBluetoothManager.getProfileManager()).thenReturn(mLocalBluetoothProfileManager);
when(mLocalBluetoothProfileManager.getHearingAidProfile()).thenReturn(mHearingAidProfile);
when(mLocalBluetoothProfileManager.getHapClientProfile()).thenReturn(mHapClientProfile);
mHelper = new HearingAidHelper(mContext);
}
@Test
public void isHearingAidSupported_supported_returnTrue() {
mBluetoothAdapter.enable();
mShadowBluetoothAdapter.clearSupportedProfiles();
mShadowBluetoothAdapter.addSupportedProfiles(BluetoothProfile.HEARING_AID);
assertThat(mHelper.isHearingAidSupported()).isTrue();
}
@Test
public void isHearingAidSupported_bluetoothOff_returnFalse() {
mShadowBluetoothAdapter.clearSupportedProfiles();
mShadowBluetoothAdapter.addSupportedProfiles(BluetoothProfile.HEARING_AID);
mBluetoothAdapter.disable();
assertThat(mHelper.isHearingAidSupported()).isFalse();
}
@Test
public void isAllHearingAidRelatedProfilesReady_allReady_returnTrue() {
when(mHearingAidProfile.isProfileReady()).thenReturn(true);
when(mHapClientProfile.isProfileReady()).thenReturn(true);
assertThat(mHelper.isAllHearingAidRelatedProfilesReady()).isTrue();
}
@Test
public void isAllHearingAidRelatedProfilesReady_notFullReady_returnFalse() {
when(mHearingAidProfile.isProfileReady()).thenReturn(false);
when(mHapClientProfile.isProfileReady()).thenReturn(true);
assertThat(mHelper.isAllHearingAidRelatedProfilesReady()).isFalse();
}
@Test
public void getConnectedHearingAidDeviceList_oneDeviceAdded_getOneDevice() {
mBluetoothAdapter.enable();
mShadowBluetoothAdapter.clearSupportedProfiles();
mShadowBluetoothAdapter.addSupportedProfiles(BluetoothProfile.HEARING_AID);
when(mHearingAidProfile.getConnectedDevices()).thenReturn(new ArrayList<>(
Collections.singletonList(mBluetoothDevice)));
assertThat(mHelper.getConnectedHearingAidDeviceList().size()).isEqualTo(1);
}
@Test
public void getConnectedHearingAidDeviceList_oneSubDeviceAdded_getZeroDevice() {
mBluetoothAdapter.enable();
mShadowBluetoothAdapter.clearSupportedProfiles();
mShadowBluetoothAdapter.addSupportedProfiles(BluetoothProfile.HEARING_AID);
when(mHearingAidProfile.getConnectedDevices()).thenReturn(new ArrayList<>(
Collections.singletonList(mBluetoothDevice)));
when(mLocalBluetoothManager.getCachedDeviceManager().isSubDevice(
mBluetoothDevice)).thenReturn(true);
assertThat(mHelper.getConnectedHearingAidDeviceList().size()).isEqualTo(0);
}
@Test
public void getConnectedHearingAidDevice_getExpectedCachedBluetoothDevice() {
mBluetoothAdapter.enable();
mShadowBluetoothAdapter.clearSupportedProfiles();
mShadowBluetoothAdapter.addSupportedProfiles(BluetoothProfile.HEARING_AID);
when(mHearingAidProfile.getConnectedDevices()).thenReturn(new ArrayList<>(
Collections.singletonList(mBluetoothDevice)));
assertThat(mHelper.getConnectedHearingAidDevice()).isEqualTo(mCachedBluetoothDevice);
assertThat(mCachedBluetoothDevice.getAddress()).isEqualTo(mBluetoothDevice.getAddress());
}
}

View File

@@ -14,13 +14,14 @@
* limitations under the License.
*/
package com.android.settings.bluetooth;
package com.android.settings.accessibility;
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.doReturn;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
@@ -37,9 +38,15 @@ import androidx.preference.ListPreference;
import androidx.test.core.app.ApplicationProvider;
import com.android.settings.R;
import com.android.settings.bluetooth.Utils;
import com.android.settings.testutils.shadow.ShadowBluetoothAdapter;
import com.android.settings.testutils.shadow.ShadowBluetoothUtils;
import com.android.settingslib.bluetooth.CachedBluetoothDevice;
import com.android.settingslib.bluetooth.CachedBluetoothDeviceManager;
import com.android.settingslib.bluetooth.HearingAidAudioRoutingConstants;
import com.android.settingslib.bluetooth.HearingAidAudioRoutingHelper;
import com.android.settingslib.bluetooth.LocalBluetoothManager;
import com.android.settingslib.bluetooth.LocalBluetoothProfileManager;
import org.junit.Before;
import org.junit.Rule;
@@ -50,11 +57,13 @@ import org.mockito.Spy;
import org.mockito.junit.MockitoJUnit;
import org.mockito.junit.MockitoRule;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.annotation.Config;
import java.util.List;
/** Tests for {@link HearingDeviceAudioRoutingBasePreferenceController}. */
@RunWith(RobolectricTestRunner.class)
@Config(shadows = {ShadowBluetoothAdapter.class, ShadowBluetoothUtils.class})
public class HearingDeviceAudioRoutingBasePreferenceControllerTest {
@Rule
@@ -63,8 +72,14 @@ public class HearingDeviceAudioRoutingBasePreferenceControllerTest {
@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";
private final ListPreference mListPreference = new ListPreference(mContext);
@Mock
private LocalBluetoothManager mLocalBluetoothManager;
@Mock
private LocalBluetoothProfileManager mLocalBluetoothProfileManager;
@Mock
private CachedBluetoothDeviceManager mCachedDeviceManager;
@Mock
private AudioProductStrategy mAudioProductStrategyMedia;
@Mock
@@ -72,8 +87,10 @@ public class HearingDeviceAudioRoutingBasePreferenceControllerTest {
@Mock
private BluetoothDevice mBluetoothDevice;
@Spy
private HearingAidAudioRoutingHelper mHelper = new HearingAidAudioRoutingHelper(mContext);
private final ListPreference mListPreference = new ListPreference(mContext);
private HearingAidAudioRoutingHelper mAudioRoutingHelper =
new HearingAidAudioRoutingHelper(mContext);
@Mock
private HearingAidHelper mHearingAidHelper;
private TestHearingDeviceAudioRoutingBasePreferenceController mController;
@Before
@@ -83,19 +100,23 @@ public class HearingDeviceAudioRoutingBasePreferenceControllerTest {
AudioDeviceInfo.TYPE_HEARING_AID,
TEST_DEVICE_ADDRESS);
ShadowBluetoothUtils.sLocalBluetoothManager = mLocalBluetoothManager;
mLocalBluetoothManager = Utils.getLocalBtManager(mContext);
when(mLocalBluetoothManager.getCachedDeviceManager()).thenReturn(mCachedDeviceManager);
when(mLocalBluetoothManager.getProfileManager()).thenReturn(mLocalBluetoothProfileManager);
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);
doReturn(hearingDeviceAttribute).when(
mAudioRoutingHelper).getMatchedHearingDeviceAttributes(any());
when(mAudioProductStrategyMedia.getAudioAttributesForLegacyStreamType(
AudioManager.STREAM_MUSIC))
.thenReturn((new AudioAttributes.Builder()).build());
when(mHelper.getAudioProductStrategies()).thenReturn(List.of(mAudioProductStrategyMedia));
AudioManager.STREAM_MUSIC)).thenReturn((new AudioAttributes.Builder()).build());
when(mAudioRoutingHelper.getAudioProductStrategies()).thenReturn(
List.of(mAudioProductStrategyMedia));
mController = new TestHearingDeviceAudioRoutingBasePreferenceController(mContext, FAKE_KEY,
mHelper);
TestHearingDeviceAudioRoutingBasePreferenceController.setupForTesting(
mCachedBluetoothDevice);
mController = new TestHearingDeviceAudioRoutingBasePreferenceController(mContext,
"test_key",
mAudioRoutingHelper, mHearingAidHelper);
mListPreference.setEntries(R.array.bluetooth_audio_routing_titles);
mListPreference.setEntryValues(R.array.bluetooth_audio_routing_values);
mListPreference.setSummary("%s");
@@ -122,20 +143,21 @@ public class HearingDeviceAudioRoutingBasePreferenceControllerTest {
@Test
public void onPreferenceChange_noMatchedDeviceAttributes_notCallSetStrategies() {
when(mHelper.getMatchedHearingDeviceAttributes(any())).thenReturn(null);
when(mAudioRoutingHelper.getMatchedHearingDeviceAttributes(any())).thenReturn(null);
verify(mHelper, never()).setPreferredDeviceRoutingStrategies(any(), isNull(), anyInt());
verify(mAudioRoutingHelper, 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);
String preferenceKey, HearingAidAudioRoutingHelper audioRoutingHelper,
HearingAidHelper hearingAidHelper) {
super(context, preferenceKey, audioRoutingHelper, hearingAidHelper);
}
@Override
@@ -143,11 +165,6 @@ public class HearingDeviceAudioRoutingBasePreferenceControllerTest {
return new int[]{AudioAttributes.USAGE_MEDIA};
}
@Override
protected CachedBluetoothDevice getHearingDevice() {
return sCachedBluetoothDevice;
}
@Override
protected void saveRoutingValue(Context context, int routingValue) {
sSavedRoutingValue = routingValue;
@@ -157,9 +174,5 @@ public class HearingDeviceAudioRoutingBasePreferenceControllerTest {
protected int restoreRoutingValue(Context context) {
return sSavedRoutingValue;
}
public static void setupForTesting(CachedBluetoothDevice cachedBluetoothDevice) {
sCachedBluetoothDevice = cachedBluetoothDevice;
}
}
}

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package com.android.settings.bluetooth;
package com.android.settings.accessibility;
import static com.android.settings.core.BasePreferenceController.AVAILABLE;
import static com.android.settings.core.BasePreferenceController.UNSUPPORTED_ON_DEVICE;

View File

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

View File

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