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