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.DebugFlagsConstants.KEY_AD_SELECTION_CLI_ENABLED;
20 import static com.android.adservices.service.DebugFlagsConstants.KEY_AD_SERVICES_JS_ISOLATE_CONSOLE_MESSAGES_IN_LOGS_ENABLED;
21 import static com.android.adservices.service.DebugFlagsConstants.KEY_CONSENT_MANAGER_DEBUG_MODE;
22 import static com.android.adservices.service.DebugFlagsConstants.KEY_CONSENT_MANAGER_OTA_DEBUG_MODE;
23 import static com.android.adservices.service.DebugFlagsConstants.KEY_CONSENT_NOTIFICATION_ACTIVITY_DEBUG_MODE;
24 import static com.android.adservices.service.DebugFlagsConstants.KEY_CONSENT_NOTIFICATION_DEBUG_MODE;
25 import static com.android.adservices.service.DebugFlagsConstants.KEY_CONSENT_NOTIFIED_DEBUG_MODE;
26 import static com.android.adservices.service.DebugFlagsConstants.KEY_FLEDGE_AUCTION_SERVER_CONSENTED_DEBUGGING_ENABLED;
27 import static com.android.adservices.service.DebugFlagsConstants.KEY_FLEDGE_IS_CONSENTED_DEBUGGING_CLI_ENABLED;
28 import static com.android.adservices.service.DebugFlagsConstants.KEY_FLEDGE_IS_CUSTOM_AUDIENCE_CLI_ENABLED;
29 import static com.android.adservices.service.DebugFlagsConstants.KEY_PROTECTED_APP_SIGNALS_CLI_ENABLED;
30 import static com.android.adservices.service.DebugFlagsConstants.KEY_RECORD_TOPICS_COMPLETE_BROADCAST_ENABLED;
31 import static com.android.adservices.service.Flags.CONSENT_MANAGER_DEBUG_MODE;
32 import static com.android.adservices.service.Flags.CONSENT_NOTIFICATION_ACTIVITY_DEBUG_MODE;
33 import static com.android.adservices.service.Flags.CONSENT_NOTIFICATION_DEBUG_MODE;
34 import static com.android.adservices.service.Flags.CONSENT_NOTIFIED_DEBUG_MODE;
35 import static com.android.adservices.service.Flags.DEFAULT_CONSENT_MANAGER_OTA_DEBUG_MODE;
36 
37 import androidx.annotation.VisibleForTesting;
38 
39 /**
40  * Flags that are only used for development / testing purposes.
41  *
42  * <p>They're never pushed to devices (through `DeviceConfig`) and must be manually set by the
43  * developer (or automatically set by the test), so they're implemented using System Properties.
44  *
45  * <p><b>NOTE: </b> the value of these flags should be such that the behavior they're changing is
46  * not changed or the feature they're guarding is disabled, so usually their default value should be
47  * {@code false}.
48  */
49 public final class DebugFlags extends CommonDebugFlags {
50     private static final DebugFlags sInstance = new DebugFlags();
51 
52     /** Default for if FLEDGE app signals CLI is enabled. */
53     @VisibleForTesting static final boolean DEFAULT_PROTECTED_APP_SIGNALS_CLI_ENABLED = false;
54 
55     /** Default for if FLEDGE ad selection CLI is enabled. */
56     @VisibleForTesting static final boolean DEFAULT_AD_SELECTION_CLI_ENABLED = false;
57 
58     /** Default value for fledge auction server consented debug enabled. */
59     @VisibleForTesting
60     static final boolean DEFAULT_FLEDGE_AUCTION_SERVER_CONSENTED_DEBUGGING_ENABLED = false;
61 
62     /** Default value for console messages from js isolate be available in logcat. */
63     @VisibleForTesting
64     static final boolean DEFAULT_JS_ISOLATE_CONSOLE_MESSAGES_IN_LOGS_ENABLED = false;
65 
66     /** Default value for status of custom audiences CLI feature */
67     @VisibleForTesting static final boolean DEFAULT_FLEDGE_CUSTOM_AUDIENCE_CLI_ENABLED = false;
68 
69     /** Default value for status of consented debugging CLI feature */
70     @VisibleForTesting static final boolean DEFAULT_FLEDGE_CONSENTED_DEBUGGING_CLI_ENABLED = false;
71 
72     /** Default value for sending a broadcast when record topics is completed. */
73     @VisibleForTesting
74     static final boolean DEFAULT_RECORD_TOPICS_COMPLETE_BROADCAST_ENABLED = false;
75 
getInstance()76     public static DebugFlags getInstance() {
77         return sInstance;
78     }
79 
DebugFlags()80     private DebugFlags() {}
81 
getConsentNotificationDebugMode()82     public boolean getConsentNotificationDebugMode() {
83         return getDebugFlag(KEY_CONSENT_NOTIFICATION_DEBUG_MODE, CONSENT_NOTIFICATION_DEBUG_MODE);
84     }
85 
getConsentNotifiedDebugMode()86     public boolean getConsentNotifiedDebugMode() {
87         return getDebugFlag(KEY_CONSENT_NOTIFIED_DEBUG_MODE, CONSENT_NOTIFIED_DEBUG_MODE);
88     }
89 
getConsentNotificationActivityDebugMode()90     public boolean getConsentNotificationActivityDebugMode() {
91         return getDebugFlag(
92                 KEY_CONSENT_NOTIFICATION_ACTIVITY_DEBUG_MODE,
93                 CONSENT_NOTIFICATION_ACTIVITY_DEBUG_MODE);
94     }
95 
getConsentManagerDebugMode()96     public boolean getConsentManagerDebugMode() {
97         return getDebugFlag(KEY_CONSENT_MANAGER_DEBUG_MODE, CONSENT_MANAGER_DEBUG_MODE);
98     }
99 
getConsentManagerOTADebugMode()100     public boolean getConsentManagerOTADebugMode() {
101         return getDebugFlag(
102                 KEY_CONSENT_MANAGER_OTA_DEBUG_MODE, DEFAULT_CONSENT_MANAGER_OTA_DEBUG_MODE);
103     }
104 
getProtectedAppSignalsCommandsEnabled()105     public boolean getProtectedAppSignalsCommandsEnabled() {
106         return getDebugFlag(
107                 KEY_PROTECTED_APP_SIGNALS_CLI_ENABLED, DEFAULT_PROTECTED_APP_SIGNALS_CLI_ENABLED);
108     }
109 
getAdSelectionCommandsEnabled()110     public boolean getAdSelectionCommandsEnabled() {
111         return getDebugFlag(KEY_AD_SELECTION_CLI_ENABLED, DEFAULT_AD_SELECTION_CLI_ENABLED);
112     }
113 
114     /** Returns whether Consented Debugging is enabled for server auctions. */
getFledgeAuctionServerConsentedDebuggingEnabled()115     public boolean getFledgeAuctionServerConsentedDebuggingEnabled() {
116         return getDebugFlag(
117                 KEY_FLEDGE_AUCTION_SERVER_CONSENTED_DEBUGGING_ENABLED,
118                 DEFAULT_FLEDGE_AUCTION_SERVER_CONSENTED_DEBUGGING_ENABLED);
119     }
120 
121     /** Returns the enabled status for custom audiences CLI feature. */
getFledgeConsentedDebuggingCliEnabledStatus()122     public boolean getFledgeConsentedDebuggingCliEnabledStatus() {
123         return getDebugFlag(
124                 KEY_FLEDGE_IS_CONSENTED_DEBUGGING_CLI_ENABLED,
125                 DEFAULT_FLEDGE_CONSENTED_DEBUGGING_CLI_ENABLED);
126     }
127 
128     /** Returns the enabled status for custom audiences CLI feature. */
getFledgeCustomAudienceCLIEnabledStatus()129     public boolean getFledgeCustomAudienceCLIEnabledStatus() {
130         return getDebugFlag(
131                 KEY_FLEDGE_IS_CUSTOM_AUDIENCE_CLI_ENABLED,
132                 DEFAULT_FLEDGE_CUSTOM_AUDIENCE_CLI_ENABLED);
133     }
134 
135     /** Returns whether sending a broadcast when record topics is completed is enabled. */
getRecordTopicsCompleteBroadcastEnabled()136     public boolean getRecordTopicsCompleteBroadcastEnabled() {
137         return getDebugFlag(
138                 KEY_RECORD_TOPICS_COMPLETE_BROADCAST_ENABLED,
139                 DEFAULT_RECORD_TOPICS_COMPLETE_BROADCAST_ENABLED);
140     }
141 
142     /**
143      * Returns a boolean to indicate if console messages from js isolate should be available in
144      * logcat or not.
145      */
getAdServicesJsIsolateConsoleMessagesInLogsEnabled()146     public boolean getAdServicesJsIsolateConsoleMessagesInLogsEnabled() {
147         return getDebugFlag(
148                 KEY_AD_SERVICES_JS_ISOLATE_CONSOLE_MESSAGES_IN_LOGS_ENABLED,
149                 DEFAULT_JS_ISOLATE_CONSOLE_MESSAGES_IN_LOGS_ENABLED);
150     }
151 }
152