• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_ATTRIBUTION_REPORTING_CLI_ENABLED;
22 import static com.android.adservices.service.DebugFlagsConstants.KEY_CONSENT_MANAGER_DEBUG_MODE;
23 import static com.android.adservices.service.DebugFlagsConstants.KEY_CONSENT_MANAGER_OTA_DEBUG_MODE;
24 import static com.android.adservices.service.DebugFlagsConstants.KEY_CONSENT_NOTIFICATION_ACTIVITY_DEBUG_MODE;
25 import static com.android.adservices.service.DebugFlagsConstants.KEY_CONSENT_NOTIFICATION_DEBUG_MODE;
26 import static com.android.adservices.service.DebugFlagsConstants.KEY_CONSENT_NOTIFIED_DEBUG_MODE;
27 import static com.android.adservices.service.DebugFlagsConstants.KEY_DEVELOPER_SESSION_FEATURE_ENABLED;
28 import static com.android.adservices.service.DebugFlagsConstants.KEY_FLEDGE_AUCTION_SERVER_CONSENTED_DEBUGGING_ENABLED;
29 import static com.android.adservices.service.DebugFlagsConstants.KEY_FLEDGE_BACKGROUND_FETCH_COMPLETE_BROADCAST_ENABLED;
30 import static com.android.adservices.service.DebugFlagsConstants.KEY_FLEDGE_BACKGROUND_KEY_FETCH_COMPLETE_BROADCAST_ENABLED;
31 import static com.android.adservices.service.DebugFlagsConstants.KEY_FLEDGE_IS_CONSENTED_DEBUGGING_CLI_ENABLED;
32 import static com.android.adservices.service.DebugFlagsConstants.KEY_FLEDGE_IS_CUSTOM_AUDIENCE_CLI_ENABLED;
33 import static com.android.adservices.service.DebugFlagsConstants.KEY_FLEDGE_SCHEDULE_CA_COMPLETE_BROADCAST_ENABLED;
34 import static com.android.adservices.service.DebugFlagsConstants.KEY_FORCED_ENCODING_JOB_COMPLETE_BROADCAST_ENABLED;
35 import static com.android.adservices.service.DebugFlagsConstants.KEY_PERIODIC_ENCODING_JOB_COMPLETE_BROADCAST_ENABLED;
36 import static com.android.adservices.service.DebugFlagsConstants.KEY_PROTECTED_APP_SIGNALS_CLI_ENABLED;
37 import static com.android.adservices.service.DebugFlagsConstants.KEY_PROTECTED_APP_SIGNALS_ENCODER_LOGIC_REGISTERED_BROADCAST_ENABLED;
38 import static com.android.adservices.service.DebugFlagsConstants.KEY_RECORD_TOPICS_COMPLETE_BROADCAST_ENABLED;
39 
40 import androidx.annotation.VisibleForTesting;
41 
42 import java.io.PrintWriter;
43 
44 /**
45  * Flags that are only used for development / testing purposes.
46  *
47  * <p>They're never pushed to devices (through `DeviceConfig`) and must be manually set by the
48  * developer (or automatically set by the test), so they're implemented using System Properties.
49  *
50  * <p><b>NOTE: </b> the value of these flags should be such that the behavior they're changing is
51  * not changed or the feature they're guarding is disabled, so usually their default value should be
52  * {@code false}.
53  */
54 public class DebugFlags extends CommonDebugFlags {
55     private static final DebugFlags sInstance = new DebugFlags();
56 
57     /** Default for if FLEDGE app signals CLI is enabled. */
58     @VisibleForTesting static final boolean DEFAULT_PROTECTED_APP_SIGNALS_CLI_ENABLED = false;
59 
60     /** Default for if FLEDGE ad selection CLI is enabled. */
61     @VisibleForTesting static final boolean DEFAULT_AD_SELECTION_CLI_ENABLED = false;
62 
63     /** Default value for fledge auction server consented debug enabled. */
64     @VisibleForTesting
65     static final boolean DEFAULT_FLEDGE_AUCTION_SERVER_CONSENTED_DEBUGGING_ENABLED = false;
66 
67     /** Default value for console messages from js isolate be available in logcat. */
68     @VisibleForTesting
69     static final boolean DEFAULT_JS_ISOLATE_CONSOLE_MESSAGES_IN_LOGS_ENABLED = false;
70 
71     /** Default value for status of custom audiences CLI feature */
72     @VisibleForTesting static final boolean DEFAULT_FLEDGE_CUSTOM_AUDIENCE_CLI_ENABLED = false;
73 
74     /** Default value for status of consented debugging CLI feature */
75     @VisibleForTesting static final boolean DEFAULT_FLEDGE_CONSENTED_DEBUGGING_CLI_ENABLED = false;
76 
77     /** Default value for status of developer mode feature. */
78     @VisibleForTesting static final boolean DEFAULT_DEVELOPER_SESSION_FEATURE_ENABLED = false;
79 
80     /** Default value for sending a broadcast when record topics is completed. */
81     @VisibleForTesting
82     static final boolean DEFAULT_RECORD_TOPICS_COMPLETE_BROADCAST_ENABLED = false;
83 
84     /** Default value for sending a broadcast when schedule custom audience is completed. */
85     @VisibleForTesting static final boolean DEFAULT_SCHEDULE_CA_COMPLETE_BROADCAST_ENABLED = false;
86 
87     /** Default value for sending a broadcast when schedule custom audience is completed. */
88     @VisibleForTesting
89     static final boolean DEFAULT_FLEDGE_BACKGROUND_FETCH_COMPLETE_BROADCAST_ENABLED = false;
90 
91     /** Default value for sending a broadcast when background key fetch is completed. */
92     @VisibleForTesting
93     static final boolean DEFAULT_FLEDGE_BACKGROUND_KEY_FETCH_COMPLETE_BROADCAST_ENABLED = false;
94 
95     /** Default value for sending a broadcast when periodic encoding is completed. */
96     @VisibleForTesting
97     static final boolean DEFAULT_PERIODIC_ENCODING_JOB_COMPLETE_BROADCAST_ENABLED = false;
98 
99     /** Default value for sending a broadcast when forced encoding is completed. */
100     @VisibleForTesting
101     static final boolean DEFAULT_FORCED_ENCODING_COMPLETE_BROADCAST_ENABLED = false;
102 
103     static final boolean CONSENT_NOTIFICATION_DEBUG_MODE = false;
104     static final boolean CONSENT_NOTIFICATION_ACTIVITY_DEBUG_MODE = false;
105     static final boolean CONSENT_NOTIFIED_DEBUG_MODE = false;
106     static final boolean CONSENT_MANAGER_DEBUG_MODE = false;
107     static final boolean DEFAULT_CONSENT_MANAGER_OTA_DEBUG_MODE = false;
108 
109     /** Default for if Protected App Signals sends a broadcast after encoder logic is registered. */
110     static final boolean DEFAULT_PROTECTED_APP_SIGNALS_ENCODER_LOGIC_REGISTERED_BROADCAST_ENABLED =
111             false;
112 
113     static final boolean DEFAULT_ATTRIBUTION_REPORTING_CLI_ENABLED = false;
114 
getInstance()115     public static DebugFlags getInstance() {
116         return sInstance;
117     }
118 
119     // TODO(b/338067482): ideally this class should be final and this constructor private, but it's
120     // extended by FakeDebugFlags, as there's no common interface for it. We should probably
121     // refactor / rename to make it similar to Flags and PhFlags (for example, by creating a
122     // DebugFlags interface and a SystemPropertiesDebugFlagsImpl)
DebugFlags()123     protected DebugFlags() {}
124 
getConsentNotificationDebugMode()125     public boolean getConsentNotificationDebugMode() {
126         return getBoolean(KEY_CONSENT_NOTIFICATION_DEBUG_MODE, CONSENT_NOTIFICATION_DEBUG_MODE);
127     }
128 
129     /** Returns whether to suppress consent notified state. */
getConsentNotifiedDebugMode()130     public boolean getConsentNotifiedDebugMode() {
131         return getBoolean(KEY_CONSENT_NOTIFIED_DEBUG_MODE, CONSENT_NOTIFIED_DEBUG_MODE);
132     }
133 
134     /** Returns the consent notification activity debug mode. */
getConsentNotificationActivityDebugMode()135     public boolean getConsentNotificationActivityDebugMode() {
136         return getBoolean(
137                 KEY_CONSENT_NOTIFICATION_ACTIVITY_DEBUG_MODE,
138                 CONSENT_NOTIFICATION_ACTIVITY_DEBUG_MODE);
139     }
140 
getConsentManagerDebugMode()141     public boolean getConsentManagerDebugMode() {
142         return getBoolean(KEY_CONSENT_MANAGER_DEBUG_MODE, CONSENT_MANAGER_DEBUG_MODE);
143     }
144 
145     /** When enabled, the device is treated as OTA device. */
getConsentManagerOTADebugMode()146     public boolean getConsentManagerOTADebugMode() {
147         return getBoolean(
148                 KEY_CONSENT_MANAGER_OTA_DEBUG_MODE, DEFAULT_CONSENT_MANAGER_OTA_DEBUG_MODE);
149     }
150 
getProtectedAppSignalsCommandsEnabled()151     public boolean getProtectedAppSignalsCommandsEnabled() {
152         return getBoolean(
153                 KEY_PROTECTED_APP_SIGNALS_CLI_ENABLED, DEFAULT_PROTECTED_APP_SIGNALS_CLI_ENABLED);
154     }
155 
getProtectedAppSignalsEncoderLogicRegisteredBroadcastEnabled()156     public boolean getProtectedAppSignalsEncoderLogicRegisteredBroadcastEnabled() {
157         return getBoolean(
158                 KEY_PROTECTED_APP_SIGNALS_ENCODER_LOGIC_REGISTERED_BROADCAST_ENABLED,
159                 DEFAULT_PROTECTED_APP_SIGNALS_ENCODER_LOGIC_REGISTERED_BROADCAST_ENABLED);
160     }
161 
getAdSelectionCommandsEnabled()162     public boolean getAdSelectionCommandsEnabled() {
163         return getBoolean(KEY_AD_SELECTION_CLI_ENABLED, DEFAULT_AD_SELECTION_CLI_ENABLED);
164     }
165 
166     /** Returns whether developer mode feature is enabled. */
getDeveloperSessionFeatureEnabled()167     public boolean getDeveloperSessionFeatureEnabled() {
168         return getBoolean(
169                 KEY_DEVELOPER_SESSION_FEATURE_ENABLED, DEFAULT_DEVELOPER_SESSION_FEATURE_ENABLED);
170     }
171 
172     /** Returns whether Consented Debugging is enabled for server auctions. */
getFledgeAuctionServerConsentedDebuggingEnabled()173     public boolean getFledgeAuctionServerConsentedDebuggingEnabled() {
174         return getBoolean(
175                 KEY_FLEDGE_AUCTION_SERVER_CONSENTED_DEBUGGING_ENABLED,
176                 DEFAULT_FLEDGE_AUCTION_SERVER_CONSENTED_DEBUGGING_ENABLED);
177     }
178 
179     /** Returns the enabled status for custom audiences CLI feature. */
getFledgeConsentedDebuggingCliEnabledStatus()180     public boolean getFledgeConsentedDebuggingCliEnabledStatus() {
181         return getBoolean(
182                 KEY_FLEDGE_IS_CONSENTED_DEBUGGING_CLI_ENABLED,
183                 DEFAULT_FLEDGE_CONSENTED_DEBUGGING_CLI_ENABLED);
184     }
185 
186     /** Returns the enabled status for custom audiences CLI feature. */
getFledgeCustomAudienceCLIEnabledStatus()187     public boolean getFledgeCustomAudienceCLIEnabledStatus() {
188         return getBoolean(
189                 KEY_FLEDGE_IS_CUSTOM_AUDIENCE_CLI_ENABLED,
190                 DEFAULT_FLEDGE_CUSTOM_AUDIENCE_CLI_ENABLED);
191     }
192 
193     /** Returns whether sending a broadcast when record topics is completed is enabled. */
getRecordTopicsCompleteBroadcastEnabled()194     public boolean getRecordTopicsCompleteBroadcastEnabled() {
195         return getBoolean(
196                 KEY_RECORD_TOPICS_COMPLETE_BROADCAST_ENABLED,
197                 DEFAULT_RECORD_TOPICS_COMPLETE_BROADCAST_ENABLED);
198     }
199 
200     /** Returns whether sending a broadcast when schedule CA is completed is enabled. */
getFledgeScheduleCACompleteBroadcastEnabled()201     public boolean getFledgeScheduleCACompleteBroadcastEnabled() {
202         return getBoolean(
203                 KEY_FLEDGE_SCHEDULE_CA_COMPLETE_BROADCAST_ENABLED,
204                 DEFAULT_SCHEDULE_CA_COMPLETE_BROADCAST_ENABLED);
205     }
206 
207     /** Returns whether sending a broadcast when background fetch job is completed is enabled. */
getFledgeBackgroundFetchCompleteBroadcastEnabled()208     public boolean getFledgeBackgroundFetchCompleteBroadcastEnabled() {
209         return getBoolean(
210                 KEY_FLEDGE_BACKGROUND_FETCH_COMPLETE_BROADCAST_ENABLED,
211                 DEFAULT_FLEDGE_BACKGROUND_FETCH_COMPLETE_BROADCAST_ENABLED);
212     }
213 
214     /** Returns whether sending a broadcast when Background Key Fetch completed is enabled. */
getFledgeBackgroundKeyFetchCompleteBroadcastEnabled()215     public boolean getFledgeBackgroundKeyFetchCompleteBroadcastEnabled() {
216         return getBoolean(
217                 KEY_FLEDGE_BACKGROUND_KEY_FETCH_COMPLETE_BROADCAST_ENABLED,
218                 DEFAULT_FLEDGE_BACKGROUND_KEY_FETCH_COMPLETE_BROADCAST_ENABLED);
219     }
220 
221     /** Returns whether sending a broadcast when Periodic encoding job is completed is enabled. */
getPeriodicEncodingJobCompleteBroadcastEnabled()222     public boolean getPeriodicEncodingJobCompleteBroadcastEnabled() {
223         return getBoolean(
224                 KEY_PERIODIC_ENCODING_JOB_COMPLETE_BROADCAST_ENABLED,
225                 DEFAULT_PERIODIC_ENCODING_JOB_COMPLETE_BROADCAST_ENABLED);
226     }
227 
228     /** Returns whether sending a broadcast when forced encoding job is completed is enabled. */
getForcedEncodingJobCompleteBroadcastEnabled()229     public boolean getForcedEncodingJobCompleteBroadcastEnabled() {
230         return getBoolean(
231                 KEY_FORCED_ENCODING_JOB_COMPLETE_BROADCAST_ENABLED,
232                 DEFAULT_FORCED_ENCODING_COMPLETE_BROADCAST_ENABLED);
233     }
234 
235     /**
236      * Returns a boolean to indicate if console messages from js isolate should be available in
237      * logcat or not.
238      */
getAdServicesJsIsolateConsoleMessagesInLogsEnabled()239     public boolean getAdServicesJsIsolateConsoleMessagesInLogsEnabled() {
240         return getBoolean(
241                 KEY_AD_SERVICES_JS_ISOLATE_CONSOLE_MESSAGES_IN_LOGS_ENABLED,
242                 DEFAULT_JS_ISOLATE_CONSOLE_MESSAGES_IN_LOGS_ENABLED);
243     }
244 
getAttributionReportingCommandsEnabled()245     public boolean getAttributionReportingCommandsEnabled() {
246         return getBoolean(
247                 KEY_ATTRIBUTION_REPORTING_CLI_ENABLED, DEFAULT_ATTRIBUTION_REPORTING_CLI_ENABLED);
248     }
249 
250     @Override
dump(PrintWriter pw)251     public void dump(PrintWriter pw) {
252         super.dump(pw);
253 
254         dump(pw, KEY_CONSENT_NOTIFICATION_DEBUG_MODE, getConsentNotificationDebugMode());
255         dump(pw, KEY_CONSENT_NOTIFIED_DEBUG_MODE, getConsentNotifiedDebugMode());
256         dump(
257                 pw,
258                 KEY_CONSENT_NOTIFICATION_ACTIVITY_DEBUG_MODE,
259                 getConsentNotificationActivityDebugMode());
260         dump(pw, KEY_CONSENT_MANAGER_DEBUG_MODE, getConsentManagerDebugMode());
261         dump(pw, KEY_CONSENT_MANAGER_OTA_DEBUG_MODE, getConsentManagerOTADebugMode());
262         dump(pw, KEY_PROTECTED_APP_SIGNALS_CLI_ENABLED, getProtectedAppSignalsCommandsEnabled());
263         dump(
264                 pw,
265                 KEY_PROTECTED_APP_SIGNALS_ENCODER_LOGIC_REGISTERED_BROADCAST_ENABLED,
266                 getProtectedAppSignalsEncoderLogicRegisteredBroadcastEnabled());
267         dump(pw, KEY_AD_SELECTION_CLI_ENABLED, getAdSelectionCommandsEnabled());
268         dump(
269                 pw,
270                 KEY_FLEDGE_AUCTION_SERVER_CONSENTED_DEBUGGING_ENABLED,
271                 getFledgeAuctionServerConsentedDebuggingEnabled());
272         dump(
273                 pw,
274                 KEY_FLEDGE_IS_CONSENTED_DEBUGGING_CLI_ENABLED,
275                 getFledgeConsentedDebuggingCliEnabledStatus());
276         dump(
277                 pw,
278                 KEY_FLEDGE_IS_CUSTOM_AUDIENCE_CLI_ENABLED,
279                 getFledgeCustomAudienceCLIEnabledStatus());
280         dump(
281                 pw,
282                 KEY_RECORD_TOPICS_COMPLETE_BROADCAST_ENABLED,
283                 getRecordTopicsCompleteBroadcastEnabled());
284         dump(
285                 pw,
286                 KEY_FLEDGE_SCHEDULE_CA_COMPLETE_BROADCAST_ENABLED,
287                 getFledgeScheduleCACompleteBroadcastEnabled());
288         dump(
289                 pw,
290                 KEY_AD_SERVICES_JS_ISOLATE_CONSOLE_MESSAGES_IN_LOGS_ENABLED,
291                 getAdServicesJsIsolateConsoleMessagesInLogsEnabled());
292         dump(
293                 pw,
294                 KEY_FLEDGE_BACKGROUND_FETCH_COMPLETE_BROADCAST_ENABLED,
295                 getFledgeBackgroundFetchCompleteBroadcastEnabled());
296         dump(
297                 pw,
298                 KEY_FLEDGE_BACKGROUND_KEY_FETCH_COMPLETE_BROADCAST_ENABLED,
299                 getFledgeBackgroundKeyFetchCompleteBroadcastEnabled());
300         dump(
301                 pw,
302                 KEY_PERIODIC_ENCODING_JOB_COMPLETE_BROADCAST_ENABLED,
303                 getPeriodicEncodingJobCompleteBroadcastEnabled());
304         dump(
305                 pw,
306                 KEY_DEVELOPER_SESSION_FEATURE_ENABLED,
307                 getDeveloperSessionFeatureEnabled());
308         dump(
309                 pw,
310                 KEY_FORCED_ENCODING_JOB_COMPLETE_BROADCAST_ENABLED,
311                 getForcedEncodingJobCompleteBroadcastEnabled());
312         dump(pw, KEY_ATTRIBUTION_REPORTING_CLI_ENABLED, getAttributionReportingCommandsEnabled());
313     }
314 }
315