1 /* 2 * Copyright (C) 2022 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.util.Log; 20 21 import androidx.annotation.NonNull; 22 import androidx.fragment.app.FragmentManager; 23 24 import com.android.settings.bluetooth.HearingAidPairingDialogFragment; 25 import com.android.settingslib.bluetooth.CachedBluetoothDevice; 26 import com.android.settingslib.bluetooth.CsipSetCoordinatorProfile; 27 import com.android.settingslib.bluetooth.HearingAidInfo; 28 29 /** Provides utility methods related hearing aids. */ 30 public final class HearingAidUtils { 31 private static final String TAG = "HearingAidUtils"; 32 HearingAidUtils()33 private HearingAidUtils(){} 34 35 /** 36 * Launches pairing dialog when hearing aid device needs other side of hearing aid device to 37 * work. 38 * 39 * @param fragmentManager The {@link FragmentManager} used to show dialog fragment 40 * @param device The {@link CachedBluetoothDevice} need to be hearing aid device 41 * @param launchPage The page id where the dialog is launched 42 */ launchHearingAidPairingDialog(FragmentManager fragmentManager, @NonNull CachedBluetoothDevice device, int launchPage)43 public static void launchHearingAidPairingDialog(FragmentManager fragmentManager, 44 @NonNull CachedBluetoothDevice device, int launchPage) { 45 // No need to show the pair another ear dialog if the device supports CSIP. 46 // CSIP will pair other devices in the same set automatically. 47 if (device.getProfiles().stream().anyMatch( 48 profile -> profile instanceof CsipSetCoordinatorProfile)) { 49 return; 50 } 51 if (device.isConnectedAshaHearingAidDevice() 52 && device.getDeviceMode() == HearingAidInfo.DeviceMode.MODE_BINAURAL 53 && device.getSubDevice() == null) { 54 launchHearingAidPairingDialogInternal(fragmentManager, device, launchPage); 55 } 56 } 57 launchHearingAidPairingDialogInternal(FragmentManager fragmentManager, @NonNull CachedBluetoothDevice device, int launchPage)58 private static void launchHearingAidPairingDialogInternal(FragmentManager fragmentManager, 59 @NonNull CachedBluetoothDevice device, int launchPage) { 60 if (device.getDeviceSide() == HearingAidInfo.DeviceSide.SIDE_INVALID) { 61 Log.w(TAG, "Can not launch hearing aid pairing dialog for invalid side"); 62 return; 63 } 64 HearingAidPairingDialogFragment.newInstance(device.getAddress(), launchPage) 65 .show(fragmentManager, HearingAidPairingDialogFragment.TAG); 66 } 67 } 68