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

Commit 254f5ffc authored by Craig Mautner's avatar Craig Mautner Committed by Android (Google) Code Review
Browse files

Merge "Pause activities behind keyguard after boot." into klp-dev

parents bc05918c 2acc389d
Loading
Loading
Loading
Loading
+41 −8
Original line number Diff line number Diff line
@@ -336,7 +336,7 @@ public final class ActivityManagerService extends ActivityManagerNative
        final int startFlags;
        final ActivityStack stack;
        public PendingActivityLaunch(ActivityRecord _r, ActivityRecord _sourceRecord,
        PendingActivityLaunch(ActivityRecord _r, ActivityRecord _sourceRecord,
                int _startFlags, ActivityStack _stack) {
            r = _r;
            sourceRecord = _sourceRecord;
@@ -815,7 +815,11 @@ public final class ActivityManagerService extends ActivityManagerNative
    /**
     * State of external call telling us if the lock screen is shown.
     */
    boolean mLockScreenShown = false;
    static final int LOCK_SCREEN_NEVER_SHOWN = 0;
    static final int LOCK_SCREEN_FIRST_SHOWN = 1;
    static final int LOCK_SCREEN_HIDDEN = 2;
    static final int LOCK_SCREEN_SHOWING = 3;
    int mLockScreenState = LOCK_SCREEN_NEVER_SHOWN;
    /**
     * Set if we are shutting down the system, similar to sleeping.
@@ -4914,8 +4918,8 @@ public final class ActivityManagerService extends ActivityManagerNative
        final long token = Binder.clearCallingIdentity();
        try {
            synchronized (this) {
                if (mLockScreenShown) {
                    mLockScreenShown = false;
                if (lockScreenShowing()) {
                    mLockScreenState = LOCK_SCREEN_HIDDEN;
                    comeOutOfSleepIfNeededLocked();
                }
                mStackSupervisor.setDismissKeyguard(true);
@@ -7956,8 +7960,22 @@ public final class ActivityManagerService extends ActivityManagerNative
        Binder.restoreCallingIdentity(origId);
    }
    boolean lockScreenShowing() {
        switch (mLockScreenState) {
            case LOCK_SCREEN_NEVER_SHOWN:
            case LOCK_SCREEN_HIDDEN:
                return false;
            case LOCK_SCREEN_FIRST_SHOWN:
            case LOCK_SCREEN_SHOWING:
                return true;
            default:
                Slog.e(TAG, "lockScreenShowing: illegal state");
                throw new IllegalStateException("mLockScreenState=" + mLockScreenState);
        }
    }
    private void comeOutOfSleepIfNeededLocked() {
        if (!mWentToSleep && !mLockScreenShown) {
        if (!mWentToSleep && !lockScreenShowing()) {
            if (mSleeping) {
                mSleeping = false;
                mStackSupervisor.comeOutOfSleepIfNeededLocked();
@@ -7993,7 +8011,12 @@ public final class ActivityManagerService extends ActivityManagerNative
        synchronized(this) {
            long ident = Binder.clearCallingIdentity();
            try {
                mLockScreenShown = shown;
                if (shown && mLockScreenState == LOCK_SCREEN_NEVER_SHOWN) {
                    mStackSupervisor.pauseStacks(false, true);
                    mLockScreenState = LOCK_SCREEN_FIRST_SHOWN;
                } else {
                    mLockScreenState = shown ? LOCK_SCREEN_SHOWING : LOCK_SCREEN_HIDDEN;
                }
                comeOutOfSleepIfNeededLocked();
            } finally {
                Binder.restoreCallingIdentity(ident);
@@ -10524,9 +10547,9 @@ public final class ActivityManagerService extends ActivityManagerNative
            }
        }
        if (dumpPackage == null) {
            if (mSleeping || mWentToSleep || mLockScreenShown) {
            if (mSleeping || mWentToSleep || lockScreenShowing()) {
                pw.println("  mSleeping=" + mSleeping + " mWentToSleep=" + mWentToSleep
                        + " mLockScreenShown " + mLockScreenShown);
                        + " mLockScreenState=" + lockScreenStateToString());
            }
            if (mShuttingDown) {
                pw.println("  mShuttingDown=" + mShuttingDown);
@@ -16098,4 +16121,14 @@ public final class ActivityManagerService extends ActivityManagerNative
        info.applicationInfo = getAppInfoForUser(info.applicationInfo, userId);
        return info;
    }
    private String lockScreenStateToString() {
        switch (mLockScreenState) {
            case LOCK_SCREEN_NEVER_SHOWN: return "LOCK_SCREEN_NEVER_SHOWN";
            case LOCK_SCREEN_FIRST_SHOWN: return "LOCK_SCREEN_FIRST_SHOWN";
            case LOCK_SCREEN_HIDDEN: return "LOCK_SCREEN_HIDDEN";
            case LOCK_SCREEN_SHOWING: return "LOCK_SCREEN_SHOWING";
            default: return "unknown (" + mLockScreenState + ")";
        }
    }
}
+5 −1
Original line number Diff line number Diff line
@@ -1190,6 +1190,10 @@ final class ActivityStack {
    }

    final boolean resumeTopActivityLocked(ActivityRecord prev, Bundle options) {
        if (mService.mLockScreenState == ActivityManagerService.LOCK_SCREEN_FIRST_SHOWN) {
            return false;
        }

        // Find the first activity that is not finishing.
        ActivityRecord next = topRunningActivityLocked(null);

@@ -1325,7 +1329,7 @@ final class ActivityStack {

        // We need to start pausing the current activity so the top one
        // can be resumed...
        boolean pausing = mStackSupervisor.pauseBackStacks(userLeaving);
        boolean pausing = mStackSupervisor.pauseStacks(userLeaving, false);
        if (mResumedActivity != null) {
            pausing = true;
            startPausingLocked(userLeaving, false);
+9 −3
Original line number Diff line number Diff line
@@ -465,12 +465,18 @@ public final class ActivityStackSupervisor {
        return true;
    }

    boolean pauseBackStacks(boolean userLeaving) {
    /**
     * Pause all activities in either all of the stacks or just the back stacks.
     * @param userLeaving Passed to pauseActivity() to indicate whether to call onUserLeaving().
     * @param allStacks Whether to pause all the stacks (true), or just the back stacks (false).
     * @return true if any activity was paused as a result of this call.
     */
    boolean pauseStacks(boolean userLeaving, boolean allStacks) {
        boolean someActivityPaused = false;
        for (int stackNdx = mStacks.size() - 1; stackNdx >= 0; --stackNdx) {
            final ActivityStack stack = mStacks.get(stackNdx);
            if (!isFrontStack(stack) && stack.mResumedActivity != null) {
                if (DEBUG_STATES) Slog.d(TAG, "pauseBackStacks: stack=" + stack +
            if ((allStacks || !isFrontStack(stack)) && stack.mResumedActivity != null) {
                if (DEBUG_STATES) Slog.d(TAG, "pauseStacks: stack=" + stack +
                        " mResumedActivity=" + stack.mResumedActivity);
                stack.startPausingLocked(userLeaving, false);
                someActivityPaused = true;