1 /*
2  * Copyright (C) 2018 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.fuelgauge;
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.SettingsActivity;
25 import com.android.settings.core.InstrumentedPreferenceFragment;
26 import com.android.settings.dashboard.DashboardFragment;
27 import com.android.settings.search.BaseSearchIndexProvider;
28 import com.android.settingslib.core.AbstractPreferenceController;
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  * Fragment to show smart battery and restricted app controls
37  */
38 @SearchIndexable(forTarget = SearchIndexable.ALL & ~SearchIndexable.ARC)
39 public class SmartBatterySettings extends DashboardFragment {
40     public static final String TAG = "SmartBatterySettings";
41 
42     @Override
getMetricsCategory()43     public int getMetricsCategory() {
44         return SettingsEnums.FUELGAUGE_SMART_BATTERY;
45     }
46 
47     @Override
getLogTag()48     protected String getLogTag() {
49         return TAG;
50     }
51 
52     @Override
getPreferenceScreenResId()53     protected int getPreferenceScreenResId() {
54         return R.xml.smart_battery_detail;
55     }
56 
57     @Override
getHelpResource()58     public int getHelpResource() {
59         return R.string.help_uri_smart_battery_settings;
60     }
61 
62     @Override
createPreferenceControllers(Context context)63     protected List<AbstractPreferenceController> createPreferenceControllers(Context context) {
64         return buildPreferenceControllers(context, (SettingsActivity) getActivity(), this);
65     }
66 
buildPreferenceControllers( Context context, SettingsActivity settingsActivity, InstrumentedPreferenceFragment fragment)67     private static List<AbstractPreferenceController> buildPreferenceControllers(
68             Context context, SettingsActivity settingsActivity,
69             InstrumentedPreferenceFragment fragment) {
70         final List<AbstractPreferenceController> controllers = new ArrayList<>();
71         if (settingsActivity != null && fragment != null) {
72             controllers.add(
73                     new RestrictAppPreferenceController(fragment));
74         } else {
75             controllers.add(new RestrictAppPreferenceController(context));
76         }
77 
78         return controllers;
79     }
80 
81     public static final BaseSearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
82             new BaseSearchIndexProvider() {
83                 @Override
84                 public List<SearchIndexableResource> getXmlResourcesToIndex(
85                         Context context, boolean enabled) {
86                     final SearchIndexableResource sir = new SearchIndexableResource(context);
87                     sir.xmlResId = R.xml.smart_battery_detail;
88                     return Arrays.asList(sir);
89                 }
90 
91                 @Override
92                 public List<AbstractPreferenceController> createPreferenceControllers(
93                         Context context) {
94                     return buildPreferenceControllers(context, null, null);
95                 }
96             };
97 }
98