1 /* 2 * Copyright (C) 2024 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.bluetooth; 18 19 import android.content.Context; 20 21 import androidx.annotation.NonNull; 22 import androidx.preference.PreferenceFragmentCompat; 23 import androidx.preference.PreferenceScreen; 24 25 import com.android.settings.accessibility.Flags; 26 import com.android.settingslib.bluetooth.CachedBluetoothDevice; 27 import com.android.settingslib.bluetooth.LocalBluetoothManager; 28 import com.android.settingslib.core.lifecycle.Lifecycle; 29 30 import com.google.common.annotations.VisibleForTesting; 31 32 import java.util.ArrayList; 33 import java.util.List; 34 35 /** 36 * The controller of the hearing device controls. 37 * 38 * <p><b>Note:</b> It is responsible for creating the sub-controllers inside this preference 39 * category controller. 40 */ 41 public class BluetoothDetailsHearingDeviceController extends BluetoothDetailsController { 42 43 public static final int ORDER_HEARING_DEVICE_SETTINGS = 1; 44 public static final int ORDER_HEARING_AIDS_PRESETS = 2; 45 static final String KEY_HEARING_DEVICE_GROUP = "hearing_device_group"; 46 47 private final List<BluetoothDetailsController> mControllers = new ArrayList<>(); 48 private Lifecycle mLifecycle; 49 private LocalBluetoothManager mManager; 50 BluetoothDetailsHearingDeviceController(@onNull Context context, @NonNull PreferenceFragmentCompat fragment, @NonNull LocalBluetoothManager manager, @NonNull CachedBluetoothDevice device, @NonNull Lifecycle lifecycle)51 public BluetoothDetailsHearingDeviceController(@NonNull Context context, 52 @NonNull PreferenceFragmentCompat fragment, 53 @NonNull LocalBluetoothManager manager, 54 @NonNull CachedBluetoothDevice device, 55 @NonNull Lifecycle lifecycle) { 56 super(context, fragment, device, lifecycle); 57 mManager = manager; 58 mLifecycle = lifecycle; 59 } 60 61 @VisibleForTesting setSubControllers( BluetoothDetailsHearingDeviceSettingsController hearingDeviceSettingsController, BluetoothDetailsHearingAidsPresetsController presetsController)62 void setSubControllers( 63 BluetoothDetailsHearingDeviceSettingsController hearingDeviceSettingsController, 64 BluetoothDetailsHearingAidsPresetsController presetsController) { 65 mControllers.clear(); 66 mControllers.add(hearingDeviceSettingsController); 67 mControllers.add(presetsController); 68 } 69 70 @Override isAvailable()71 public boolean isAvailable() { 72 return mControllers.stream().anyMatch(BluetoothDetailsController::isAvailable); 73 } 74 75 @Override 76 @NonNull getPreferenceKey()77 public String getPreferenceKey() { 78 return KEY_HEARING_DEVICE_GROUP; 79 } 80 81 @Override init(PreferenceScreen screen)82 protected void init(PreferenceScreen screen) { 83 84 } 85 86 @Override refresh()87 protected void refresh() { 88 89 } 90 91 /** 92 * Initiates the sub controllers controlled by this group controller. 93 * 94 * <p><b>Note:</b> The caller must call this method when creating this class. 95 * 96 * @param isLaunchFromHearingDevicePage a boolean that determines if the caller is launch from 97 * hearing device page 98 */ initSubControllers(boolean isLaunchFromHearingDevicePage)99 void initSubControllers(boolean isLaunchFromHearingDevicePage) { 100 mControllers.clear(); 101 // Don't need to show the entrance to hearing device page when launched from the same page 102 if (!isLaunchFromHearingDevicePage) { 103 mControllers.add(new BluetoothDetailsHearingDeviceSettingsController(mContext, 104 mFragment, mCachedDevice, mLifecycle)); 105 } 106 if (Flags.enableHearingAidPresetControl()) { 107 mControllers.add(new BluetoothDetailsHearingAidsPresetsController(mContext, mFragment, 108 mManager, mCachedDevice, mLifecycle)); 109 } 110 } 111 112 @NonNull getSubControllers()113 public List<BluetoothDetailsController> getSubControllers() { 114 return mControllers; 115 } 116 } 117