Fan Zhang | 690986d | 2017-08-17 11:22:31 -0700 | [diff] [blame^] | 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 android.util; |
| 18 | |
| 19 | import android.os.SystemProperties; |
| 20 | import android.text.TextUtils; |
| 21 | |
| 22 | import java.util.Map; |
| 23 | |
| 24 | /** |
| 25 | * Util class to get feature flag information. |
| 26 | * |
| 27 | * @hide |
| 28 | */ |
| 29 | public class FeatureFlagUtils { |
| 30 | |
| 31 | public static final String FFLAG_PREFIX = "sys.fflag."; |
| 32 | public static final String FFLAG_OVERRIDE_PREFIX = FFLAG_PREFIX + "override."; |
| 33 | |
| 34 | /** |
| 35 | * Whether or not a flag is enabled. |
| 36 | * |
| 37 | * @param feature the flag name |
| 38 | * @return true if the flag is enabled (either by default in system, or override by user) |
| 39 | */ |
| 40 | public static boolean isEnabled(String feature) { |
| 41 | // Tries to get feature flag from system property. |
| 42 | // Step 1: check if feature flag has any override. Flag name: sys.fflag.override.<feature> |
| 43 | String value = SystemProperties.get(FFLAG_OVERRIDE_PREFIX + feature); |
| 44 | if (!TextUtils.isEmpty(value)) { |
| 45 | return Boolean.parseBoolean(value); |
| 46 | } |
| 47 | // Step 2: check if feature flag has any default value. Flag name: sys.fflag.<feature> |
| 48 | value = SystemProperties.get(FFLAG_PREFIX + feature); |
| 49 | return Boolean.parseBoolean(value); |
| 50 | } |
| 51 | |
| 52 | /** |
| 53 | * Returns all feature flags in their raw form. |
| 54 | */ |
| 55 | public static Map<String, String> getAllFeatureFlags() { |
| 56 | return null; |
| 57 | } |
| 58 | } |