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 android.companion.utils;
18 
19 import android.os.Binder;
20 import android.os.Build;
21 import android.provider.DeviceConfig;
22 
23 /**
24  * Util class for feature flags
25  *
26  * @hide
27  */
28 public final class FeatureUtils {
29 
30     private static final String NAMESPACE_COMPANION = "companion";
31 
32     private static final String PROPERTY_PERM_SYNC_ENABLED = "perm_sync_enabled";
33 
isPermSyncEnabled()34     public static boolean isPermSyncEnabled() {
35         // Permissions sync is always enabled in debuggable mode.
36         if (Build.isDebuggable()) {
37             return true;
38         }
39 
40         // Clear app identity to read the device config for feature flag.
41         final long identity = Binder.clearCallingIdentity();
42         try {
43             return DeviceConfig.getBoolean(NAMESPACE_COMPANION,
44                     PROPERTY_PERM_SYNC_ENABLED, false);
45         } finally {
46             Binder.restoreCallingIdentity(identity);
47         }
48     }
49 
FeatureUtils()50     private FeatureUtils() {
51     }
52 }
53