Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 9cfc96d9 authored by jasonwshsu's avatar jasonwshsu
Browse files

Show intro and footer string according to the device's supported status



Bug: 390078046
Bug: 386121967
Test: atest HearingAidHelperTest HearingDeviceFooterPreferenceControllerTest HearingDeviceIntroPreferenceControllerTest BluetoothDetailsHearingDeviceSettingsControllerTest
Flag: EXEMPT bugfix
Change-Id: I564cdb80cd14f4d2d8e882b64db939449c6936b7
Signed-off-by: default avatarJie Wang <jie.x.wang@sony.com>
Signed-off-by: default avatarJason Hsu <jasonwshsu@google.com>
parent 2117499c
Loading
Loading
Loading
Loading
+15 −3
Original line number Diff line number Diff line
@@ -5733,8 +5733,12 @@
    <string name="accessibility_hearingaid_instruction_continue_button">Continue</string>
    <!-- Title for the accessibility preference for hearing devices. [CHAR LIMIT=35] -->
    <string name="accessibility_hearingaid_title">Hearing devices</string>
    <!-- Introduction for the Hearing devices page to introduce feature. [CHAR LIMIT=NONE BACKUP_MESSAGE_ID=5856992709195963850] -->
    <!-- Introduction for the Hearing devices page to introduce feature. [CHAR LIMIT=NONE] -->
    <string name="accessibility_hearingaid_intro">Set up and manage ASHA and LE Audio hearing aids, cochlear implants, and other amplification devices</string>
    <!-- Introduction for the Hearing devices page to introduce feature. This string is for device that only supports ASHA hearing aids. [CHAR LIMIT=NONE] -->
    <string name="accessibility_hearingaid_asha_only_intro">Set up and manage ASHA hearing aids, cochlear implants, and other amplification devices</string>
    <!-- Introduction for the Hearing devices page to introduce feature. This string is for device that only supports LE Audio hearing aids.  [CHAR LIMIT=NONE] -->
    <string name="accessibility_hearingaid_hap_only_intro">Set up and manage LE Audio hearing aids, cochlear implants, and other amplification devices</string>
    <!-- Summary for the accessibility preference for hearing aid when not connected. [CHAR LIMIT=50] -->
    <string name="accessibility_hearingaid_not_connected_summary">No hearing devices connected</string>
    <!-- Summary for the accessibility preference for hearing aid when adding new devices. [CHAR LIMIT=50] -->
@@ -5769,10 +5773,18 @@
    <string name="accessibility_hac_mode_summary">Improves compatibility with telecoils and reduces unwanted noise</string>
    <!-- Title for accessibility hearing device page footer. [CHAR LIMIT=40] -->
    <string name="accessibility_hearing_device_about_title">About hearing devices</string>
    <!-- Description for text in accessibility hearing aids footer. [CHAR LIMIT=NONE BACKUP_MESSAGE_ID=7451899224828040581] -->
    <!-- Description for text in accessibility hearing aids footer. [CHAR LIMIT=NONE] -->
    <string name="accessibility_hearing_device_footer_summary"><![CDATA[To find other hearing devices that aren’t supported by ASHA or LE Audio, tap <b>Pair new device</b> > <b>See more devices</b>]]></string>
    <!-- Content description for text in accessibility hearing aids footer to be announce. Replace '>' to 'then' compare to non tts version. [CHAR LIMIT=NONE BACKUP_MESSAGE_ID=7451899224828040581] -->
    <!-- Content description for text in accessibility hearing aids footer to be announce. Replace '>' to 'then' compare to non tts version. [CHAR LIMIT=NONE] -->
    <string name="accessibility_hearing_device_footer_summary_tts">To find other hearing devices that aren’t supported by ASHA or LE Audio, tap <b>Pair new device</b> then <b>See more devices</b></string>
    <!-- Description for text in accessibility hearing aids footer. This string is for device that only supports ASHA hearing aids. [CHAR LIMIT=NONE] -->
    <string name="accessibility_hearing_device_footer_asha_only_summary"><![CDATA[To find other hearing devices that aren’t supported by ASHA, tap <b>Pair new device</b> > <b>See more devices</b>]]></string>
    <!-- Content description for text in accessibility hearing aids footer to be announce. This string is for device that only supports ASHA hearing aids. Replace '>' to 'then' compare to non tts version. [CHAR LIMIT=NONE] -->
    <string name="accessibility_hearing_device_footer_asha_only_summary_tts">To find other hearing devices that aren’t supported by ASHA, tap <b>Pair new device</b> then <b>See more devices</b></string>
    <!-- Description for text in accessibility hearing aids footer. This string is for device that only supports LE Audio hearing aids. [CHAR LIMIT=NONE] -->
    <string name="accessibility_hearing_device_footer_hap_only_summary"><![CDATA[To find other hearing devices that aren’t supported by LE Audio, tap <b>Pair new device</b> > <b>See more devices</b>]]></string>
    <!-- Content description for text in accessibility hearing aids footer to be announce. This string is for device that only supports LE Audio hearing aids. Replace '>' to 'then' compare to non tts version. [CHAR LIMIT=NONE] -->
    <string name="accessibility_hearing_device_footer_hap_only_summary_tts">To find other hearing devices that aren’t supported by LE Audio, tap <b>Pair new device</b> then <b>See more devices</b></string>
    <!-- Title for the pair hearing device page. [CHAR LIMIT=25] -->
    <string name="accessibility_hearing_device_pairing_page_title">Pair hearing device</string>
    <!-- Subtitle for the pair hearing device page. [CHAR LIMIT=NONE] -->
+3 −1
Original line number Diff line number Diff line
@@ -20,8 +20,10 @@
    android:title="@string/accessibility_hearingaid_title">

    <com.android.settingslib.widget.TopIntroPreference
        android:key="hearing_device_intro"
        android:title="@string/accessibility_hearingaid_intro"
        settings:searchable="false" />
        settings:searchable="false"
        settings:controller="com.android.settings.accessibility.HearingDeviceIntroPreferenceController"/>

    <PreferenceCategory
        android:key="available_hearing_devices"
+16 −0
Original line number Diff line number Diff line
@@ -94,6 +94,22 @@ public class HearingAidHelper {
                || supportedList.contains(BluetoothProfile.HAP_CLIENT);
    }

    /**
     * Checks if {@link BluetoothProfile#HEARING_AID} supported.
     */
    public boolean isAshaProfileSupported() {
        final List<Integer> supportedList = mBluetoothAdapter.getSupportedProfiles();
        return supportedList.contains(BluetoothProfile.HEARING_AID);
    }

    /**
     * Checks if {@link BluetoothProfile#HAP_CLIENT} supported.
     */
    public boolean isHapClientProfileSupported() {
        final List<Integer> supportedList = mBluetoothAdapter.getSupportedProfiles();
        return supportedList.contains(BluetoothProfile.HAP_CLIENT);
    }

    /**
     * Checks if {@link BluetoothProfile#HEARING_AID} or {@link BluetoothProfile#HAP_CLIENT}
     * profiles all ready.
+45 −5
Original line number Diff line number Diff line
@@ -24,12 +24,27 @@ import androidx.preference.PreferenceScreen;

import com.android.settings.R;

import com.google.common.annotations.VisibleForTesting;

/** Preference controller for footer in hearing device page. */
public class HearingDeviceFooterPreferenceController extends
        AccessibilityFooterPreferenceController {
    public HearingDeviceFooterPreferenceController(Context context,
            String key) {
    private final HearingAidHelper mHelper;

    public HearingDeviceFooterPreferenceController(
            @NonNull Context context,
            @NonNull String key) {
        super(context, key);
        mHelper = new HearingAidHelper(context);
    }

    @VisibleForTesting
    public HearingDeviceFooterPreferenceController(
            @NonNull Context context,
            @NonNull String key,
            @NonNull HearingAidHelper hearingAidHelper) {
        super(context, key);
        mHelper = hearingAidHelper;
    }

    @Override
@@ -37,22 +52,47 @@ public class HearingDeviceFooterPreferenceController extends
        return mContext.getString(R.string.accessibility_hearing_device_about_title);
    }

    @Override
    public int getAvailabilityStatus() {
        return mHelper.isHearingAidSupported() ? AVAILABLE : UNSUPPORTED_ON_DEVICE;
    }

    @Override
    public void displayPreference(@NonNull PreferenceScreen screen) {
        super.displayPreference(screen);

        final AccessibilityFooterPreference footerPreference =
                screen.findPreference(getPreferenceKey());
        final boolean isAshaProfileSupported = mHelper.isAshaProfileSupported();
        final boolean isHapClientProfileSupported = mHelper.isHapClientProfileSupported();
        final String summary;
        final String summaryTts;
        if (isAshaProfileSupported && isHapClientProfileSupported) {
            summary = mContext.getString(R.string.accessibility_hearing_device_footer_summary);
            summaryTts = mContext.getString(
                    R.string.accessibility_hearing_device_footer_summary_tts);
        } else if (isAshaProfileSupported) {
            summary = mContext.getString(
                    R.string.accessibility_hearing_device_footer_asha_only_summary);
            summaryTts = mContext.getString(
                    R.string.accessibility_hearing_device_footer_asha_only_summary_tts);
        } else if (isHapClientProfileSupported) {
            summary = mContext.getString(
                    R.string.accessibility_hearing_device_footer_hap_only_summary);
            summaryTts = mContext.getString(
                    R.string.accessibility_hearing_device_footer_hap_only_summary_tts);
        } else {
            return;
        }

        // We use html tag inside footer string, so it is better to load from html to have better
        // html tag support.
        final CharSequence title = Html.fromHtml(
                mContext.getString(R.string.accessibility_hearing_device_footer_summary),
                summary,
                Html.FROM_HTML_MODE_COMPACT, /* imageGetter= */ null, /* tagHandler= */ null);
        footerPreference.setTitle(title);

        // Need to update contentDescription string to announce "than" rather than ">"
        final String summaryTts = mContext.getString(
                R.string.accessibility_hearing_device_footer_summary_tts);
        final String contentDescription = getIntroductionTitle() + "\n\n" + summaryTts;
        footerPreference.setContentDescription(contentDescription);
    }
+74 −0
Original line number Diff line number Diff line
/*
 * 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 HearingDeviceIntroPreferenceController extends BasePreferenceController {
    private final HearingAidHelper mHelper;

    public HearingDeviceIntroPreferenceController(
            @NonNull Context context,
            @NonNull String preferenceKey) {
        super(context, preferenceKey);
        mHelper = new HearingAidHelper(context);
    }

    @VisibleForTesting
    public HearingDeviceIntroPreferenceController(
            @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 introPreference = screen.findPreference(getPreferenceKey());
        final boolean isAshaProfileSupported = mHelper.isAshaProfileSupported();
        final boolean isHapClientProfileSupported = mHelper.isHapClientProfileSupported();
        if (isAshaProfileSupported && isHapClientProfileSupported) {
            introPreference.setTitle(mContext.getString(R.string.accessibility_hearingaid_intro));
        } else if (isAshaProfileSupported) {
            introPreference.setTitle(
                    mContext.getString(R.string.accessibility_hearingaid_asha_only_intro));
        } else if (isHapClientProfileSupported) {
            introPreference.setTitle(
                    mContext.getString(R.string.accessibility_hearingaid_hap_only_intro));
        } else {
            // Intentionally blank, getAvailabilityStatus() should handle visibility for
            // none-supported case.
        }
    }
}
Loading