1 /* 2 * Copyright (C) 2024 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 package com.android.settings.accessibility; 17 18 import static com.google.common.truth.Truth.assertThat; 19 20 import android.bluetooth.BluetoothAdapter; 21 import android.bluetooth.BluetoothProfile; 22 import android.content.Context; 23 import android.platform.test.annotations.EnableFlags; 24 import android.platform.test.flag.junit.SetFlagsRule; 25 import android.util.FeatureFlagUtils; 26 27 import androidx.test.core.app.ApplicationProvider; 28 29 import com.android.settings.bluetooth.Utils; 30 import com.android.settings.testutils.shadow.ShadowBluetoothAdapter; 31 import com.android.settings.testutils.shadow.ShadowBluetoothUtils; 32 import com.android.settingslib.bluetooth.LocalBluetoothManager; 33 34 import org.junit.Before; 35 import org.junit.Rule; 36 import org.junit.Test; 37 import org.junit.runner.RunWith; 38 import org.mockito.Mock; 39 import org.mockito.Spy; 40 import org.mockito.junit.MockitoJUnit; 41 import org.mockito.junit.MockitoRule; 42 import org.robolectric.RobolectricTestRunner; 43 import org.robolectric.annotation.Config; 44 import org.robolectric.shadow.api.Shadow; 45 46 /** Tests for {@link AccessibilityAudioRoutingFragment}. */ 47 @RunWith(RobolectricTestRunner.class) 48 @Config(shadows = {ShadowBluetoothAdapter.class, ShadowBluetoothUtils.class}) 49 public class AccessibilityAudioRoutingFragmentTest { 50 51 @Rule 52 public MockitoRule mMockitoRule = MockitoJUnit.rule(); 53 @Rule 54 public final SetFlagsRule mSetFlagsRule = new SetFlagsRule(); 55 56 @Spy 57 private final Context mContext = ApplicationProvider.getApplicationContext(); 58 59 @Mock 60 private LocalBluetoothManager mLocalBluetoothManager; 61 private ShadowBluetoothAdapter mShadowBluetoothAdapter; 62 private BluetoothAdapter mBluetoothAdapter; 63 64 @Before setUp()65 public void setUp() { 66 ShadowBluetoothUtils.sLocalBluetoothManager = mLocalBluetoothManager; 67 mLocalBluetoothManager = Utils.getLocalBtManager(mContext); 68 mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); 69 mShadowBluetoothAdapter = Shadow.extract(mBluetoothAdapter); 70 } 71 72 @Test 73 @EnableFlags(Flags.FLAG_FIX_A11Y_SETTINGS_SEARCH) deviceSupportsHearingAidAndPageEnabled_isPageSearchEnabled_returnTrue()74 public void deviceSupportsHearingAidAndPageEnabled_isPageSearchEnabled_returnTrue() { 75 FeatureFlagUtils.setEnabled(mContext, 76 FeatureFlagUtils.SETTINGS_AUDIO_ROUTING, true); 77 mShadowBluetoothAdapter.clearSupportedProfiles(); 78 mShadowBluetoothAdapter.addSupportedProfiles(BluetoothProfile.HEARING_AID); 79 80 assertThat(AccessibilityAudioRoutingFragment.isPageSearchEnabled(mContext)).isTrue(); 81 } 82 83 @Test 84 @EnableFlags(Flags.FLAG_FIX_A11Y_SETTINGS_SEARCH) deviceDoesNotSupportHearingAidAndPageEnabled_isPageSearchEnabled_returnFalse()85 public void deviceDoesNotSupportHearingAidAndPageEnabled_isPageSearchEnabled_returnFalse() { 86 FeatureFlagUtils.setEnabled(mContext, 87 FeatureFlagUtils.SETTINGS_AUDIO_ROUTING, true); 88 mShadowBluetoothAdapter.clearSupportedProfiles(); 89 mShadowBluetoothAdapter.addSupportedProfiles(BluetoothProfile.HEADSET); 90 91 assertThat(AccessibilityAudioRoutingFragment.isPageSearchEnabled(mContext)).isFalse(); 92 } 93 94 @Test 95 @EnableFlags(Flags.FLAG_FIX_A11Y_SETTINGS_SEARCH) deviceSupportsHearingAidAndPageDisabled_isPageSearchEnabled_returnFalse()96 public void deviceSupportsHearingAidAndPageDisabled_isPageSearchEnabled_returnFalse() { 97 FeatureFlagUtils.setEnabled(mContext, 98 FeatureFlagUtils.SETTINGS_AUDIO_ROUTING, false); 99 mShadowBluetoothAdapter.clearSupportedProfiles(); 100 mShadowBluetoothAdapter.addSupportedProfiles(BluetoothProfile.HEARING_AID); 101 102 assertThat(AccessibilityAudioRoutingFragment.isPageSearchEnabled(mContext)).isFalse(); 103 } 104 } 105