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.KEY_ADSERVICES_SHELL_COMMAND_ENABLED;
20 
21 import android.os.SystemProperties;
22 
23 import com.android.internal.annotations.VisibleForTesting;
24 
25 /**
26  * Common debug flags shared between system-server and service that are only used for development /
27  * testing purposes.
28  *
29  * <p>They're never pushed to devices (through `DeviceConfig`) and must be manually set by the
30  * developer (or automatically set by the test), so they're implemented using System Properties.
31  *
32  * <p><b>NOTE: </b> the value of these flags should be such that the behavior they're changing is
33  * not changed or the feature they're guarding is disabled, so usually their default value should be
34  * {@code false}.
35  *
36  * @hide
37  */
38 public abstract class CommonDebugFlags {
39     private static final String SYSTEM_PROPERTY_FOR_DEBUGGING_PREFIX = "debug.adservices.";
40 
41     @VisibleForTesting static final boolean DEFAULT_ADSERVICES_SHELL_COMMAND_ENABLED = false;
42 
getAdServicesShellCommandEnabled()43     public boolean getAdServicesShellCommandEnabled() {
44         return getDebugFlag(
45                 KEY_ADSERVICES_SHELL_COMMAND_ENABLED, DEFAULT_ADSERVICES_SHELL_COMMAND_ENABLED);
46     }
47 
getDebugFlag(String name, boolean defaultValue)48     static boolean getDebugFlag(String name, boolean defaultValue) {
49         return SystemProperties.getBoolean(getSystemPropertyName(name), defaultValue);
50     }
51 
getSystemPropertyName(String key)52     private static String getSystemPropertyName(String key) {
53         return SYSTEM_PROPERTY_FOR_DEBUGGING_PREFIX + key;
54     }
55 }
56