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.server.companion;
18 
19 import android.os.Binder;
20 import android.provider.DeviceConfig;
21 
22 /**
23  * Feature flags for companion.
24  */
25 public class CompanionDeviceConfig {
26 
27     private static final String NAMESPACE_COMPANION = "companion";
28 
29     /**
30      * Whether system data syncing for telecom-type data is enabled.
31      */
32     public static final String ENABLE_CONTEXT_SYNC_TELECOM = "enable_context_sync_telecom";
33 
34     /**
35      * Returns whether the given flag is currently enabled, with a default value of {@code false}.
36      */
isEnabled(String flag)37     public static boolean isEnabled(String flag) {
38         final long token = Binder.clearCallingIdentity();
39         try {
40             return DeviceConfig.getBoolean(NAMESPACE_COMPANION, flag, /* defaultValue= */ false);
41         } finally {
42             Binder.restoreCallingIdentity(token);
43         }
44     }
45 
46     /**
47      * Returns whether the given flag is currently enabled.
48      */
isEnabled(String flag, boolean defaultValue)49     public static boolean isEnabled(String flag, boolean defaultValue) {
50         return DeviceConfig.getBoolean(NAMESPACE_COMPANION, flag, defaultValue);
51     }
52 }
53