1 /*
2  * Copyright (C) 2019 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.car.developeroptions.fuelgauge;
18 
19 import android.app.settings.SettingsEnums;
20 import android.content.Context;
21 import android.provider.SearchIndexableResource;
22 
23 import com.android.car.developeroptions.R;
24 import com.android.car.developeroptions.SettingsActivity;
25 import com.android.car.developeroptions.core.InstrumentedPreferenceFragment;
26 import com.android.car.developeroptions.dashboard.DashboardFragment;
27 import com.android.car.developeroptions.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         controllers.add(new SmartBatteryPreferenceController(context));
72         if (settingsActivity != null && fragment != null) {
73             controllers.add(
74                     new RestrictAppPreferenceController(fragment));
75         } else {
76             controllers.add(new RestrictAppPreferenceController(context));
77         }
78 
79         return controllers;
80     }
81 
82     public static final SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
83             new BaseSearchIndexProvider() {
84                 @Override
85                 public List<SearchIndexableResource> getXmlResourcesToIndex(
86                         Context context, boolean enabled) {
87                     final SearchIndexableResource sir = new SearchIndexableResource(context);
88                     sir.xmlResId = R.xml.smart_battery_detail;
89                     return Arrays.asList(sir);
90                 }
91 
92                 @Override
93                 public List<AbstractPreferenceController> createPreferenceControllers(
94                         Context context) {
95                     return buildPreferenceControllers(context, null, null);
96                 }
97             };
98 }
99