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

Commit 58076e5d authored by Hui Yu's avatar Hui Yu
Browse files

Set temp allowlist for runtime broadcast.

1. Add/move scheduleTempAllowlistLocked() call into
deliverToRegisteredReceiverLocked() so it can be called also for runtime
broadcast.
2. Rename scheduleTempAllowlistLocked() to
maybeScheduleTempAllowlistLocked().

Bug: 187550591
Test: b/187550591 reproduce steps.
Test: atest cts/tests/app/src/android/app/cts/ActivityManagerFgsBgStartTest.java
Change-Id: I323550a8ccd16b7e4ca359cd2a43476637847c85
parent a91e5123
Loading
Loading
Loading
Loading
+12 −18
Original line number Diff line number Diff line
@@ -828,6 +828,7 @@ public final class BroadcastQueue {
            } else {
                r.receiverTime = SystemClock.uptimeMillis();
                maybeAddAllowBackgroundActivityStartsToken(filter.receiverList.app, r);
                maybeScheduleTempAllowlistLocked(filter.owningUid, r, r.options);
                performReceiveLocked(filter.receiverList.app, filter.receiverList.receiver,
                        new Intent(r.intent), r.resultCode, r.resultData,
                        r.resultExtras, r.ordered, r.initialSticky, r.userId);
@@ -911,9 +912,16 @@ public final class BroadcastQueue {
        return false;
    }

    final void scheduleTempAllowlistLocked(int uid, long duration, BroadcastRecord r,
            @TempAllowListType int type, @ReasonCode int reasonCode,
            @Nullable String reason) {
    void maybeScheduleTempAllowlistLocked(int uid, BroadcastRecord r,
            @Nullable BroadcastOptions brOptions) {
        if (brOptions == null || brOptions.getTemporaryAppAllowlistDuration() <= 0) {
            return;
        }
        long duration = brOptions.getTemporaryAppAllowlistDuration();
        final @TempAllowListType int type = brOptions.getTemporaryAppAllowlistType();
        final @ReasonCode int reasonCode = brOptions.getTemporaryAppAllowlistReasonCode();
        final String reason = brOptions.getTemporaryAppAllowlistReason();

        if (duration > Integer.MAX_VALUE) {
            duration = Integer.MAX_VALUE;
        }
@@ -1344,13 +1352,6 @@ public final class BroadcastQueue {
                    // r is guaranteed ordered at this point, so we know finishReceiverLocked()
                    // will get a callback and handle the activity start token lifecycle.
                }
                if (brOptions != null && brOptions.getTemporaryAppAllowlistDuration() > 0) {
                    scheduleTempAllowlistLocked(filter.owningUid,
                            brOptions.getTemporaryAppAllowlistDuration(), r,
                            brOptions.getTemporaryAppAllowlistType(),
                            brOptions.getTemporaryAppAllowlistReasonCode(),
                            brOptions.getTemporaryAppAllowlistReason());
                }
            }
            return;
        }
@@ -1646,16 +1647,9 @@ public final class BroadcastQueue {
                    + info.activityInfo + ", callingUid = " + r.callingUid + ", uid = "
                    + receiverUid);
        }

        final boolean isActivityCapable =
                (brOptions != null && brOptions.getTemporaryAppAllowlistDuration() > 0);
        if (isActivityCapable) {
            scheduleTempAllowlistLocked(receiverUid,
                    brOptions.getTemporaryAppAllowlistDuration(), r,
                    brOptions.getTemporaryAppAllowlistType(),
                    brOptions.getTemporaryAppAllowlistReasonCode(),
                    brOptions.getTemporaryAppAllowlistReason());
        }
        maybeScheduleTempAllowlistLocked(receiverUid, r, brOptions);

        // Report that a component is used for explicit broadcasts.
        if (!r.intent.isExcludingStopped() && r.curComponent != null