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

Commit f6f23bff authored by Amith Yamasani's avatar Amith Yamasani
Browse files

Implement freezer delay broadcast option in legacy queue

Add similar logic for freezer delay as in the modern queue.

Also, gracefully return from forceDelayBroadcastDelay() when
called for legacy queue.

Bug: 278940896
Test: atest BroadcastFreezerTest
Change-Id: Iae17898df59f50799ed9ba6c44bf745b0e090026
parent 34bc8be6
Loading
Loading
Loading
Loading
+4 −1
Original line number Diff line number Diff line
@@ -19037,8 +19037,11 @@ public class ActivityManagerService extends IActivityManager.Stub
            long delayedDurationMs) {
        Objects.requireNonNull(targetPackage);
        Preconditions.checkArgumentNonnegative(delayedDurationMs);
        Preconditions.checkState(mEnableModernQueue, "Not valid in legacy queue");
        enforceCallingPermission(permission.DUMP, "forceDelayBroadcastDelivery()");
        // Ignore request if modern queue is not enabled
        if (!mEnableModernQueue) {
            return;
        }
        for (BroadcastQueue queue : mBroadcastQueues) {
            queue.forceDelayBroadcastDelivery(targetPackage, delayedDurationMs);
+18 −2
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@ package com.android.server.am;

import static android.app.ActivityManager.RESTRICTION_LEVEL_RESTRICTED_BUCKET;
import static android.app.ActivityManagerInternal.OOM_ADJ_REASON_START_RECEIVER;
import static android.os.PowerExemptionManager.TEMPORARY_ALLOW_LIST_TYPE_APP_FREEZING_DELAYED;
import static android.os.Process.ZYGOTE_POLICY_FLAG_EMPTY;
import static android.os.Process.ZYGOTE_POLICY_FLAG_LATENCY_SENSITIVE;
import static android.text.TextUtils.formatSimple;
@@ -384,6 +385,16 @@ public class BroadcastQueueImpl extends BroadcastQueue {
        maybeReportBroadcastDispatchedEventLocked(r, r.curReceiver.applicationInfo.uid);
        r.intent.setComponent(r.curComponent);

        // See if we need to delay the freezer based on BroadcastOptions
        if (r.options != null
                && r.options.getTemporaryAppAllowlistDuration() > 0
                && r.options.getTemporaryAppAllowlistType()
                    == TEMPORARY_ALLOW_LIST_TYPE_APP_FREEZING_DELAYED) {
            mService.mOomAdjuster.mCachedAppOptimizer.unfreezeTemporarily(app,
                    CachedAppOptimizer.UNFREEZE_REASON_START_RECEIVER,
                    r.options.getTemporaryAppAllowlistDuration());
        }

        boolean started = false;
        try {
            if (DEBUG_BROADCAST_LIGHT) Slog.v(TAG_BROADCAST,
@@ -930,9 +941,14 @@ public class BroadcastQueueImpl extends BroadcastQueue {
            Slog.v(TAG, "Broadcast temp allowlist uid=" + uid + " duration=" + duration
                    + " type=" + type + " : " + b.toString());
        }

        // Only add to temp allowlist if it's not the APP_FREEZING_DELAYED type. That will be
        // handled when the broadcast is actually being scheduled on the app thread.
        if (type != TEMPORARY_ALLOW_LIST_TYPE_APP_FREEZING_DELAYED) {
            mService.tempAllowlistUidLocked(uid, duration, reasonCode, b.toString(), type,
                    r.callingUid);
        }
    }

    private void processNextBroadcast(boolean fromMsg) {
        synchronized (mService) {