1 /*
2  * Copyright (C) 2015 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.location;
18 
19 import android.app.settings.SettingsEnums;
20 import android.content.Context;
21 import android.provider.SearchIndexableResource;
22 
23 import com.android.settings.R;
24 import com.android.settings.dashboard.DashboardFragment;
25 import com.android.settings.search.BaseSearchIndexProvider;
26 import com.android.settings.search.Indexable;
27 import com.android.settingslib.core.AbstractPreferenceController;
28 import com.android.settingslib.search.SearchIndexable;
29 
30 import java.util.ArrayList;
31 import java.util.Arrays;
32 import java.util.List;
33 
34 /**
35  * A page that configures the background scanning settings for Wi-Fi and Bluetooth.
36  */
37 @SearchIndexable(forTarget = SearchIndexable.ALL & ~SearchIndexable.ARC)
38 public class ScanningSettings extends DashboardFragment {
39     private static final String TAG = "ScanningSettings";
40 
41     @Override
getMetricsCategory()42     public int getMetricsCategory() {
43         return SettingsEnums.LOCATION_SCANNING;
44     }
45 
46     @Override
getPreferenceScreenResId()47     protected int getPreferenceScreenResId() {
48         return R.xml.location_scanning;
49     }
50 
51     @Override
getLogTag()52     protected String getLogTag() {
53         return TAG;
54     }
55 
56     @Override
createPreferenceControllers(Context context)57     protected List<AbstractPreferenceController> createPreferenceControllers(Context context) {
58         return buildPreferenceControllers(context);
59     }
60 
buildPreferenceControllers(Context context)61     private static List<AbstractPreferenceController> buildPreferenceControllers(Context context) {
62         final List<AbstractPreferenceController> controllers = new ArrayList<>();
63         controllers.add(new WifiScanningPreferenceController(context));
64         controllers.add(new BluetoothScanningPreferenceController(context));
65         return controllers;
66     }
67 
68     /**
69      * For Search.
70      */
71     public static final Indexable.SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
72             new BaseSearchIndexProvider() {
73                 @Override
74                 public List<SearchIndexableResource> getXmlResourcesToIndex(
75                         Context context, boolean enabled) {
76                     final SearchIndexableResource sir = new SearchIndexableResource(context);
77                     sir.xmlResId = R.xml.location_scanning;
78                     return Arrays.asList(sir);
79                 }
80 
81                 @Override
82                 public List<AbstractPreferenceController> createPreferenceControllers(Context
83                         context) {
84                     return buildPreferenceControllers(context);
85                 }
86             };
87 }
88