• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.development.featureflags;
18 
19 import android.content.Context;
20 import android.os.Build;
21 import android.util.FeatureFlagUtils;
22 
23 import androidx.preference.PreferenceGroup;
24 import androidx.preference.PreferenceScreen;
25 
26 import com.android.car.developeroptions.core.BasePreferenceController;
27 import com.android.settingslib.core.lifecycle.LifecycleObserver;
28 import com.android.settingslib.core.lifecycle.events.OnStart;
29 
30 import java.util.Map;
31 
32 public class FeatureFlagsPreferenceController extends BasePreferenceController
33         implements LifecycleObserver, OnStart {
34 
35     private PreferenceGroup mGroup;
36 
FeatureFlagsPreferenceController(Context context, String key)37     public FeatureFlagsPreferenceController(Context context, String key) {
38         super(context, key);
39     }
40 
41     @Override
getAvailabilityStatus()42     public int getAvailabilityStatus() {
43         return Build.IS_DEBUGGABLE ? AVAILABLE : UNSUPPORTED_ON_DEVICE;
44     }
45 
46     @Override
displayPreference(PreferenceScreen screen)47     public void displayPreference(PreferenceScreen screen) {
48         super.displayPreference(screen);
49         mGroup = screen.findPreference(getPreferenceKey());
50     }
51 
52     @Override
onStart()53     public void onStart() {
54         if (mGroup == null) {
55             return;
56         }
57         final Map<String, String> featureMap = FeatureFlagUtils.getAllFeatureFlags();
58         if (featureMap == null) {
59             return;
60         }
61         mGroup.removeAll();
62         final Context prefContext = mGroup.getContext();
63         featureMap.keySet().stream().sorted().forEach(feature ->
64                 mGroup.addPreference(new FeatureFlagPreference(prefContext, feature)));
65     }
66 }
67