Merge "Show hearing device pairing intro according to the device's supported status" into main
This commit is contained in:
committed by
Android (Google) Code Review
commit
dc34cabee1
@@ -5934,6 +5934,10 @@
|
||||
<string name="accessibility_hearing_device_pairing_page_title">Pair hearing device</string>
|
||||
<!-- Subtitle for the pair hearing device page. [CHAR LIMIT=NONE] -->
|
||||
<string name="accessibility_hearing_device_pairing_intro">You can pair ASHA and LE Audio hearing devices on this page. Make sure your hearing device is turned on and ready to pair.</string>
|
||||
<!-- Subtitle for the pair hearing device page. This string is for device that only supports ASHA hearing aids. [CHAR LIMIT=NONE] -->
|
||||
<string name="accessibility_hearing_device_pairing_asha_only_intro">You can pair ASHA hearing devices on this page. Make sure your hearing device is turned on and ready to pair.</string>
|
||||
<!-- Subtitle for the pair hearing device page. This string is for device that only supports LE Audio hearing aids. [CHAR LIMIT=NONE] -->
|
||||
<string name="accessibility_hearing_device_pairing_hap_only_intro">You can pair LE Audio hearing devices on this page. Make sure your hearing device is turned on and ready to pair.</string>
|
||||
<!-- Title for the preference category containing the list of the available hearing during and after bluetooth scanning devices. [CHAR LIMIT=30] -->
|
||||
<string name="accessibility_found_hearing_devices">Available hearing devices</string>
|
||||
<!-- Title for the preference category containing the all bluetooth devices during and after bluetooth scanning devices. Used when people can not find their hearing device in hearing device pairing list. [CHAR LIMIT=45] -->
|
||||
|
@@ -20,8 +20,10 @@
|
||||
android:title="@string/bluetooth_pairing_pref_title">
|
||||
|
||||
<com.android.settingslib.widget.TopIntroPreference
|
||||
android:key="hearing_device_pairing_intro"
|
||||
settings:searchable="false"
|
||||
android:title="@string/accessibility_hearing_device_pairing_intro" />
|
||||
android:title="@string/accessibility_hearing_device_pairing_intro"
|
||||
settings:controller="com.android.settings.accessibility.HearingDevicePairingIntroPreferenceController"/>
|
||||
|
||||
<com.android.settings.bluetooth.BluetoothProgressCategory
|
||||
android:key="available_hearing_devices"
|
||||
|
@@ -0,0 +1,77 @@
|
||||
/*
|
||||
* 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 android.content.Context;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.preference.Preference;
|
||||
import androidx.preference.PreferenceScreen;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.core.BasePreferenceController;
|
||||
|
||||
import com.google.common.annotations.VisibleForTesting;
|
||||
|
||||
public class HearingDevicePairingIntroPreferenceController extends BasePreferenceController {
|
||||
private final HearingAidHelper mHelper;
|
||||
|
||||
public HearingDevicePairingIntroPreferenceController(
|
||||
@NonNull Context context,
|
||||
@NonNull String preferenceKey) {
|
||||
super(context, preferenceKey);
|
||||
mHelper = new HearingAidHelper(context);
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
public HearingDevicePairingIntroPreferenceController(
|
||||
@NonNull Context context,
|
||||
@NonNull String preferenceKey,
|
||||
@NonNull HearingAidHelper hearingAidHelper) {
|
||||
super(context, preferenceKey);
|
||||
mHelper = hearingAidHelper;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getAvailabilityStatus() {
|
||||
return mHelper.isHearingAidSupported() ? AVAILABLE : UNSUPPORTED_ON_DEVICE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void displayPreference(@NonNull PreferenceScreen screen) {
|
||||
super.displayPreference(screen);
|
||||
|
||||
final Preference pairingIntroPreference = screen.findPreference(getPreferenceKey());
|
||||
final boolean isAshaProfileSupported = mHelper.isAshaProfileSupported();
|
||||
final boolean isHapClientProfileSupported = mHelper.isHapClientProfileSupported();
|
||||
if (isAshaProfileSupported && isHapClientProfileSupported) {
|
||||
pairingIntroPreference.setTitle(
|
||||
mContext.getString(R.string.accessibility_hearing_device_pairing_intro));
|
||||
} else if (isAshaProfileSupported) {
|
||||
pairingIntroPreference.setTitle(
|
||||
mContext.getString(
|
||||
R.string.accessibility_hearing_device_pairing_asha_only_intro));
|
||||
} else if (isHapClientProfileSupported) {
|
||||
pairingIntroPreference.setTitle(
|
||||
mContext.getString(
|
||||
R.string.accessibility_hearing_device_pairing_hap_only_intro));
|
||||
} else {
|
||||
// Intentionally blank, getAvailabilityStatus() should handle visibility for
|
||||
// none-supported case.
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,122 @@
|
||||
/*
|
||||
* 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 HearingDevicePairingIntroPreferenceController}.
|
||||
*/
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
public class HearingDevicePairingIntroPreferenceControllerTest {
|
||||
|
||||
@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 HearingDevicePairingIntroPreferenceController mController;
|
||||
private TopIntroPreference mPreference;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
mController = new HearingDevicePairingIntroPreferenceController(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_hearing_device_pairing_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_hearing_device_pairing_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_hearing_device_pairing_hap_only_intro));
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user