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.content.Context; 19 import android.content.pm.PackageManager; 20 import android.provider.SearchIndexableResource; 21 22 import com.android.internal.logging.nano.MetricsProto; 23 import com.android.settings.R; 24 import com.android.settings.bluetooth.BluetoothFilesPreferenceController; 25 import com.android.settings.dashboard.DashboardFragment; 26 import com.android.settings.nfc.AndroidBeamPreferenceController; 27 import com.android.settings.print.PrintSettingPreferenceController; 28 import com.android.settings.search.BaseSearchIndexProvider; 29 import com.android.settingslib.core.AbstractPreferenceController; 30 import com.android.settingslib.core.lifecycle.Lifecycle; 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 public class AdvancedConnectedDeviceDashboardFragment extends DashboardFragment { 40 41 private static final String TAG = "AdvancedConnectedDeviceFrag"; 42 43 static final String KEY_BLUETOOTH = "bluetooth_settings"; 44 45 @Override getMetricsCategory()46 public int getMetricsCategory() { 47 return MetricsProto.MetricsEvent.CONNECTION_DEVICE_ADVANCED; 48 } 49 50 @Override getLogTag()51 protected String getLogTag() { 52 return TAG; 53 } 54 55 @Override getHelpResource()56 public int getHelpResource() { 57 return R.string.help_url_connected_devices; 58 } 59 60 @Override getPreferenceScreenResId()61 protected int getPreferenceScreenResId() { 62 return R.xml.connected_devices_advanced; 63 } 64 65 @Override createPreferenceControllers(Context context)66 protected List<AbstractPreferenceController> createPreferenceControllers(Context context) { 67 return buildControllers(context, getLifecycle()); 68 } 69 buildControllers(Context context, Lifecycle lifecycle)70 private static List<AbstractPreferenceController> buildControllers(Context context, 71 Lifecycle lifecycle) { 72 final List<AbstractPreferenceController> controllers = new ArrayList<>(); 73 74 controllers.add(new BluetoothFilesPreferenceController(context)); 75 controllers.add(new BluetoothOnWhileDrivingPreferenceController(context)); 76 77 final PrintSettingPreferenceController printerController = 78 new PrintSettingPreferenceController(context); 79 80 if (lifecycle != null) { 81 lifecycle.addObserver(printerController); 82 } 83 controllers.add(printerController); 84 85 return controllers; 86 } 87 88 /** 89 * For Search. 90 */ 91 public static final SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER = 92 new BaseSearchIndexProvider() { 93 @Override 94 public List<SearchIndexableResource> getXmlResourcesToIndex( 95 Context context, boolean enabled) { 96 final SearchIndexableResource sir = new SearchIndexableResource(context); 97 sir.xmlResId = R.xml.connected_devices_advanced; 98 return Arrays.asList(sir); 99 } 100 101 @Override 102 public List<String> getNonIndexableKeys(Context context) { 103 final List<String> keys = super.getNonIndexableKeys(context); 104 PackageManager pm = context.getPackageManager(); 105 if (!pm.hasSystemFeature(PackageManager.FEATURE_NFC)) { 106 keys.add(AndroidBeamPreferenceController.KEY_ANDROID_BEAM_SETTINGS); 107 } 108 109 // Parent duplicate 110 keys.add(KEY_BLUETOOTH); 111 112 return keys; 113 } 114 115 @Override 116 public List<AbstractPreferenceController> createPreferenceControllers( 117 Context context) { 118 return buildControllers(context, null /* lifecycle */); 119 } 120 }; 121 } 122