• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
17 package com.android.settings.development.featureflags;
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.core.lifecycle.Lifecycle;
29 import com.android.settingslib.development.DevelopmentSettingsEnabler;
30 import com.android.settingslib.search.SearchIndexable;
31 
32 import java.util.ArrayList;
33 import java.util.List;
34 
35 @SearchIndexable
36 public class FeatureFlagsDashboard extends DashboardFragment {
37 
38     private static final String TAG = "FeatureFlagsDashboard";
39 
40     @Override
getMetricsCategory()41     public int getMetricsCategory() {
42         return SettingsEnums.SETTINGS_FEATURE_FLAGS_DASHBOARD;
43     }
44 
45     @Override
getLogTag()46     protected String getLogTag() {
47         return TAG;
48     }
49 
50     @Override
getPreferenceScreenResId()51     protected int getPreferenceScreenResId() {
52         return R.xml.feature_flags_settings;
53     }
54 
55     @Override
onAttach(Context context)56     public void onAttach(Context context) {
57         super.onAttach(context);
58         use(FeatureFlagFooterPreferenceController.class).setFooterMixin(mFooterPreferenceMixin);
59     }
60 
61     @Override
getHelpResource()62     public int getHelpResource() {
63         return 0;
64     }
65 
66     @Override
createPreferenceControllers(Context context)67     protected List<AbstractPreferenceController> createPreferenceControllers(Context context) {
68         return buildPrefControllers(context, getSettingsLifecycle());
69     }
70 
buildPrefControllers(Context context, Lifecycle lifecycle)71     private static List<AbstractPreferenceController> buildPrefControllers(Context context,
72             Lifecycle lifecycle) {
73         final List<AbstractPreferenceController> controllers = new ArrayList<>();
74         final FeatureFlagFooterPreferenceController footerController =
75                 new FeatureFlagFooterPreferenceController(context);
76         if (lifecycle != null) {
77             lifecycle.addObserver(footerController);
78         }
79         controllers.add(footerController);
80         return controllers;
81     }
82 
83     public static final Indexable.SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
84             new BaseSearchIndexProvider() {
85                 @Override
86                 public List<SearchIndexableResource> getXmlResourcesToIndex(Context context,
87                         boolean enabled) {
88                     final List<SearchIndexableResource> result = new ArrayList<>();
89 
90                     final SearchIndexableResource sir = new SearchIndexableResource(context);
91                     sir.xmlResId = R.xml.feature_flags_settings;
92                     result.add(sir);
93                     return result;
94                 }
95 
96                 @Override
97                 protected boolean isPageSearchEnabled(Context context) {
98                     return DevelopmentSettingsEnabler.isDevelopmentSettingsEnabled(context);
99                 }
100 
101                 @Override
102                 public List<AbstractPreferenceController> createPreferenceControllers(
103                         Context context) {
104                     return buildPrefControllers(context, null /* lifecycle */);
105                 }
106             };
107 }
108