• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2023 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.ondevicepersonalization.services;
18 
19 import android.annotation.NonNull;
20 import android.os.SystemProperties;
21 import android.provider.DeviceConfig;
22 
23 import com.android.internal.annotations.VisibleForTesting;
24 
25 /** Flags Implementation that delegates to DeviceConfig. */
26 // TODO(b/228037065): Add validation logics for Feature flags read from PH.
27 public final class PhFlags implements Flags {
28     /*
29      * Keys for ALL the flags stored in DeviceConfig.
30      */
31     // Killswitch keys
32     static final String KEY_GLOBAL_KILL_SWITCH = "global_kill_switch";
33 
34     // SystemProperty prefix. SystemProperty is for overriding OnDevicePersonalization Configs.
35     private static final String SYSTEM_PROPERTY_PREFIX = "debug.ondevicepersonalization.";
36 
37     // OnDevicePersonalization Namespace String from DeviceConfig class
38     static final String NAMESPACE_ON_DEVICE_PERSONALIZATION = "on_device_personalization";
39     private static final PhFlags sSingleton = new PhFlags();
40 
41     /** Returns the singleton instance of the PhFlags. */
42     @NonNull
getInstance()43     public static PhFlags getInstance() {
44         return sSingleton;
45     }
46 
47     // Group of All Killswitches
48     @Override
getGlobalKillSwitch()49     public boolean getGlobalKillSwitch() {
50         // The priority of applying the flag values: SystemProperties, PH (DeviceConfig),
51         // then hard-coded value.
52         return SystemProperties.getBoolean(
53                         getSystemPropertyName(KEY_GLOBAL_KILL_SWITCH),
54                         DeviceConfig.getBoolean(
55                                 /* namespace= */ NAMESPACE_ON_DEVICE_PERSONALIZATION,
56                                 /* name= */ KEY_GLOBAL_KILL_SWITCH,
57                                 /* defaultValue= */ GLOBAL_KILL_SWITCH));
58     }
59 
60     @VisibleForTesting
getSystemPropertyName(String key)61     static String getSystemPropertyName(String key) {
62         return SYSTEM_PROPERTY_PREFIX + key;
63     }
64 }
65