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