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.development.featureflags; 18 19 import android.content.Context; 20 import android.os.SystemProperties; 21 import android.text.TextUtils; 22 import android.util.FeatureFlagUtils; 23 24 import androidx.annotation.VisibleForTesting; 25 26 import com.android.settings.core.FeatureFlags; 27 28 import java.util.HashSet; 29 30 /** 31 * Helper class to get feature persistent flag information. 32 */ 33 public class FeatureFlagPersistent { 34 private static final HashSet<String> PERSISTENT_FLAGS; 35 static { 36 PERSISTENT_FLAGS = new HashSet<>(); 37 PERSISTENT_FLAGS.add(FeatureFlags.HEARING_AID_SETTINGS); 38 PERSISTENT_FLAGS.add(FeatureFlags.NETWORK_INTERNET_V2); 39 PERSISTENT_FLAGS.add(FeatureFlags.DYNAMIC_SYSTEM); 40 } 41 isEnabled(Context context, String feature)42 public static boolean isEnabled(Context context, String feature) { 43 String value = SystemProperties.get(FeatureFlagUtils.PERSIST_PREFIX + feature); 44 if (!TextUtils.isEmpty(value)) { 45 return Boolean.parseBoolean(value); 46 } else { 47 return FeatureFlagUtils.isEnabled(context, feature); 48 } 49 } 50 setEnabled(Context context, String feature, boolean enabled)51 public static void setEnabled(Context context, String feature, boolean enabled) { 52 SystemProperties.set(FeatureFlagUtils.PERSIST_PREFIX + feature, enabled ? "true" : "false"); 53 FeatureFlagUtils.setEnabled(context, feature, enabled); 54 } 55 isPersistent(String feature)56 public static boolean isPersistent(String feature) { 57 return PERSISTENT_FLAGS.contains(feature); 58 } 59 60 /** 61 * Returns all persistent flags in their raw form. 62 */ 63 @VisibleForTesting(otherwise = VisibleForTesting.NONE) getAllPersistentFlags()64 static HashSet<String> getAllPersistentFlags() { 65 return PERSISTENT_FLAGS; 66 } 67 } 68 69