1 /*
2  * Copyright (C) 2018 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.server.am;
18 
19 import static android.provider.DeviceConfig.NAMESPACE_ACTIVITY_MANAGER_NATIVE_BOOT;
20 
21 import android.annotation.IntDef;
22 import android.annotation.NonNull;
23 import android.app.ActivityManager;
24 import android.compat.annotation.ChangeId;
25 import android.compat.annotation.EnabledAfter;
26 import android.compat.annotation.Overridable;
27 import android.content.ContentResolver;
28 import android.database.ContentObserver;
29 import android.os.Build;
30 import android.os.Handler;
31 import android.os.HandlerExecutor;
32 import android.os.SystemProperties;
33 import android.provider.DeviceConfig;
34 import android.provider.Settings;
35 import android.util.IndentingPrintWriter;
36 import android.util.KeyValueListParser;
37 import android.util.Slog;
38 import android.util.TimeUtils;
39 
40 import dalvik.annotation.optimization.NeverCompile;
41 
42 import java.lang.annotation.Retention;
43 import java.lang.annotation.RetentionPolicy;
44 
45 /**
46  * Tunable parameters for broadcast dispatch policy
47  */
48 public class BroadcastConstants {
49     private static final String TAG = "BroadcastConstants";
50 
51     // TODO: migrate remaining constants to be loaded from DeviceConfig
52     // TODO: migrate fg/bg values into single constants instance
53 
54     // Value element names within the Settings record
55     static final String KEY_TIMEOUT = "bcast_timeout";
56     static final String KEY_ALLOW_BG_ACTIVITY_START_TIMEOUT =
57             "bcast_allow_bg_activity_start_timeout";
58 
59     // All time intervals are in milliseconds
60     private static final long DEFAULT_TIMEOUT = 10_000 * Build.HW_TIMEOUT_MULTIPLIER;
61     private static final long DEFAULT_ALLOW_BG_ACTIVITY_START_TIMEOUT =
62             10_000 * Build.HW_TIMEOUT_MULTIPLIER;
63 
64     /**
65      * Defer LOCKED_BOOT_COMPLETED and BOOT_COMPLETED broadcasts until the first time any process in
66      * the UID is started.
67      */
68     @ChangeId
69     @EnabledAfter(targetSdkVersion = android.os.Build.VERSION_CODES.S_V2)
70     @Overridable
71     static final long DEFER_BOOT_COMPLETED_BROADCAST_CHANGE_ID = 203704822L;
72 
73     /**
74      * Do not defer LOCKED_BOOT_COMPLETED and BOOT_COMPLETED broadcasts.
75      */
76     public static final int DEFER_BOOT_COMPLETED_BROADCAST_NONE = 0;
77     /**
78      * Defer all LOCKED_BOOT_COMPLETED and BOOT_COMPLETED broadcasts.
79      */
80     public static final int DEFER_BOOT_COMPLETED_BROADCAST_ALL = 1 << 0;
81     /**
82      * Defer LOCKED_BOOT_COMPLETED and BOOT_COMPLETED broadcasts if app is background restricted.
83      */
84     public static final int DEFER_BOOT_COMPLETED_BROADCAST_BACKGROUND_RESTRICTED_ONLY = 1 << 1;
85     /**
86      * Defer LOCKED_BOOT_COMPLETED and BOOT_COMPLETED broadcasts if app's targetSdkVersion is T
87      * and above.
88      */
89     public static final int DEFER_BOOT_COMPLETED_BROADCAST_TARGET_T_ONLY = 1 << 2;
90 
91     /**
92      * The list of DEFER_BOOT_COMPLETED_BROADCAST types.
93      * If multiple flags are selected, all conditions must be met to defer the broadcast.
94      * @hide
95      */
96     @IntDef(flag = true, prefix = { "DEFER_BOOT_COMPLETED_BROADCAST_" }, value = {
97             DEFER_BOOT_COMPLETED_BROADCAST_NONE,
98             DEFER_BOOT_COMPLETED_BROADCAST_ALL,
99             DEFER_BOOT_COMPLETED_BROADCAST_BACKGROUND_RESTRICTED_ONLY,
100             DEFER_BOOT_COMPLETED_BROADCAST_TARGET_T_ONLY,
101     })
102     @Retention(RetentionPolicy.SOURCE)
103     public @interface DeferBootCompletedBroadcastType {}
104 
105     // All time constants are in milliseconds
106 
107     // Timeout period for this broadcast queue
108     public long TIMEOUT = DEFAULT_TIMEOUT;
109     // For a receiver that has been allowed to start background activities, how long after it
110     // started its process can start a background activity.
111     public long ALLOW_BG_ACTIVITY_START_TIMEOUT = DEFAULT_ALLOW_BG_ACTIVITY_START_TIMEOUT;
112 
113     /**
114      * For {@link BroadcastQueueModernImpl}: Maximum dispatch parallelism
115      * that we'll tolerate for ordinary broadcast dispatch.
116      */
117     public int MAX_RUNNING_PROCESS_QUEUES = DEFAULT_MAX_RUNNING_PROCESS_QUEUES;
118     private static final String KEY_MAX_RUNNING_PROCESS_QUEUES = "bcast_max_running_process_queues";
119     private static final int DEFAULT_MAX_RUNNING_PROCESS_QUEUES =
120             ActivityManager.isLowRamDeviceStatic() ? 2 : 4;
121 
122     /**
123      * For {@link BroadcastQueueModernImpl}: Additional running process queue parallelism beyond
124      * {@link #MAX_RUNNING_PROCESS_QUEUES} for dispatch of "urgent" broadcasts.
125      */
126     public int EXTRA_RUNNING_URGENT_PROCESS_QUEUES = DEFAULT_EXTRA_RUNNING_URGENT_PROCESS_QUEUES;
127     private static final String KEY_EXTRA_RUNNING_URGENT_PROCESS_QUEUES =
128             "bcast_extra_running_urgent_process_queues";
129     private static final int DEFAULT_EXTRA_RUNNING_URGENT_PROCESS_QUEUES = 1;
130 
131     /**
132      * For {@link BroadcastQueueModernImpl}: Maximum number of consecutive urgent
133      * broadcast dispatches allowed before letting broadcasts in lower priority queue
134      * to be scheduled in order to avoid starvation.
135      */
136     public int MAX_CONSECUTIVE_URGENT_DISPATCHES = DEFAULT_MAX_CONSECUTIVE_URGENT_DISPATCHES;
137     private static final String KEY_MAX_CONSECUTIVE_URGENT_DISPATCHES =
138             "bcast_max_consecutive_urgent_dispatches";
139     private static final int DEFAULT_MAX_CONSECUTIVE_URGENT_DISPATCHES = 3;
140 
141     /**
142      * For {@link BroadcastQueueModernImpl}: Maximum number of consecutive normal
143      * broadcast dispatches allowed before letting broadcasts in lower priority queue
144      * to be scheduled in order to avoid starvation.
145      */
146     public int MAX_CONSECUTIVE_NORMAL_DISPATCHES = DEFAULT_MAX_CONSECUTIVE_NORMAL_DISPATCHES;
147     private static final String KEY_MAX_CONSECUTIVE_NORMAL_DISPATCHES =
148             "bcast_max_consecutive_normal_dispatches";
149     private static final int DEFAULT_MAX_CONSECUTIVE_NORMAL_DISPATCHES = 10;
150 
151     /**
152      * For {@link BroadcastQueueModernImpl}: Maximum number of active broadcasts
153      * to dispatch to a "running" process queue before we retire them back to
154      * being "runnable" to give other processes a chance to run.
155      */
156     public int MAX_RUNNING_ACTIVE_BROADCASTS = DEFAULT_MAX_RUNNING_ACTIVE_BROADCASTS;
157     private static final String KEY_MAX_RUNNING_ACTIVE_BROADCASTS =
158             "bcast_max_running_active_broadcasts";
159     private static final int DEFAULT_MAX_RUNNING_ACTIVE_BROADCASTS =
160             ActivityManager.isLowRamDeviceStatic() ? 8 : 16;
161 
162     /**
163      * For {@link BroadcastQueueModernImpl}: Maximum number of active "blocking" broadcasts
164      * to dispatch to a "running" System process queue before we retire them back to
165      * being "runnable" to give other processes a chance to run. Here "blocking" refers to
166      * whether or not we are going to block on the finishReceiver() to be called before moving
167      * to the next broadcast.
168      */
169     public int MAX_CORE_RUNNING_BLOCKING_BROADCASTS = DEFAULT_MAX_CORE_RUNNING_BLOCKING_BROADCASTS;
170     private static final String KEY_CORE_MAX_RUNNING_BLOCKING_BROADCASTS =
171             "bcast_max_core_running_blocking_broadcasts";
172     private static final int DEFAULT_MAX_CORE_RUNNING_BLOCKING_BROADCASTS =
173             ActivityManager.isLowRamDeviceStatic() ? 8 : 16;
174 
175     /**
176      * For {@link BroadcastQueueModernImpl}: Maximum number of active non-"blocking" broadcasts
177      * to dispatch to a "running" System process queue before we retire them back to
178      * being "runnable" to give other processes a chance to run. Here "blocking" refers to
179      * whether or not we are going to block on the finishReceiver() to be called before moving
180      * to the next broadcast.
181      */
182     public int MAX_CORE_RUNNING_NON_BLOCKING_BROADCASTS =
183             DEFAULT_MAX_CORE_RUNNING_NON_BLOCKING_BROADCASTS;
184     private static final String KEY_CORE_MAX_RUNNING_NON_BLOCKING_BROADCASTS =
185             "bcast_max_core_running_non_blocking_broadcasts";
186     private static final int DEFAULT_MAX_CORE_RUNNING_NON_BLOCKING_BROADCASTS =
187             ActivityManager.isLowRamDeviceStatic() ? 32 : 64;
188 
189     /**
190      * For {@link BroadcastQueueModernImpl}: Maximum number of pending
191      * broadcasts to hold for a process before we ignore any delays that policy
192      * might have applied to that process.
193      */
194     public int MAX_PENDING_BROADCASTS = DEFAULT_MAX_PENDING_BROADCASTS;
195     private static final String KEY_MAX_PENDING_BROADCASTS = "bcast_max_pending_broadcasts";
196     private static final int DEFAULT_MAX_PENDING_BROADCASTS =
197             ActivityManager.isLowRamDeviceStatic() ? 128 : 256;
198 
199     /**
200      * For {@link BroadcastQueueModernImpl}: Delay to apply to normal
201      * broadcasts, giving a chance for debouncing of rapidly changing events.
202      */
203     public long DELAY_NORMAL_MILLIS = DEFAULT_DELAY_NORMAL_MILLIS;
204     private static final String KEY_DELAY_NORMAL_MILLIS = "bcast_delay_normal_millis";
205     private static final long DEFAULT_DELAY_NORMAL_MILLIS = +500;
206 
207     /**
208      * For {@link BroadcastQueueModernImpl}: Delay to apply to broadcasts
209      * targeting cached applications.
210      */
211     public long DELAY_CACHED_MILLIS = DEFAULT_DELAY_CACHED_MILLIS;
212     private static final String KEY_DELAY_CACHED_MILLIS = "bcast_delay_cached_millis";
213     private static final long DEFAULT_DELAY_CACHED_MILLIS = +120_000;
214 
215     /**
216      * For {@link BroadcastQueueModernImpl}: Delay to apply to urgent
217      * broadcasts, typically a negative value to indicate they should be
218      * executed before most other pending broadcasts.
219      */
220     public long DELAY_URGENT_MILLIS = DEFAULT_DELAY_URGENT_MILLIS;
221     private static final String KEY_DELAY_URGENT_MILLIS = "bcast_delay_urgent_millis";
222     private static final long DEFAULT_DELAY_URGENT_MILLIS = -120_000;
223 
224     /**
225      * For {@link BroadcastQueueModernImpl}: Delay to apply to broadcasts to
226      * foreground processes, typically a negative value to indicate they should be
227      * executed before most other pending broadcasts.
228      */
229     public long DELAY_FOREGROUND_PROC_MILLIS = DEFAULT_DELAY_FOREGROUND_PROC_MILLIS;
230     private static final String KEY_DELAY_FOREGROUND_PROC_MILLIS =
231             "bcast_delay_foreground_proc_millis";
232     private static final long DEFAULT_DELAY_FOREGROUND_PROC_MILLIS = -120_000;
233 
234     /**
235      * For {@link BroadcastQueueModernImpl}: Delay to apply to broadcasts to
236      * persistent processes, typically a negative value to indicate they should be
237      * executed before most other pending broadcasts.
238      */
239     public long DELAY_PERSISTENT_PROC_MILLIS = DEFAULT_DELAY_FOREGROUND_PROC_MILLIS;
240     private static final String KEY_DELAY_PERSISTENT_PROC_MILLIS =
241             "bcast_delay_persistent_proc_millis";
242     private static final long DEFAULT_DELAY_PERSISTENT_PROC_MILLIS = -120_000;
243 
244     /**
245      * For {@link BroadcastQueueModernImpl}: Maximum number of complete
246      * historical broadcasts to retain for debugging purposes.
247      */
248     public int MAX_HISTORY_COMPLETE_SIZE = DEFAULT_MAX_HISTORY_COMPLETE_SIZE;
249     private static final String KEY_MAX_HISTORY_COMPLETE_SIZE = "bcast_max_history_complete_size";
250     private static final int DEFAULT_MAX_HISTORY_COMPLETE_SIZE =
251             ActivityManager.isLowRamDeviceStatic() ? 64 : 256;
252 
253     /**
254      * For {@link BroadcastQueueModernImpl}: Maximum number of summarized
255      * historical broadcasts to retain for debugging purposes.
256      */
257     public int MAX_HISTORY_SUMMARY_SIZE = DEFAULT_MAX_HISTORY_SUMMARY_SIZE;
258     private static final String KEY_MAX_HISTORY_SUMMARY_SIZE = "bcast_max_history_summary_size";
259     private static final int DEFAULT_MAX_HISTORY_SUMMARY_SIZE =
260             ActivityManager.isLowRamDeviceStatic() ? 256 : 1024;
261 
262     /**
263      * For {@link BroadcastRecord}: Default to treating all broadcasts sent by
264      * the system as be {@link android.app.BroadcastOptions#DEFERRAL_POLICY_UNTIL_ACTIVE}.
265      */
266     public boolean CORE_DEFER_UNTIL_ACTIVE = DEFAULT_CORE_DEFER_UNTIL_ACTIVE;
267     private static final String KEY_CORE_DEFER_UNTIL_ACTIVE = "bcast_core_defer_until_active";
268     private static final boolean DEFAULT_CORE_DEFER_UNTIL_ACTIVE = true;
269 
270     /**
271      * For {@link BroadcastQueueModernImpl}: How frequently we should check for the pending
272      * cold start validity.
273      */
274     public long PENDING_COLD_START_CHECK_INTERVAL_MILLIS =
275             DEFAULT_PENDING_COLD_START_CHECK_INTERVAL_MILLIS;
276     private static final String KEY_PENDING_COLD_START_CHECK_INTERVAL_MILLIS =
277             "pending_cold_start_check_interval_millis";
278     private static final long DEFAULT_PENDING_COLD_START_CHECK_INTERVAL_MILLIS = 30_000;
279 
280     /**
281      * For {@link BroadcastQueueModernImpl}: Maximum number of outgoing broadcasts from a
282      * freezable process that will be allowed before killing the process.
283      */
284     public int MAX_FROZEN_OUTGOING_BROADCASTS = DEFAULT_MAX_FROZEN_OUTGOING_BROADCASTS;
285     private static final String KEY_MAX_FROZEN_OUTGOING_BROADCASTS =
286             "max_frozen_outgoing_broadcasts";
287     private static final int DEFAULT_MAX_FROZEN_OUTGOING_BROADCASTS = 32;
288 
289     // Settings override tracking for this instance
290     private String mSettingsKey;
291     private SettingsObserver mSettingsObserver;
292     private ContentResolver mResolver;
293     private final KeyValueListParser mParser = new KeyValueListParser(',');
294 
295     class SettingsObserver extends ContentObserver {
SettingsObserver(Handler handler)296         SettingsObserver(Handler handler) {
297             super(handler);
298         }
299 
300         @Override
onChange(boolean selfChange)301         public void onChange(boolean selfChange) {
302             updateSettingsConstants();
303         }
304     }
305 
306     // A given constants instance is configured to observe specific keys from which
307     // that instance's values are drawn.
BroadcastConstants(String settingsKey)308     public BroadcastConstants(String settingsKey) {
309         mSettingsKey = settingsKey;
310 
311         // Load initial values at least once before we start observing below
312         updateDeviceConfigConstants();
313     }
314 
315     /**
316      * Spin up the observer lazily, since it can only happen once the settings provider
317      * has been brought into service
318      */
startObserving(Handler handler, ContentResolver resolver)319     public void startObserving(Handler handler, ContentResolver resolver) {
320         mResolver = resolver;
321 
322         mSettingsObserver = new SettingsObserver(handler);
323         mResolver.registerContentObserver(Settings.Global.getUriFor(mSettingsKey),
324                 false, mSettingsObserver);
325         updateSettingsConstants();
326 
327         DeviceConfig.addOnPropertiesChangedListener(NAMESPACE_ACTIVITY_MANAGER_NATIVE_BOOT,
328                 new HandlerExecutor(handler), this::updateDeviceConfigConstants);
329         updateDeviceConfigConstants();
330     }
331 
getMaxRunningQueues()332     public int getMaxRunningQueues() {
333         return MAX_RUNNING_PROCESS_QUEUES + EXTRA_RUNNING_URGENT_PROCESS_QUEUES;
334     }
335 
updateSettingsConstants()336     private void updateSettingsConstants() {
337         synchronized (this) {
338             try {
339                 mParser.setString(Settings.Global.getString(mResolver, mSettingsKey));
340             } catch (IllegalArgumentException e) {
341                 Slog.e(TAG, "Bad broadcast settings in key '" + mSettingsKey + "'", e);
342                 return;
343             }
344 
345             // Unspecified fields retain their current value rather than revert to default
346             TIMEOUT = mParser.getLong(KEY_TIMEOUT, TIMEOUT);
347             ALLOW_BG_ACTIVITY_START_TIMEOUT = mParser.getLong(KEY_ALLOW_BG_ACTIVITY_START_TIMEOUT,
348                     ALLOW_BG_ACTIVITY_START_TIMEOUT);
349         }
350     }
351 
352     /**
353      * Return the {@link SystemProperties} name for the given key in our
354      * {@link DeviceConfig} namespace.
355      */
propertyFor(@onNull String key)356     private static @NonNull String propertyFor(@NonNull String key) {
357         return "persist.device_config." + NAMESPACE_ACTIVITY_MANAGER_NATIVE_BOOT + "." + key;
358     }
359 
360     /**
361      * Return the {@link SystemProperties} name for the given key in our
362      * {@link DeviceConfig} namespace, but with a different prefix that can be
363      * used to locally override the {@link DeviceConfig} value.
364      */
propertyOverrideFor(@onNull String key)365     private static @NonNull String propertyOverrideFor(@NonNull String key) {
366         return "persist.sys." + NAMESPACE_ACTIVITY_MANAGER_NATIVE_BOOT + "." + key;
367     }
368 
getDeviceConfigBoolean(@onNull String key, boolean def)369     static boolean getDeviceConfigBoolean(@NonNull String key, boolean def) {
370         return SystemProperties.getBoolean(propertyOverrideFor(key),
371                 SystemProperties.getBoolean(propertyFor(key), def));
372     }
373 
getDeviceConfigInt(@onNull String key, int def)374     private int getDeviceConfigInt(@NonNull String key, int def) {
375         return SystemProperties.getInt(propertyOverrideFor(key),
376                 SystemProperties.getInt(propertyFor(key), def));
377     }
378 
getDeviceConfigLong(@onNull String key, long def)379     private long getDeviceConfigLong(@NonNull String key, long def) {
380         return SystemProperties.getLong(propertyOverrideFor(key),
381                 SystemProperties.getLong(propertyFor(key), def));
382     }
383 
updateDeviceConfigConstants(@onNull DeviceConfig.Properties properties)384     private void updateDeviceConfigConstants(@NonNull DeviceConfig.Properties properties) {
385         updateDeviceConfigConstants();
386     }
387 
388     /**
389      * Since our values are stored in a "native boot" namespace, we load them
390      * directly from the system properties.
391      */
updateDeviceConfigConstants()392     private void updateDeviceConfigConstants() {
393         synchronized (this) {
394             MAX_RUNNING_PROCESS_QUEUES = getDeviceConfigInt(KEY_MAX_RUNNING_PROCESS_QUEUES,
395                     DEFAULT_MAX_RUNNING_PROCESS_QUEUES);
396             EXTRA_RUNNING_URGENT_PROCESS_QUEUES = getDeviceConfigInt(
397                     KEY_EXTRA_RUNNING_URGENT_PROCESS_QUEUES,
398                     DEFAULT_EXTRA_RUNNING_URGENT_PROCESS_QUEUES);
399             MAX_CONSECUTIVE_URGENT_DISPATCHES = getDeviceConfigInt(
400                     KEY_MAX_CONSECUTIVE_URGENT_DISPATCHES,
401                     DEFAULT_MAX_CONSECUTIVE_URGENT_DISPATCHES);
402             MAX_CONSECUTIVE_NORMAL_DISPATCHES = getDeviceConfigInt(
403                     KEY_MAX_CONSECUTIVE_NORMAL_DISPATCHES,
404                     DEFAULT_MAX_CONSECUTIVE_NORMAL_DISPATCHES);
405             MAX_RUNNING_ACTIVE_BROADCASTS = getDeviceConfigInt(KEY_MAX_RUNNING_ACTIVE_BROADCASTS,
406                     DEFAULT_MAX_RUNNING_ACTIVE_BROADCASTS);
407             MAX_CORE_RUNNING_BLOCKING_BROADCASTS = getDeviceConfigInt(
408                     KEY_CORE_MAX_RUNNING_BLOCKING_BROADCASTS,
409                     DEFAULT_MAX_CORE_RUNNING_BLOCKING_BROADCASTS);
410             MAX_CORE_RUNNING_NON_BLOCKING_BROADCASTS = getDeviceConfigInt(
411                     KEY_CORE_MAX_RUNNING_NON_BLOCKING_BROADCASTS,
412                     DEFAULT_MAX_CORE_RUNNING_NON_BLOCKING_BROADCASTS);
413             MAX_PENDING_BROADCASTS = getDeviceConfigInt(KEY_MAX_PENDING_BROADCASTS,
414                     DEFAULT_MAX_PENDING_BROADCASTS);
415             DELAY_NORMAL_MILLIS = getDeviceConfigLong(KEY_DELAY_NORMAL_MILLIS,
416                     DEFAULT_DELAY_NORMAL_MILLIS);
417             DELAY_CACHED_MILLIS = getDeviceConfigLong(KEY_DELAY_CACHED_MILLIS,
418                     DEFAULT_DELAY_CACHED_MILLIS);
419             DELAY_URGENT_MILLIS = getDeviceConfigLong(KEY_DELAY_URGENT_MILLIS,
420                     DEFAULT_DELAY_URGENT_MILLIS);
421             DELAY_FOREGROUND_PROC_MILLIS = getDeviceConfigLong(KEY_DELAY_FOREGROUND_PROC_MILLIS,
422                     DEFAULT_DELAY_FOREGROUND_PROC_MILLIS);
423             DELAY_PERSISTENT_PROC_MILLIS = getDeviceConfigLong(KEY_DELAY_PERSISTENT_PROC_MILLIS,
424                     DEFAULT_DELAY_PERSISTENT_PROC_MILLIS);
425             MAX_HISTORY_COMPLETE_SIZE = getDeviceConfigInt(KEY_MAX_HISTORY_COMPLETE_SIZE,
426                     DEFAULT_MAX_HISTORY_COMPLETE_SIZE);
427             MAX_HISTORY_SUMMARY_SIZE = getDeviceConfigInt(KEY_MAX_HISTORY_SUMMARY_SIZE,
428                     DEFAULT_MAX_HISTORY_SUMMARY_SIZE);
429             CORE_DEFER_UNTIL_ACTIVE = getDeviceConfigBoolean(KEY_CORE_DEFER_UNTIL_ACTIVE,
430                     DEFAULT_CORE_DEFER_UNTIL_ACTIVE);
431             PENDING_COLD_START_CHECK_INTERVAL_MILLIS = getDeviceConfigLong(
432                     KEY_PENDING_COLD_START_CHECK_INTERVAL_MILLIS,
433                     DEFAULT_PENDING_COLD_START_CHECK_INTERVAL_MILLIS);
434             MAX_FROZEN_OUTGOING_BROADCASTS = getDeviceConfigInt(
435                     KEY_MAX_FROZEN_OUTGOING_BROADCASTS,
436                     DEFAULT_MAX_FROZEN_OUTGOING_BROADCASTS);
437         }
438 
439         // TODO: migrate BroadcastRecord to accept a BroadcastConstants
440         BroadcastRecord.CORE_DEFER_UNTIL_ACTIVE = CORE_DEFER_UNTIL_ACTIVE;
441     }
442 
443     /**
444      * Standard dumpsys support; invoked from BroadcastQueue dump
445      */
446     @NeverCompile
dump(@onNull IndentingPrintWriter pw)447     public void dump(@NonNull IndentingPrintWriter pw) {
448         synchronized (this) {
449             pw.print("Broadcast parameters (key=");
450             pw.print(mSettingsKey);
451             pw.print(", observing=");
452             pw.print(mSettingsObserver != null);
453             pw.println("):");
454             pw.increaseIndent();
455             pw.print(KEY_TIMEOUT, TimeUtils.formatDuration(TIMEOUT)).println();
456             pw.print(KEY_ALLOW_BG_ACTIVITY_START_TIMEOUT,
457                     TimeUtils.formatDuration(ALLOW_BG_ACTIVITY_START_TIMEOUT)).println();
458             pw.decreaseIndent();
459             pw.println();
460 
461             pw.print("Broadcast parameters (namespace=");
462             pw.print(NAMESPACE_ACTIVITY_MANAGER_NATIVE_BOOT);
463             pw.println("):");
464             pw.increaseIndent();
465             pw.print(KEY_MAX_RUNNING_PROCESS_QUEUES, MAX_RUNNING_PROCESS_QUEUES).println();
466             pw.print(KEY_MAX_RUNNING_ACTIVE_BROADCASTS, MAX_RUNNING_ACTIVE_BROADCASTS).println();
467             pw.print(KEY_CORE_MAX_RUNNING_BLOCKING_BROADCASTS,
468                     MAX_CORE_RUNNING_BLOCKING_BROADCASTS).println();
469             pw.print(KEY_CORE_MAX_RUNNING_NON_BLOCKING_BROADCASTS,
470                     MAX_CORE_RUNNING_NON_BLOCKING_BROADCASTS).println();
471             pw.print(KEY_MAX_PENDING_BROADCASTS, MAX_PENDING_BROADCASTS).println();
472             pw.print(KEY_DELAY_NORMAL_MILLIS,
473                     TimeUtils.formatDuration(DELAY_NORMAL_MILLIS)).println();
474             pw.print(KEY_DELAY_CACHED_MILLIS,
475                     TimeUtils.formatDuration(DELAY_CACHED_MILLIS)).println();
476             pw.print(KEY_DELAY_URGENT_MILLIS,
477                     TimeUtils.formatDuration(DELAY_URGENT_MILLIS)).println();
478             pw.print(KEY_DELAY_FOREGROUND_PROC_MILLIS,
479                     TimeUtils.formatDuration(DELAY_FOREGROUND_PROC_MILLIS)).println();
480             pw.print(KEY_DELAY_PERSISTENT_PROC_MILLIS,
481                     TimeUtils.formatDuration(DELAY_PERSISTENT_PROC_MILLIS)).println();
482             pw.print(KEY_MAX_HISTORY_COMPLETE_SIZE, MAX_HISTORY_COMPLETE_SIZE).println();
483             pw.print(KEY_MAX_HISTORY_SUMMARY_SIZE, MAX_HISTORY_SUMMARY_SIZE).println();
484             pw.print(KEY_MAX_CONSECUTIVE_URGENT_DISPATCHES,
485                     MAX_CONSECUTIVE_URGENT_DISPATCHES).println();
486             pw.print(KEY_MAX_CONSECUTIVE_NORMAL_DISPATCHES,
487                     MAX_CONSECUTIVE_NORMAL_DISPATCHES).println();
488             pw.print(KEY_CORE_DEFER_UNTIL_ACTIVE,
489                     CORE_DEFER_UNTIL_ACTIVE).println();
490             pw.print(KEY_PENDING_COLD_START_CHECK_INTERVAL_MILLIS,
491                     PENDING_COLD_START_CHECK_INTERVAL_MILLIS).println();
492             pw.print(KEY_MAX_FROZEN_OUTGOING_BROADCASTS,
493                     MAX_FROZEN_OUTGOING_BROADCASTS).println();
494             pw.decreaseIndent();
495             pw.println();
496         }
497     }
498 }
499