• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2017 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 package com.android.settings.connecteddevice;
17 
18 import android.app.settings.SettingsEnums;
19 import android.content.Context;
20 import android.provider.SearchIndexableResource;
21 
22 import com.android.settings.R;
23 import com.android.settings.connecteddevice.virtual.VirtualDeviceListController;
24 import com.android.settings.dashboard.DashboardFragment;
25 import com.android.settings.print.PrintSettingPreferenceController;
26 import com.android.settings.search.BaseSearchIndexProvider;
27 import com.android.settings.uwb.UwbPreferenceController;
28 import com.android.settingslib.core.AbstractPreferenceController;
29 import com.android.settingslib.core.lifecycle.Lifecycle;
30 import com.android.settingslib.search.SearchIndexable;
31 
32 import java.util.ArrayList;
33 import java.util.Arrays;
34 import java.util.List;
35 
36 /**
37  * This fragment contains all the advanced connection preferences(i.e, Bluetooth, NFC, USB..)
38  */
39 @SearchIndexable(forTarget = SearchIndexable.ALL & ~SearchIndexable.ARC)
40 public class AdvancedConnectedDeviceDashboardFragment extends DashboardFragment {
41 
42     private static final String TAG = "AdvancedConnectedDeviceFrag";
43 
44     static final String KEY_BLUETOOTH = "bluetooth_settings";
45     static final String KEY_UWB = "uwb_settings";
46 
47     @Override
getMetricsCategory()48     public int getMetricsCategory() {
49         return SettingsEnums.CONNECTION_DEVICE_ADVANCED;
50     }
51 
52     @Override
getLogTag()53     protected String getLogTag() {
54         return TAG;
55     }
56 
57     @Override
getHelpResource()58     public int getHelpResource() {
59         return R.string.help_url_connected_devices;
60     }
61 
62     @Override
getPreferenceScreenResId()63     protected int getPreferenceScreenResId() {
64         return R.xml.connected_devices_advanced;
65     }
66 
67     @Override
onAttach(Context context)68     public void onAttach(Context context) {
69         super.onAttach(context);
70         UwbPreferenceController uwbPreferenceController = use(UwbPreferenceController.class);
71         // We only need the observer listen to the broadcast in the background for refreshing
72         // UI if the device supports UWB.
73         if (uwbPreferenceController != null && uwbPreferenceController.isUwbSupportedOnDevice()) {
74             if (getSettingsLifecycle() != null) {
75                 getSettingsLifecycle().addObserver(uwbPreferenceController);
76             }
77         }
78         use(VirtualDeviceListController.class).setFragment(this);
79     }
80 
81     @Override
createPreferenceControllers(Context context)82     protected List<AbstractPreferenceController> createPreferenceControllers(Context context) {
83         return buildControllers(context, getSettingsLifecycle());
84     }
85 
buildControllers(Context context, Lifecycle lifecycle)86     private static List<AbstractPreferenceController> buildControllers(Context context,
87             Lifecycle lifecycle) {
88         final List<AbstractPreferenceController> controllers = new ArrayList<>();
89 
90         final PrintSettingPreferenceController printerController =
91                 new PrintSettingPreferenceController(context);
92 
93         if (lifecycle != null) {
94             lifecycle.addObserver(printerController);
95         }
96         controllers.add(printerController);
97 
98         return controllers;
99     }
100 
101     /**
102      * For Search.
103      */
104     public static final BaseSearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
105             new BaseSearchIndexProvider() {
106                 @Override
107                 public List<SearchIndexableResource> getXmlResourcesToIndex(
108                         Context context, boolean enabled) {
109                     final SearchIndexableResource sir = new SearchIndexableResource(context);
110                     sir.xmlResId = R.xml.connected_devices_advanced;
111                     return Arrays.asList(sir);
112                 }
113 
114                 @Override
115                 public List<AbstractPreferenceController> createPreferenceControllers(
116                         Context context) {
117                     return buildControllers(context, null /* lifecycle */);
118                 }
119             };
120 }
121