Skip to content

Commit f46723b

Browse files
author
Christopher Tate
committed
Implement background vs foreground broadcasts
Before now, receiving a broadcast would cause a process to be hoisted to foreground priority / cgroup. This is no longer the case: broadcasts by default are handled in the background, with a suitably increased timeout interval. When a given broadcast needs to be dealt with in a more timely manner, the issuer can set the new FLAG_BROADCAST_FOREGROUND flag on the Intent, which will produce the old foreground-priority behavior. To avoid priority inversions, foreground broadcasts are tracked on a separate outgoing queue and can be in flight simultaneously with a background-priority broadcast. If there is already a background-level broadcast in flight to a given app and then a foreground-level one is dispatched to that app, the app [and its handling of both broadcasts] will be properly hoisted to foreground priority. This change is also essentially the first step towards refactoring the broadcast-handling portions of the Activity Manager into a more independent existence. Making BroadcastQueue a top-level class and regularizing its operation viz the primary Activity Manager operation is the next step. Change-Id: If1be33156dc22dcce318edbb5846b08df8e7bed5
1 parent c97992b commit f46723b

File tree

4 files changed

+972
-757
lines changed

4 files changed

+972
-757
lines changed

api/current.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5640,6 +5640,7 @@ package android.content {
56405640
field public static final int FLAG_GRANT_READ_URI_PERMISSION = 1; // 0x1
56415641
field public static final int FLAG_GRANT_WRITE_URI_PERMISSION = 2; // 0x2
56425642
field public static final int FLAG_INCLUDE_STOPPED_PACKAGES = 32; // 0x20
5643+
field public static final int FLAG_RECEIVER_FOREGROUND = 268435456; // 0x10000000
56435644
field public static final int FLAG_RECEIVER_REGISTERED_ONLY = 1073741824; // 0x40000000
56445645
field public static final int FLAG_RECEIVER_REPLACE_PENDING = 536870912; // 0x20000000
56455646
field public static final java.lang.String METADATA_DOCK_HOME = "android.dock_home";

core/java/android/content/Intent.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2956,6 +2956,13 @@ public static Intent createChooser(Intent target, CharSequence title) {
29562956
* to their receivers.
29572957
*/
29582958
public static final int FLAG_RECEIVER_REPLACE_PENDING = 0x20000000;
2959+
/**
2960+
* If set, when sending a broadcast the recipient is allowed to run at
2961+
* foreground priority, with a shorter timeout interval. During normal
2962+
* broadcasts the receivers are not automatically hoisted out of the
2963+
* background priority class.
2964+
*/
2965+
public static final int FLAG_RECEIVER_FOREGROUND = 0x10000000;
29592966
/**
29602967
* If set, when sending a broadcast <i>before boot has completed</i> only
29612968
* registered receivers will be called -- no BroadcastReceiver components
@@ -2969,14 +2976,14 @@ public static Intent createChooser(Intent target, CharSequence title) {
29692976
*
29702977
* @hide
29712978
*/
2972-
public static final int FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT = 0x10000000;
2979+
public static final int FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT = 0x08000000;
29732980
/**
29742981
* Set when this broadcast is for a boot upgrade, a special mode that
29752982
* allows the broadcast to be sent before the system is ready and launches
29762983
* the app process with no providers running in it.
29772984
* @hide
29782985
*/
2979-
public static final int FLAG_RECEIVER_BOOT_UPGRADE = 0x08000000;
2986+
public static final int FLAG_RECEIVER_BOOT_UPGRADE = 0x04000000;
29802987

29812988
/**
29822989
* @hide Flags that can't be changed with PendingIntent.

0 commit comments

Comments
 (0)