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

Commit a62cf4dc authored by Mark Fasheh's avatar Mark Fasheh Committed by Android (Google) Code Review
Browse files

Merge "Don't spam MSG_CHECK_PENDING_COLD_START_VALIDITY" into main

parents 3cee10e5 d4730896
Loading
Loading
Loading
Loading
+23 −11
Original line number Diff line number Diff line
@@ -192,6 +192,12 @@ class BroadcastQueueModernImpl extends BroadcastQueue {
    @GuardedBy("mService")
    private @Nullable BroadcastProcessQueue mRunningColdStart;

    /**
     * Indicates whether we have queued a message to check pending cold start validity.
     */
    @GuardedBy("mService")
    private boolean mCheckPendingColdStartQueued;

    /**
     * Collection of latches waiting for device to reach specific state. The
     * first argument is a function to test for the desired state, and the
@@ -302,7 +308,11 @@ class BroadcastQueueModernImpl extends BroadcastQueue {
                return true;
            }
            case MSG_CHECK_PENDING_COLD_START_VALIDITY: {
                checkPendingColdStartValidity();
                synchronized (mService) {
                    /* Clear this as we have just received the broadcast. */
                    mCheckPendingColdStartQueued = false;
                    checkPendingColdStartValidityLocked();
                }
                return true;
            }
            case MSG_PROCESS_FREEZABLE_CHANGED: {
@@ -549,7 +559,7 @@ class BroadcastQueueModernImpl extends BroadcastQueue {
            mService.updateOomAdjPendingTargetsLocked(OOM_ADJ_REASON_START_RECEIVER);
        }

        checkPendingColdStartValidity();
        checkPendingColdStartValidityLocked();
        checkAndRemoveWaitingFor();

        traceEnd(cookie);
@@ -573,24 +583,26 @@ class BroadcastQueueModernImpl extends BroadcastQueue {
        enqueueUpdateRunningList();
    }

    private void checkPendingColdStartValidity() {
    @GuardedBy("mService")
    private void checkPendingColdStartValidityLocked() {
        // There are a few cases where a starting process gets killed but AMS doesn't report
        // this event. So, once we start waiting for a pending cold start, periodically check
        // if the pending start is still valid and if not, clear it so that the queue doesn't
        // keep waiting for the process start forever.
        synchronized (mService) {
        // If there is no pending cold start, then nothing to do.
        if (mRunningColdStart == null) {
            return;
        }
        if (isPendingColdStartValid()) {
            if (!mCheckPendingColdStartQueued) {
                mLocalHandler.sendEmptyMessageDelayed(MSG_CHECK_PENDING_COLD_START_VALIDITY,
                        mConstants.PENDING_COLD_START_CHECK_INTERVAL_MILLIS);
                mCheckPendingColdStartQueued = true;
            }
        } else {
            clearInvalidPendingColdStart();
        }
    }
    }

    private void reEnqueueActiveBroadcast(@NonNull BroadcastProcessQueue queue) {
        checkState(queue.isActive(), "isActive");