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.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.settings.core.BasePreferenceController; 27 28 import java.util.Map; 29 30 /** 31 * A {@link BasePreferenceController} used in {@link FeatureFlagsDashboard} 32 */ 33 public class FeatureFlagsPreferenceController extends BasePreferenceController { 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 final Map<String, String> featureMap = FeatureFlagUtils.getAllFeatureFlags(); 51 if (featureMap == null) { 52 return; 53 } 54 mGroup.removeAll(); 55 final Context prefContext = mGroup.getContext(); 56 featureMap.keySet().stream().sorted().forEach(feature -> 57 mGroup.addPreference(new FeatureFlagPreference(prefContext, feature))); 58 } 59 } 60