1 /* 2 * Copyright (C) 2025 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 17 package com.android.settings.accessibility; 18 19 import android.content.Context; 20 21 import androidx.annotation.NonNull; 22 import androidx.preference.Preference; 23 import androidx.preference.PreferenceScreen; 24 25 import com.android.settings.R; 26 import com.android.settings.core.BasePreferenceController; 27 28 import com.google.common.annotations.VisibleForTesting; 29 30 public class HearingDevicePairingIntroPreferenceController extends BasePreferenceController { 31 private final HearingAidHelper mHelper; 32 HearingDevicePairingIntroPreferenceController( @onNull Context context, @NonNull String preferenceKey)33 public HearingDevicePairingIntroPreferenceController( 34 @NonNull Context context, 35 @NonNull String preferenceKey) { 36 super(context, preferenceKey); 37 mHelper = new HearingAidHelper(context); 38 } 39 40 @VisibleForTesting HearingDevicePairingIntroPreferenceController( @onNull Context context, @NonNull String preferenceKey, @NonNull HearingAidHelper hearingAidHelper)41 public HearingDevicePairingIntroPreferenceController( 42 @NonNull Context context, 43 @NonNull String preferenceKey, 44 @NonNull HearingAidHelper hearingAidHelper) { 45 super(context, preferenceKey); 46 mHelper = hearingAidHelper; 47 } 48 49 @Override getAvailabilityStatus()50 public int getAvailabilityStatus() { 51 return mHelper.isHearingAidSupported() ? AVAILABLE : UNSUPPORTED_ON_DEVICE; 52 } 53 54 @Override displayPreference(@onNull PreferenceScreen screen)55 public void displayPreference(@NonNull PreferenceScreen screen) { 56 super.displayPreference(screen); 57 58 final Preference pairingIntroPreference = screen.findPreference(getPreferenceKey()); 59 final boolean isAshaProfileSupported = mHelper.isAshaProfileSupported(); 60 final boolean isHapClientProfileSupported = mHelper.isHapClientProfileSupported(); 61 if (isAshaProfileSupported && isHapClientProfileSupported) { 62 pairingIntroPreference.setTitle( 63 mContext.getString(R.string.accessibility_hearing_device_pairing_intro)); 64 } else if (isAshaProfileSupported) { 65 pairingIntroPreference.setTitle( 66 mContext.getString( 67 R.string.accessibility_hearing_device_pairing_asha_only_intro)); 68 } else if (isHapClientProfileSupported) { 69 pairingIntroPreference.setTitle( 70 mContext.getString( 71 R.string.accessibility_hearing_device_pairing_hap_only_intro)); 72 } else { 73 // Intentionally blank, getAvailabilityStatus() should handle visibility for 74 // none-supported case. 75 } 76 } 77 } 78