Merge "Show intro and footer string according to the device's supported status" into main
This commit is contained in:
@@ -117,6 +117,22 @@ public class HearingAidHelperTest {
|
||||
assertThat(mHelper.isHearingAidSupported()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isAshaProfileSupported_supported_returnTrue() {
|
||||
mShadowBluetoothAdapter.clearSupportedProfiles();
|
||||
mShadowBluetoothAdapter.addSupportedProfiles(BluetoothProfile.HEARING_AID);
|
||||
|
||||
assertThat(mHelper.isAshaProfileSupported()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isHapClientProfileSupported_supported_returnTrue() {
|
||||
mShadowBluetoothAdapter.clearSupportedProfiles();
|
||||
mShadowBluetoothAdapter.addSupportedProfiles(BluetoothProfile.HAP_CLIENT);
|
||||
|
||||
assertThat(mHelper.isHapClientProfileSupported()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isAllHearingAidRelatedProfilesReady_allReady_returnTrue() {
|
||||
when(mHearingAidProfile.isProfileReady()).thenReturn(true);
|
||||
|
||||
@@ -0,0 +1,123 @@
|
||||
/*
|
||||
* Copyright (C) 2025 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 static org.mockito.Mockito.when;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.res.Resources;
|
||||
|
||||
import androidx.preference.PreferenceScreen;
|
||||
import androidx.test.core.app.ApplicationProvider;
|
||||
|
||||
import com.android.settings.R;
|
||||
|
||||
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 HearingDeviceFooterPreferenceController}.
|
||||
*/
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
public class HearingDeviceFooterPreferenceControllerTest {
|
||||
|
||||
@Rule
|
||||
public final MockitoRule mockito = MockitoJUnit.rule();
|
||||
|
||||
@Spy
|
||||
private final Context mContext = ApplicationProvider.getApplicationContext();
|
||||
@Spy
|
||||
private final Resources mResources = mContext.getResources();
|
||||
@Mock
|
||||
private PreferenceScreen mScreen;
|
||||
@Mock
|
||||
private HearingAidHelper mHelper;
|
||||
private HearingDeviceFooterPreferenceController mController;
|
||||
private AccessibilityFooterPreference mPreference;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
mController = new HearingDeviceFooterPreferenceController(mContext, "test_key", mHelper);
|
||||
mPreference = new AccessibilityFooterPreference(mContext);
|
||||
mPreference.setKey("test_key");
|
||||
|
||||
when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(mPreference);
|
||||
when(mContext.getResources()).thenReturn(mResources);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getAvailabilityStatus_hearingAidSupported_available() {
|
||||
when(mHelper.isHearingAidSupported()).thenReturn(true);
|
||||
|
||||
assertThat(mController.getAvailabilityStatus()).isEqualTo(AVAILABLE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getAvailabilityStatus_hearingAidNotSupported_unsupportedOnDevice() {
|
||||
when(mHelper.isHearingAidSupported()).thenReturn(false);
|
||||
|
||||
assertThat(mController.getAvailabilityStatus()).isEqualTo(UNSUPPORTED_ON_DEVICE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void displayPreference_ashaHapSupported_expectedContentDescription() {
|
||||
when(mHelper.isAshaProfileSupported()).thenReturn(true);
|
||||
when(mHelper.isHapClientProfileSupported()).thenReturn(true);
|
||||
|
||||
mController.displayPreference(mScreen);
|
||||
|
||||
assertThat(mPreference.getContentDescription().toString()).isEqualTo(
|
||||
mController.getIntroductionTitle() + "\n\n" + mContext.getString(
|
||||
R.string.accessibility_hearing_device_footer_summary_tts));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void displayPreference_ashaSupported_expectedContentDescription() {
|
||||
when(mHelper.isAshaProfileSupported()).thenReturn(true);
|
||||
when(mHelper.isHapClientProfileSupported()).thenReturn(false);
|
||||
|
||||
mController.displayPreference(mScreen);
|
||||
|
||||
assertThat(mPreference.getContentDescription().toString()).isEqualTo(
|
||||
mController.getIntroductionTitle() + "\n\n" + mContext.getString(
|
||||
R.string.accessibility_hearing_device_footer_asha_only_summary_tts));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void displayPreference_hapSupported_expectedContentDescription() {
|
||||
when(mHelper.isAshaProfileSupported()).thenReturn(false);
|
||||
when(mHelper.isHapClientProfileSupported()).thenReturn(true);
|
||||
|
||||
mController.displayPreference(mScreen);
|
||||
|
||||
assertThat(mPreference.getContentDescription().toString()).isEqualTo(
|
||||
mController.getIntroductionTitle() + "\n\n" + mContext.getString(
|
||||
R.string.accessibility_hearing_device_footer_hap_only_summary_tts));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,121 @@
|
||||
/*
|
||||
* Copyright (C) 2025 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 static org.mockito.Mockito.when;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.res.Resources;
|
||||
|
||||
import androidx.preference.PreferenceScreen;
|
||||
import androidx.test.core.app.ApplicationProvider;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settingslib.widget.TopIntroPreference;
|
||||
|
||||
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 HearingDeviceIntroPreferenceController}.
|
||||
*/
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
public class HearingDeviceIntroPreferenceControllerTest {
|
||||
|
||||
@Rule
|
||||
public final MockitoRule mockito = MockitoJUnit.rule();
|
||||
|
||||
@Spy
|
||||
private final Context mContext = ApplicationProvider.getApplicationContext();
|
||||
@Spy
|
||||
private final Resources mResources = mContext.getResources();
|
||||
@Mock
|
||||
private PreferenceScreen mScreen;
|
||||
@Mock
|
||||
private HearingAidHelper mHelper;
|
||||
private HearingDeviceIntroPreferenceController mController;
|
||||
private TopIntroPreference mPreference;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
mController = new HearingDeviceIntroPreferenceController(mContext, "test_key", mHelper);
|
||||
mPreference = new TopIntroPreference(mContext);
|
||||
mPreference.setKey("test_key");
|
||||
|
||||
when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(mPreference);
|
||||
when(mContext.getResources()).thenReturn(mResources);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getAvailabilityStatus_hearingAidSupported_available() {
|
||||
when(mHelper.isHearingAidSupported()).thenReturn(true);
|
||||
|
||||
assertThat(mController.getAvailabilityStatus()).isEqualTo(AVAILABLE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getAvailabilityStatus_hearingAidNotSupported_unsupportedOnDevice() {
|
||||
when(mHelper.isHearingAidSupported()).thenReturn(false);
|
||||
|
||||
assertThat(mController.getAvailabilityStatus()).isEqualTo(UNSUPPORTED_ON_DEVICE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void displayPreference_ashaHapSupported_expectedTitle() {
|
||||
when(mHelper.isAshaProfileSupported()).thenReturn(true);
|
||||
when(mHelper.isHapClientProfileSupported()).thenReturn(true);
|
||||
|
||||
mController.displayPreference(mScreen);
|
||||
|
||||
assertThat(mPreference.getTitle().toString()).isEqualTo(
|
||||
mContext.getString(R.string.accessibility_hearingaid_intro));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void displayPreference_ashaSupported_expectedTitle() {
|
||||
when(mHelper.isAshaProfileSupported()).thenReturn(true);
|
||||
when(mHelper.isHapClientProfileSupported()).thenReturn(false);
|
||||
|
||||
mController.displayPreference(mScreen);
|
||||
|
||||
assertThat(mPreference.getTitle().toString()).isEqualTo(
|
||||
mContext.getString(R.string.accessibility_hearingaid_asha_only_intro));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void displayPreference_hapSupported_expectedTitle() {
|
||||
when(mHelper.isAshaProfileSupported()).thenReturn(false);
|
||||
when(mHelper.isHapClientProfileSupported()).thenReturn(true);
|
||||
|
||||
mController.displayPreference(mScreen);
|
||||
|
||||
assertThat(mPreference.getTitle().toString()).isEqualTo(
|
||||
mContext.getString(R.string.accessibility_hearingaid_hap_only_intro));
|
||||
}
|
||||
}
|
||||
@@ -62,15 +62,15 @@ public class BluetoothDetailsHearingDeviceSettingsControllerTest extends
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isAvailable_isHearingAidDevice_available() {
|
||||
when(mCachedDevice.isHearingAidDevice()).thenReturn(true);
|
||||
public void isAvailable_isHearingDevice_available() {
|
||||
when(mCachedDevice.isHearingDevice()).thenReturn(true);
|
||||
|
||||
assertThat(mController.isAvailable()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isAvailable_isNotHearingAidDevice_notAvailable() {
|
||||
when(mCachedDevice.isHearingAidDevice()).thenReturn(false);
|
||||
public void isAvailable_isNotHearingDevice_notAvailable() {
|
||||
when(mCachedDevice.isHearingDevice()).thenReturn(false);
|
||||
|
||||
assertThat(mController.isAvailable()).isFalse();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user