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 } 39 isEnabled(Context context, String feature)40 public static boolean isEnabled(Context context, String feature) { 41 String value = SystemProperties.get(FeatureFlagUtils.PERSIST_PREFIX + feature); 42 if (!TextUtils.isEmpty(value)) { 43 return Boolean.parseBoolean(value); 44 } else { 45 return FeatureFlagUtils.isEnabled(context, feature); 46 } 47 } 48 setEnabled(Context context, String feature, boolean enabled)49 public static void setEnabled(Context context, String feature, boolean enabled) { 50 SystemProperties.set(FeatureFlagUtils.PERSIST_PREFIX + feature, enabled ? "true" : "false"); 51 FeatureFlagUtils.setEnabled(context, feature, enabled); 52 } 53 isPersistent(String feature)54 public static boolean isPersistent(String feature) { 55 return PERSISTENT_FLAGS.contains(feature); 56 } 57 58 /** 59 * Returns all persistent flags in their raw form. 60 */ 61 @VisibleForTesting(otherwise = VisibleForTesting.NONE) getAllPersistentFlags()62 static HashSet<String> getAllPersistentFlags() { 63 return PERSISTENT_FLAGS; 64 } 65 } 66 67