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