Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit f46723b4 authored by Christopher Tate's avatar Christopher Tate
Browse files

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
parent c97992b4
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -5640,6 +5640,7 @@ package android.content {
    field public static final int FLAG_GRANT_READ_URI_PERMISSION = 1; // 0x1
    field public static final int FLAG_GRANT_WRITE_URI_PERMISSION = 2; // 0x2
    field public static final int FLAG_INCLUDE_STOPPED_PACKAGES = 32; // 0x20
    field public static final int FLAG_RECEIVER_FOREGROUND = 268435456; // 0x10000000
    field public static final int FLAG_RECEIVER_REGISTERED_ONLY = 1073741824; // 0x40000000
    field public static final int FLAG_RECEIVER_REPLACE_PENDING = 536870912; // 0x20000000
    field public static final java.lang.String METADATA_DOCK_HOME = "android.dock_home";
+9 −2
Original line number Diff line number Diff line
@@ -2956,6 +2956,13 @@ public class Intent implements Parcelable, Cloneable {
     * to their receivers.
     */
    public static final int FLAG_RECEIVER_REPLACE_PENDING = 0x20000000;
    /**
     * If set, when sending a broadcast the recipient is allowed to run at
     * foreground priority, with a shorter timeout interval.  During normal
     * broadcasts the receivers are not automatically hoisted out of the
     * background priority class.
     */
    public static final int FLAG_RECEIVER_FOREGROUND = 0x10000000;
    /**
     * If set, when sending a broadcast <i>before boot has completed</i> only
     * registered receivers will be called -- no BroadcastReceiver components
@@ -2969,14 +2976,14 @@ public class Intent implements Parcelable, Cloneable {
     *
     * @hide
     */
    public static final int FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT = 0x10000000;
    public static final int FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT = 0x08000000;
    /**
     * Set when this broadcast is for a boot upgrade, a special mode that
     * allows the broadcast to be sent before the system is ready and launches
     * the app process with no providers running in it.
     * @hide
     */
    public static final int FLAG_RECEIVER_BOOT_UPGRADE = 0x08000000;
    public static final int FLAG_RECEIVER_BOOT_UPGRADE = 0x04000000;

    /**
     * @hide Flags that can't be changed with PendingIntent.
+958 −754

File changed.

Preview size limit exceeded, changes collapsed.

+4 −1
Original line number Diff line number Diff line
@@ -59,6 +59,7 @@ class BroadcastRecord extends Binder {
    IBinder receiver;       // who is currently running, null if none.
    int state;
    int anrCount;           // has this broadcast record hit any ANRs?
    ActivityManagerService.BroadcastQueue queue;   // the outbound queue handling this broadcast

    static final int IDLE = 0;
    static final int APP_RECEIVE = 1;
@@ -161,11 +162,13 @@ class BroadcastRecord extends Binder {
        }
    }

    BroadcastRecord(Intent _intent, ProcessRecord _callerApp, String _callerPackage,
    BroadcastRecord(ActivityManagerService.BroadcastQueue _queue,
            Intent _intent, ProcessRecord _callerApp, String _callerPackage,
            int _callingPid, int _callingUid, String _requiredPermission,
            List _receivers, IIntentReceiver _resultTo, int _resultCode,
            String _resultData, Bundle _resultExtras, boolean _serialized,
            boolean _sticky, boolean _initialSticky) {
        queue = _queue;
        intent = _intent;
        callerApp = _callerApp;
        callerPackage = _callerPackage;