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.content.pm.PackageManager; 21 import android.provider.SearchIndexableResource; 22 23 import com.android.settings.R; 24 import com.android.settings.dashboard.DashboardFragment; 25 import com.android.settings.nfc.AndroidBeamPreferenceController; 26 import com.android.settings.print.PrintSettingPreferenceController; 27 import com.android.settings.search.BaseSearchIndexProvider; 28 import com.android.settings.uwb.UwbPreferenceController; 29 import com.android.settingslib.core.AbstractPreferenceController; 30 import com.android.settingslib.core.lifecycle.Lifecycle; 31 import com.android.settingslib.search.SearchIndexable; 32 33 import java.util.ArrayList; 34 import java.util.Arrays; 35 import java.util.List; 36 37 /** 38 * This fragment contains all the advanced connection preferences(i.e, Bluetooth, NFC, USB..) 39 */ 40 @SearchIndexable(forTarget = SearchIndexable.ALL & ~SearchIndexable.ARC) 41 public class AdvancedConnectedDeviceDashboardFragment extends DashboardFragment { 42 43 private static final String TAG = "AdvancedConnectedDeviceFrag"; 44 45 static final String KEY_BLUETOOTH = "bluetooth_settings"; 46 static final String KEY_UWB = "uwb_settings"; 47 48 @Override getMetricsCategory()49 public int getMetricsCategory() { 50 return SettingsEnums.CONNECTION_DEVICE_ADVANCED; 51 } 52 53 @Override getLogTag()54 protected String getLogTag() { 55 return TAG; 56 } 57 58 @Override getHelpResource()59 public int getHelpResource() { 60 return R.string.help_url_connected_devices; 61 } 62 63 @Override getPreferenceScreenResId()64 protected int getPreferenceScreenResId() { 65 return R.xml.connected_devices_advanced; 66 } 67 68 @Override onAttach(Context context)69 public void onAttach(Context context) { 70 super.onAttach(context); 71 UwbPreferenceController uwbPreferenceController = use(UwbPreferenceController.class); 72 // We only need the observer listen to the broadcast in the background for refreshing 73 // UI if the device supports UWB. 74 if (uwbPreferenceController != null && uwbPreferenceController.isUwbSupportedOnDevice()) { 75 if (getSettingsLifecycle() != null) { 76 getSettingsLifecycle().addObserver(uwbPreferenceController); 77 } 78 } 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<String> getNonIndexableKeys(Context context) { 116 final List<String> keys = super.getNonIndexableKeys(context); 117 PackageManager pm = context.getPackageManager(); 118 if (!pm.hasSystemFeature(PackageManager.FEATURE_NFC)) { 119 keys.add(AndroidBeamPreferenceController.KEY_ANDROID_BEAM_SETTINGS); 120 } 121 122 return keys; 123 } 124 125 @Override 126 public List<AbstractPreferenceController> createPreferenceControllers( 127 Context context) { 128 return buildControllers(context, null /* lifecycle */); 129 } 130 }; 131 } 132