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