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

Commit ebe5002f authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Push Broadcast related state to ProcessStateController" into main

parents bd838048 54ae32ae
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -15839,7 +15839,7 @@ public class ActivityManagerService extends IActivityManager.Stub
        for (int i = mProcessList.mRemovedProcesses.size() - 1; i >= 0; i--) {
            final ProcessRecord app = mProcessList.mRemovedProcesses.get(i);
            if (!app.hasActivitiesOrRecentTasks()
                    && app.mReceivers.numberOfCurReceivers() == 0
                    && !app.mReceivers.isReceivingBroadcast()
                    && app.mServices.numberOfRunningServices() == 0) {
                final IApplicationThread thread = app.getThread();
                Slog.i(TAG, "Exiting empty application process "
@@ -17041,7 +17041,7 @@ public class ActivityManagerService extends IActivityManager.Stub
                            (WindowProcessController) procsToKill.get(i);
                    final ProcessRecord pr = (ProcessRecord) wpc.mOwner;
                    if (ActivityManager.isProcStateBackground(pr.mState.getSetProcState())
                            && pr.mReceivers.numberOfCurReceivers() == 0
                            && !pr.mReceivers.isReceivingBroadcast()
                            && !pr.mState.hasStartedServices()) {
                        pr.killLocked("remove task", ApplicationExitInfo.REASON_USER_REQUESTED,
                                ApplicationExitInfo.SUBREASON_REMOVE_TASK, true);
+0 −19
Original line number Diff line number Diff line
@@ -248,13 +248,6 @@ class BroadcastProcessQueue {
     */
    private long mProcessStartInitiatedTimestampMillis;

    /**
     * Indicates whether the number of current receivers has been incremented using
     * {@link ProcessReceiverRecord#incrementCurReceivers()}. This allows to skip decrementing
     * the receivers when it is not required.
     */
    private boolean mCurReceiversIncremented;

    public BroadcastProcessQueue(@NonNull BroadcastConstants constants,
            @NonNull String processName, int uid) {
        this.constants = Objects.requireNonNull(constants);
@@ -662,18 +655,6 @@ class BroadcastProcessQueue {
        return mActiveFirstLaunch;
    }

    public void incrementCurAppReceivers() {
        app.mReceivers.incrementCurReceivers();
        mCurReceiversIncremented = true;
    }

    public void decrementCurAppReceivers() {
        if (mCurReceiversIncremented) {
            app.mReceivers.decrementCurReceivers();
            mCurReceiversIncremented = false;
        }
    }

    public void setProcessStartInitiatedTimestampMillis(@UptimeMillisLong long timestampMillis) {
        mProcessStartInitiatedTimestampMillis = timestampMillis;
    }
+3 −4
Original line number Diff line number Diff line
@@ -2087,8 +2087,6 @@ class BroadcastQueueImpl extends BroadcastQueue {
    @GuardedBy("mService")
    private void notifyStartedRunning(@NonNull BroadcastProcessQueue queue) {
        if (queue.app != null) {
            queue.incrementCurAppReceivers();

            // Don't bump its LRU position if it's in the background restricted.
            if (mService.mInternal.getRestrictionLevel(
                    queue.uid) < ActivityManager.RESTRICTION_LEVEL_RESTRICTED_BUCKET) {
@@ -2098,6 +2096,8 @@ class BroadcastQueueImpl extends BroadcastQueue {
            mService.mOomAdjuster.unfreezeTemporarily(queue.app,
                    CachedAppOptimizer.UNFREEZE_REASON_START_RECEIVER);

            mService.mProcessStateController.noteBroadcastDeliveryStarted(queue.app,
                    queue.getPreferredSchedulingGroupLocked());
            if (queue.runningOomAdjusted) {
                queue.app.mState.forceProcessStateUpTo(ActivityManager.PROCESS_STATE_RECEIVER);
                mService.enqueueOomAdjTargetLocked(queue.app);
@@ -2112,8 +2112,7 @@ class BroadcastQueueImpl extends BroadcastQueue {
    @GuardedBy("mService")
    private void notifyStoppedRunning(@NonNull BroadcastProcessQueue queue) {
        if (queue.app != null) {
            queue.decrementCurAppReceivers();

            mService.mProcessStateController.noteBroadcastDeliveryEnded(queue.app);
            if (queue.runningOomAdjusted) {
                mService.enqueueOomAdjTargetLocked(queue.app);
            }
+10 −2
Original line number Diff line number Diff line
@@ -1702,6 +1702,14 @@ public abstract class OomAdjuster {
        }
    }

    protected boolean isReceivingBroadcast(ProcessRecord app) {
        if (Flags.pushBroadcastStateToOomadjuster()) {
            return app.mReceivers.isReceivingBroadcast();
        } else {
            return app.mState.getCachedIsReceivingBroadcast(mTmpSchedGroup);
        }
    }

    /**
     * @return The proposed change to the schedGroup.
     */
@@ -1816,7 +1824,7 @@ public abstract class OomAdjuster {
        } else if (app.mServices.hasForegroundServices()) {
            return PROCESS_CAPABILITY_CPU_TIME;
        }
        if (app.mReceivers.numberOfCurReceivers() > 0) {
        if (app.mReceivers.isReceivingBroadcast()) {
            return PROCESS_CAPABILITY_CPU_TIME;
        }
        if (app.hasActiveInstrumentation()) {
@@ -1958,7 +1966,7 @@ public abstract class OomAdjuster {
        }

        final int curSchedGroup = state.getCurrentSchedulingGroup();
        if (app.getWaitingToKill() != null && app.mReceivers.numberOfCurReceivers() == 0
        if (app.getWaitingToKill() != null && !app.mReceivers.isReceivingBroadcast()
                && ActivityManager.isProcStateBackground(state.getCurProcState())
                && !state.hasStartedServices()) {
            app.killLocked(app.getWaitingToKill(), ApplicationExitInfo.REASON_USER_REQUESTED,
+7 −2
Original line number Diff line number Diff line
@@ -1473,13 +1473,18 @@ public class OomAdjusterImpl extends OomAdjuster {
            if (DEBUG_OOM_ADJ_REASON || logUid == appUid) {
                reportOomAdjMessageLocked(TAG_OOM_ADJ, "Making instrumentation: " + app);
            }
        } else if (state.getCachedIsReceivingBroadcast(mTmpSchedGroup)) {
        } else if (isReceivingBroadcast(app)) {
            // An app that is currently receiving a broadcast also
            // counts as being in the foreground for OOM killer purposes.
            // It's placed in a sched group based on the nature of the
            // broadcast as reflected by which queue it's active in.
            adj = FOREGROUND_APP_ADJ;
            if (Flags.pushBroadcastStateToOomadjuster()) {
                schedGroup = app.mReceivers.getBroadcastReceiverSchedGroup();
            } else {
                /// Priority was stored in mTmpSchedGroup by {@link #isReceivingBroadcast)
                schedGroup = mTmpSchedGroup[0];
            }
            state.setAdjType("broadcast");
            procState = ActivityManager.PROCESS_STATE_RECEIVER;
            if (DEBUG_OOM_ADJ_REASON || logUid == appUid) {
Loading