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

Commit 9b80b941 authored by Fyodor Kupolov's avatar Fyodor Kupolov
Browse files

Do not schedule restarts if the system is shutting down

Bug: 29357754
Change-Id: Id5cf43fb6c4c6ea04d60bd09e910a9cec194c753
parent 02435d24
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -1443,6 +1443,12 @@ public final class ActiveServices {
            boolean allowCancel) {
        boolean canceled = false;

        if (mAm.isShuttingDownLocked()) {
            Slog.w(TAG, "Not scheduling restart of crashed service " + r.shortName
                    + " - system is shutting down");
            return false;
        }

        ServiceMap smap = getServiceMap(r.userId);
        if (smap.mServicesByName.get(r.name) != r) {
            ServiceRecord cur = smap.mServicesByName.get(r.name);
+13 −9
Original line number Diff line number Diff line
@@ -11476,11 +11476,15 @@ public final class ActivityManagerService extends ActivityManagerNative
    // Actually is sleeping or shutting down or whatever else in the future
    // is an inactive state.
    public boolean isSleepingOrShuttingDown() {
        return isSleeping() || mShuttingDown;
    boolean isSleepingOrShuttingDownLocked() {
        return isSleepingLocked() || mShuttingDown;
    }
    public boolean isSleeping() {
    boolean isShuttingDownLocked() {
        return mShuttingDown;
    }
    boolean isSleepingLocked() {
        return mSleeping;
    }
@@ -12850,7 +12854,7 @@ public final class ActivityManagerService extends ActivityManagerNative
                    proc.notCachedSinceIdle = true;
                    proc.initialIdlePss = 0;
                    proc.nextPssTime = ProcessList.computeNextPssTime(proc.setProcState, true,
                            mTestPssMode, isSleeping(), now);
                            mTestPssMode, isSleepingLocked(), now);
                }
            }
@@ -19756,7 +19760,7 @@ public final class ActivityManagerService extends ActivityManagerNative
            if (memLowered || now > (app.lastStateTime+ProcessList.PSS_ALL_INTERVAL)) {
                app.pssProcState = app.setProcState;
                app.nextPssTime = ProcessList.computeNextPssTime(app.curProcState, true,
                        mTestPssMode, isSleeping(), now);
                        mTestPssMode, isSleepingLocked(), now);
                mPendingPssProcesses.add(app);
            }
        }
@@ -19804,7 +19808,7 @@ public final class ActivityManagerService extends ActivityManagerNative
            }
        }
        return !processingBroadcasts
                && (isSleeping() || mStackSupervisor.allResumedActivitiesIdle());
                && (isSleepingLocked() || mStackSupervisor.allResumedActivitiesIdle());
    }
    /**
@@ -20095,7 +20099,7 @@ public final class ActivityManagerService extends ActivityManagerNative
            }
            app.lastStateTime = now;
            app.nextPssTime = ProcessList.computeNextPssTime(app.curProcState, true,
                    mTestPssMode, isSleeping(), now);
                    mTestPssMode, isSleepingLocked(), now);
            if (DEBUG_PSS) Slog.d(TAG_PSS, "Process state change from "
                    + ProcessList.makeProcStateString(app.setProcState) + " to "
                    + ProcessList.makeProcStateString(app.curProcState) + " next pss in "
@@ -20106,7 +20110,7 @@ public final class ActivityManagerService extends ActivityManagerNative
                    mTestPssMode)))) {
                requestPssLocked(app, app.setProcState);
                app.nextPssTime = ProcessList.computeNextPssTime(app.curProcState, false,
                        mTestPssMode, isSleeping(), now);
                        mTestPssMode, isSleepingLocked(), now);
            } else if (false && DEBUG_PSS) Slog.d(TAG_PSS,
                    "Not requesting PSS of " + app + ": next=" + (app.nextPssTime-now));
        }
@@ -20632,7 +20636,7 @@ public final class ActivityManagerService extends ActivityManagerNative
        }
        mLastMemoryLevel = memFactor;
        mLastNumProcesses = mLruProcesses.size();
        boolean allChanged = mProcessStats.setMemFactorLocked(memFactor, !isSleeping(), now);
        boolean allChanged = mProcessStats.setMemFactorLocked(memFactor, !isSleepingLocked(), now);
        final int trackerMemFactor = mProcessStats.getMemFactorLocked();
        if (memFactor != ProcessStats.ADJ_MEM_FACTOR_NORMAL) {
            if (mLowRamStartTime == 0) {
+1 −1
Original line number Diff line number Diff line
@@ -931,7 +931,7 @@ final class ActivityRecord {
        final ReferrerIntent rintent = new ReferrerIntent(intent, referrer);
        boolean unsent = true;
        if ((state == ActivityState.RESUMED
                || (service.isSleeping() && task.stack != null
                || (service.isSleepingLocked() && task.stack != null
                    && task.stack.topRunningActivityLocked() == this))
                && app != null && app.thread != null) {
            try {
+9 −9
Original line number Diff line number Diff line
@@ -1075,7 +1075,7 @@ final class ActivityStack {
        if (mPausingActivity != null) {
            Slog.wtf(TAG, "Going to pause when pause is already pending for " + mPausingActivity
                    + " state=" + mPausingActivity.state);
            if (!mService.isSleeping()) {
            if (!mService.isSleepingLocked()) {
                // Avoid recursion among check for sleep and complete pause during sleeping.
                // Because activity will be paused immediately after resume, just let pause
                // be completed by the order of activity paused from clients.
@@ -1139,7 +1139,7 @@ final class ActivityStack {

        // If we are not going to sleep, we want to ensure the device is
        // awake until the next activity is started.
        if (!uiSleeping && !mService.isSleepingOrShuttingDown()) {
        if (!uiSleeping && !mService.isSleepingOrShuttingDownLocked()) {
            mStackSupervisor.acquireLaunchWakelock();
        }

@@ -1292,7 +1292,7 @@ final class ActivityStack {
                    // We don't need to schedule another stop, we only need to let it happen.
                    prev.state = ActivityState.STOPPING;
                } else if ((!prev.visible && !hasVisibleBehindActivity())
                        || mService.isSleepingOrShuttingDown()) {
                        || mService.isSleepingOrShuttingDownLocked()) {
                    // If we were visible then resumeTopActivities will release resources before
                    // stopping.
                    addToStopping(prev, true /* immediate */);
@@ -1310,7 +1310,7 @@ final class ActivityStack {

        if (resumeNext) {
            final ActivityStack topStack = mStackSupervisor.getFocusedStack();
            if (!mService.isSleepingOrShuttingDown()) {
            if (!mService.isSleepingOrShuttingDownLocked()) {
                mStackSupervisor.resumeFocusedStackTopActivityLocked(topStack, prev, null);
            } else {
                mStackSupervisor.checkReadyForSleepLocked();
@@ -1821,7 +1821,7 @@ final class ActivityStack {
            boolean behindFullscreenActivity) {

        if (!okToShowLocked(r)
                || (mService.isSleepingOrShuttingDown() && r.voiceSession == null)) {
                || (mService.isSleepingOrShuttingDownLocked() && r.voiceSession == null)) {
            return false;
        }

@@ -2196,7 +2196,7 @@ final class ActivityStack {

        // If we are sleeping, and there is no resumed activity, and the top
        // activity is paused, well that is the state we want.
        if (mService.isSleepingOrShuttingDown()
        if (mService.isSleepingOrShuttingDownLocked()
                && mLastPausedActivity == next
                && mStackSupervisor.allPausedActivitiesComplete()) {
            // Make sure we have executed any pending transitions, since there
@@ -2278,7 +2278,7 @@ final class ActivityStack {
        // If the most recent activity was noHistory but was only stopped rather
        // than stopped+finished because the device went to sleep, we need to make
        // sure to finish it as we're making a new activity topmost.
        if (mService.isSleeping() && mLastNoHistoryActivity != null &&
        if (mService.isSleepingLocked() && mLastNoHistoryActivity != null &&
                !mLastNoHistoryActivity.finishing) {
            if (DEBUG_STATES) Slog.d(TAG_STATES,
                    "no-history finish of " + mLastNoHistoryActivity + " on new resume");
@@ -3212,7 +3212,7 @@ final class ActivityStack {
        if ((r.intent.getFlags()&Intent.FLAG_ACTIVITY_NO_HISTORY) != 0
                || (r.info.flags&ActivityInfo.FLAG_NO_HISTORY) != 0) {
            if (!r.finishing) {
                if (!mService.isSleeping()) {
                if (!mService.isSleepingLocked()) {
                    if (DEBUG_STATES) Slog.d(TAG_STATES, "no-history finish of " + r);
                    if (requestFinishActivityLocked(r.appToken, Activity.RESULT_CANCELED, null,
                            "stop-no-history", false)) {
@@ -3244,7 +3244,7 @@ final class ActivityStack {
                EventLogTags.writeAmStopActivity(
                        r.userId, System.identityHashCode(r), r.shortComponentName);
                r.app.thread.scheduleStopActivity(r.appToken, r.visible, r.configChangeFlags);
                if (mService.isSleepingOrShuttingDown()) {
                if (mService.isSleepingOrShuttingDownLocked()) {
                    r.setSleeping(true);
                }
                Message msg = mHandler.obtainMessage(STOP_TIMEOUT_MSG, r);
+3 −3
Original line number Diff line number Diff line
@@ -2707,7 +2707,7 @@ public final class ActivityStackSupervisor implements DisplayListener {
    }

    void checkReadyForSleepLocked() {
        if (!mService.isSleepingOrShuttingDown()) {
        if (!mService.isSleepingOrShuttingDownLocked()) {
            // Do not care.
            return;
        }
@@ -3047,7 +3047,7 @@ public final class ActivityStackSupervisor implements DisplayListener {
                    mWindowManager.setAppVisibility(s.appToken, false);
                }
            }
            if ((!waitingVisible || mService.isSleepingOrShuttingDown()) && remove) {
            if ((!waitingVisible || mService.isSleepingOrShuttingDownLocked()) && remove) {
                if (DEBUG_STATES) Slog.v(TAG, "Ready to stop: " + s);
                if (stops == null) {
                    stops = new ArrayList<>();
@@ -3771,7 +3771,7 @@ public final class ActivityStackSupervisor implements DisplayListener {
                } break;
                case SLEEP_TIMEOUT_MSG: {
                    synchronized (mService) {
                        if (mService.isSleepingOrShuttingDown()) {
                        if (mService.isSleepingOrShuttingDownLocked()) {
                            Slog.w(TAG, "Sleep timeout!  Sleeping now.");
                            mSleepTimeout = true;
                            checkReadyForSleepLocked();