1 /*
2  * Copyright (C) 2024 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.adservices.service;
18 
19 import static com.android.adservices.service.CommonFlagsConstants.NAMESPACE_ADSERVICES;
20 
21 import android.provider.DeviceConfig;
22 
23 // NOTE: not package-protected because it's used by {@code MddFlags}. It could also be moved to
24 // shared code (and take the namespace in the constructor), but it's too simple for that.
25 /**
26  * Helper class that abstract calls to DeviceConfig for adservices namespace.
27  *
28  * @hide
29  */
30 @SuppressWarnings("AvoidDeviceConfigUsage") // Helper / infra class
31 public final class DeviceConfigFlagsHelper {
32 
33     /** Gets the value of a boolean flag. */
getDeviceConfigFlag(String name, boolean defaultValue)34     public static boolean getDeviceConfigFlag(String name, boolean defaultValue) {
35         return DeviceConfig.getBoolean(NAMESPACE_ADSERVICES, name, defaultValue);
36     }
37 
38     /** Gets the value of a string flag. */
getDeviceConfigFlag(String name, String defaultValue)39     public static String getDeviceConfigFlag(String name, String defaultValue) {
40         return DeviceConfig.getString(NAMESPACE_ADSERVICES, name, defaultValue);
41     }
42 
43     /** Gets the value of a int flag. */
getDeviceConfigFlag(String name, int defaultValue)44     public static int getDeviceConfigFlag(String name, int defaultValue) {
45         return DeviceConfig.getInt(NAMESPACE_ADSERVICES, name, defaultValue);
46     }
47 
48     /** Gets the value of a long flag. */
getDeviceConfigFlag(String name, long defaultValue)49     public static long getDeviceConfigFlag(String name, long defaultValue) {
50         return DeviceConfig.getLong(NAMESPACE_ADSERVICES, name, defaultValue);
51     }
52 
53     /** Gets the value of a float flag. */
getDeviceConfigFlag(String name, float defaultValue)54     public static float getDeviceConfigFlag(String name, float defaultValue) {
55         return DeviceConfig.getFloat(NAMESPACE_ADSERVICES, name, defaultValue);
56     }
57 
DeviceConfigFlagsHelper()58     private DeviceConfigFlagsHelper() {
59         throw new UnsupportedOperationException("provides only static methods");
60     }
61 }
62