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.launcher3.uioverrides;
18 
19 import android.annotation.TargetApi;
20 import android.os.Build;
21 import android.provider.DeviceConfig;
22 
23 import com.android.launcher3.config.FeatureFlags.DebugFlag;
24 
25 @TargetApi(Build.VERSION_CODES.P)
26 public class DeviceFlag extends DebugFlag {
27 
28     public static final String NAMESPACE_LAUNCHER = "launcher";
29 
30     private final boolean mDefaultValueInCode;
31 
DeviceFlag(String key, boolean defaultValue, String description)32     public DeviceFlag(String key, boolean defaultValue, String description) {
33         super(key, getDeviceValue(key, defaultValue), description);
34         mDefaultValueInCode = defaultValue;
35     }
36 
37     @Override
appendProps(StringBuilder src)38     protected StringBuilder appendProps(StringBuilder src) {
39         return super.appendProps(src).append(", mDefaultValueInCode=").append(mDefaultValueInCode);
40     }
41 
42     @Override
get()43     public boolean get() {
44         // Override this method in order to let Robolectric ShadowDeviceFlag to stub it.
45         return super.get();
46     }
47 
getDeviceValue(String key, boolean defaultValue)48     protected static boolean getDeviceValue(String key, boolean defaultValue) {
49         return DeviceConfig.getBoolean(NAMESPACE_LAUNCHER, key, defaultValue);
50     }
51 }
52