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

Commit 9979a51e authored by wilsonshih's avatar wilsonshih
Browse files

Replace ActivityRecord#mSetToSleep by canTurnScreenOn

The member ActivityRecord#mSetToSleep can be replaced by checking
canTurnScreenOn & mCurrentLaunchCanTurnScreenOn.

Before Task#goToSleep been called, the display will be set to sleeping
in RootWindowContainer#applySleepTokens, so when checking
ActivityRecord#shouldBeVisibleUnchecked while display is sleeping,
we only need to perform an additional check whether this activity can
turn screen on.
This is because there are only two ways to apply sleep token, which
are keyguard and screen state, and we have checked the keyguard
visibility through KeyguardController#checkKeyguardVisibility.

Test: atest ActivityVisibilityTests KeyguardTests KeyguardLockedTests
KeyguardTransitionTests
Test: atest ActivityRecordTests
Bug: 163993448

Change-Id: I64cf04e3037ab9ca7afec9d1c8bf65d202a02e36
parent 9a095a4e
Loading
Loading
Loading
Loading
+7 −18
Original line number Diff line number Diff line
@@ -499,7 +499,6 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A
                                        // process that it is hidden.
    private boolean mLastDeferHidingClient; // If true we will defer setting mClientVisible to false
                                           // and reporting to the client that it is hidden.
    private boolean mSetToSleep; // have we told the activity to sleep?
    boolean nowVisible;     // is this activity's window visible?
    boolean mClientVisibilityDeferred;// was the visibility change message to client deferred?
    boolean idle;           // has the activity gone idle?
@@ -906,7 +905,6 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A
                pw.print(" finishing="); pw.println(finishing);
        pw.print(prefix); pw.print("keysPaused="); pw.print(keysPaused);
                pw.print(" inHistory="); pw.print(inHistory);
        pw.print(" setToSleep="); pw.print(mSetToSleep);
                pw.print(" idle="); pw.print(idle);
                pw.print(" mStartingWindowState=");
                pw.println(startingWindowStateToString(mStartingWindowState));
@@ -4675,15 +4673,14 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A
            return false;
        }

        // Check if the activity is on a sleeping display
        // TODO b/163993448 mSetToSleep is required when restarting an existing activity, try to
        // remove it if possible.
        if (mSetToSleep && mDisplayContent.isSleeping()) {
            return false;
        }

        // Check if the activity is on a sleeping display, canTurnScreenOn will also check
        // keyguard visibility
        if (mDisplayContent.isSleeping()) {
            return canTurnScreenOn();
        } else {
            return mStackSupervisor.getKeyguardController().checkKeyguardVisibility(this);
        }
    }

    void updateVisibilityIgnoringKeyguard(boolean behindFullscreenActivity) {
        visibleIgnoringKeyguard = (!behindFullscreenActivity || mLaunchTaskBehind)
@@ -4719,7 +4716,6 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A
                stack.mUndrawnActivitiesBelowTopTranslucent.add(this);
            }
            setVisibility(true);
            mSetToSleep = false;
            app.postPendingUiCleanMsg(true);
            if (reportToClient) {
                mClientVisibilityDeferred = false;
@@ -5118,9 +5114,6 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A
            mAtmService.getLifecycleManager().scheduleTransaction(app.getThread(), appToken,
                    StopActivityItem.obtain(configChangeFlags));

            if (stack.shouldSleepOrShutDownActivities()) {
                setSleeping(true);
            }
            mAtmService.mH.postDelayed(mStopTimeoutRunnable, STOP_TIMEOUT);
        } catch (Exception e) {
            // Maybe just ignore exceptions here...  if the process has crashed, our death
@@ -5711,10 +5704,6 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A
        return mVisibleRequested || nowVisible || mState == PAUSING || mState == RESUMED;
    }

    void setSleeping(boolean sleeping) {
        mSetToSleep = sleeping;
    }

    static int getTaskForActivityLocked(IBinder token, boolean onlyRoot) {
        final ActivityRecord r = ActivityRecord.forTokenLocked(token);
        if (r == null || r.getParent() == null) {
@@ -7561,7 +7550,7 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A
            return false;
        }
        final Task stack = getRootTask();
        return stack != null
        return mCurrentLaunchCanTurnScreenOn && stack != null
                && mStackSupervisor.getKeyguardController().checkKeyguardVisibility(this);
    }

+0 −1
Original line number Diff line number Diff line
@@ -820,7 +820,6 @@ public class ActivityStackSupervisor implements RecentTasks.Callbacks {
                }
                mService.getPackageManagerInternalLocked().notifyPackageUse(
                        r.intent.getComponent().getPackageName(), NOTIFY_PACKAGE_USE_ACTIVITY);
                r.setSleeping(false);
                r.forceNewConfig = false;
                mService.getAppWarningsLocked().onStartActivity(r);
                r.compat = mService.compatibilityInfoForPackageLocked(r.info.applicationInfo);
+4 −0
Original line number Diff line number Diff line
@@ -2546,6 +2546,10 @@ class ActivityStarter {

    private void resumeTargetStackIfNeeded() {
        if (mDoResume) {
            final ActivityRecord next = mTargetStack.topRunningActivity(true /* focusableOnly */);
            if (next != null) {
                next.setCurrentLaunchCanTurnScreenOn(true);
            }
            mRootWindowContainer.resumeFocusedStacksTopActivities(mTargetStack, null, mOptions);
        } else {
            ActivityOptions.abort(mOptions);
+3 −1
Original line number Diff line number Diff line
@@ -55,6 +55,7 @@ import static com.android.server.policy.WindowManagerPolicy.FINISH_LAYOUT_REDO_L
import static com.android.server.policy.WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER;
import static com.android.server.wm.ActivityStackSupervisor.DEFER_RESUME;
import static com.android.server.wm.ActivityStackSupervisor.ON_TOP;
import static com.android.server.wm.ActivityStackSupervisor.PRESERVE_WINDOWS;
import static com.android.server.wm.ActivityStackSupervisor.dumpHistoryList;
import static com.android.server.wm.ActivityStackSupervisor.printThisActivity;
import static com.android.server.wm.ActivityTaskManagerDebugConfig.DEBUG_RECENTS;
@@ -2779,7 +2780,8 @@ class RootWindowContainer extends WindowContainer<DisplayContent>
                if (allowDelay) {
                    result &= stack.goToSleepIfPossible(shuttingDown);
                } else {
                    stack.goToSleep();
                    stack.ensureActivitiesVisible(null /* starting */, 0 /* configChanges */,
                            !PRESERVE_WINDOWS);
                }
            }
            return result;
+2 −20
Original line number Diff line number Diff line
@@ -5342,8 +5342,6 @@ class Task extends WindowContainer<WindowContainer> {
    }

    void awakeFromSleepingLocked() {
        // Ensure activities are no longer sleeping.
        forAllActivities((Consumer<ActivityRecord>) (r) -> r.setSleeping(false));
        if (mPausingActivity != null) {
            Slog.d(TAG, "awakeFromSleepingLocked: previously pausing activity didn't pause");
            mPausingActivity.activityPaused(true);
@@ -5397,27 +5395,13 @@ class Task extends WindowContainer<WindowContainer> {
        }

        if (shouldSleep) {
            goToSleep();
            ensureActivitiesVisible(null /* starting */, 0 /* configChanges */,
                    !PRESERVE_WINDOWS);
        }

        return shouldSleep;
    }

    void goToSleep() {
        // Make sure all visible activities are now sleeping. This will update the activity's
        // visibility and onStop() will be called.
        forAllActivities((r) -> {
            if (r.isState(STARTED, RESUMED, PAUSING, PAUSED, STOPPING, STOPPED)) {
                r.setSleeping(true);
            }
        });

        // Ensure visibility after updating sleep states without updating configuration,
        // as activities are about to be sent to sleep.
        ensureActivitiesVisible(null /* starting */, 0 /* configChanges */,
                !PRESERVE_WINDOWS);
    }

    private boolean containsActivityFromStack(List<ActivityRecord> rs) {
        for (ActivityRecord r : rs) {
            if (r.getRootTask() == this) {
@@ -5948,7 +5932,6 @@ class Task extends WindowContainer<WindowContainer> {
        // The activity may be waiting for stop, but that is no longer
        // appropriate for it.
        mStackSupervisor.mStoppingActivities.remove(next);
        next.setSleeping(false);

        if (DEBUG_SWITCH) Slog.v(TAG_SWITCH, "Resuming " + next);

@@ -6221,7 +6204,6 @@ class Task extends WindowContainer<WindowContainer> {
                EventLogTags.writeWmResumeActivity(next.mUserId, System.identityHashCode(next),
                        next.getTask().mTaskId, next.shortComponentName);

                next.setSleeping(false);
                mAtmService.getAppWarningsLocked().onResumeActivity(next);
                next.app.setPendingUiCleanAndForceProcessStateUpTo(mAtmService.mTopProcessState);
                next.clearOptionsLocked();