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

Commit a72217f7 authored by Louis Chang's avatar Louis Chang Committed by Android (Google) Code Review
Browse files

Merge "Make all activities on visible and focusable leaf tasks be resumed"

parents 00da245b 3befe55f
Loading
Loading
Loading
Loading
+6 −6
Original line number Diff line number Diff line
@@ -1021,12 +1021,6 @@
      "group": "WM_ERROR",
      "at": "com\/android\/server\/wm\/WindowManagerService.java"
    },
    "-903853754": {
      "message": "pauseBackStacks: stack=%s mResumedActivity=%s",
      "level": "DEBUG",
      "group": "WM_DEBUG_STATES",
      "at": "com\/android\/server\/wm\/TaskDisplayArea.java"
    },
    "-883738232": {
      "message": "Adding more than one toast window for UID at a time.",
      "level": "WARN",
@@ -2125,6 +2119,12 @@
      "group": "WM_DEBUG_APP_TRANSITIONS",
      "at": "com\/android\/server\/wm\/AppTransition.java"
    },
    "349443311": {
      "message": "pauseBackStacks: task=%s mResumedActivity=%s",
      "level": "DEBUG",
      "group": "WM_DEBUG_STATES",
      "at": "com\/android\/server\/wm\/TaskDisplayArea.java"
    },
    "355720268": {
      "message": "stopFreezingDisplayLocked: Unfreezing now",
      "level": "DEBUG",
+20 −22
Original line number Diff line number Diff line
@@ -2568,7 +2568,7 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A
        }

        final Task rootTask = getRootTask();
        final boolean mayAdjustTop = (isState(RESUMED) || rootTask.mResumedActivity == null)
        final boolean mayAdjustTop = (isState(RESUMED) || rootTask.getResumedActivity() == null)
                && rootTask.isFocusedStackOnDisplay()
                // Do not adjust focus task because the task will be reused to launch new activity.
                && !task.isClearingToReuseTask();
@@ -2640,12 +2640,12 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A
                // Tell window manager to prepare for this one to be removed.
                setVisibility(false);

                if (rootTask.mPausingActivity == null) {
                if (task.getPausingActivity() == null) {
                    ProtoLog.v(WM_DEBUG_STATES, "Finish needs to pause: %s", this);
                    if (DEBUG_USER_LEAVING) {
                        Slog.v(TAG_USER_LEAVING, "finish() => pause with userLeaving=false");
                    }
                    rootTask.startPausingLocked(false /* userLeaving */, false /* uiSleeping */,
                    task.startPausingLocked(false /* userLeaving */, false /* uiSleeping */,
                            null /* resuming */, "finish");
                }

@@ -2733,7 +2733,7 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A
        final boolean isCurrentVisible = mVisibleRequested || isState(PAUSED);
        if (isCurrentVisible) {
            final Task stack = getStack();
            final ActivityRecord activity = stack.mResumedActivity;
            final ActivityRecord activity = stack.getResumedActivity();
            boolean ensureVisibility = false;
            if (activity != null && !activity.occludesParent()) {
                // If the resume activity is not opaque, we need to make sure the visibilities of
@@ -2961,10 +2961,10 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A
    boolean safelyDestroy(String reason) {
        if (isDestroyable()) {
            if (DEBUG_SWITCH) {
                final Task stack = getRootTask();
                final Task task = getTask();
                Slog.v(TAG_SWITCH, "Safely destroying " + this + " in state " + getState()
                        + " resumed=" + stack.mResumedActivity
                        + " pausing=" + stack.mPausingActivity
                        + " resumed=" + task.getResumedActivity()
                        + " pausing=" + task.getPausingActivity()
                        + " for reason " + reason);
            }
            return destroyImmediately(reason);
@@ -4842,7 +4842,7 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A
                    // If the app is capable of entering PIP, we should try pausing it now
                    // so it can PIP correctly.
                    if (deferHidingClient) {
                        getRootTask().startPausingLocked(userLeaving, false /* uiSleeping */,
                        task.startPausingLocked(userLeaving, false /* uiSleeping */,
                                null /* resuming */, "makeInvisible");
                        break;
                    }
@@ -5073,25 +5073,24 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A
        ProtoLog.v(WM_DEBUG_STATES, "Activity paused: token=%s, timeout=%b", appToken,
                timeout);

        final Task stack = getStack();

        if (stack != null) {
        if (task != null) {
            removePauseTimeout();

            if (stack.mPausingActivity == this) {
            final ActivityRecord pausingActivity = task.getPausingActivity();
            if (pausingActivity == this) {
                ProtoLog.v(WM_DEBUG_STATES, "Moving to PAUSED: %s %s", this,
                        (timeout ? "(due to timeout)" : " (pause complete)"));
                mAtmService.deferWindowLayout();
                try {
                    stack.completePauseLocked(true /* resumeNext */, null /* resumingActivity */);
                    task.completePauseLocked(true /* resumeNext */, null /* resumingActivity */);
                } finally {
                    mAtmService.continueWindowLayout();
                }
                return;
            } else {
                EventLogTags.writeWmFailedToPause(mUserId, System.identityHashCode(this),
                        shortComponentName, stack.mPausingActivity != null
                                ? stack.mPausingActivity.shortComponentName : "(none)");
                        shortComponentName, pausingActivity != null
                                ? pausingActivity.shortComponentName : "(none)");
                if (isState(PAUSING)) {
                    setState(PAUSED, "activityPausedLocked");
                    if (finishing) {
@@ -5721,14 +5720,14 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A
        // First find the real culprit...  if this activity has stopped, then the key dispatching
        // timeout should not be caused by this.
        if (stopped) {
            final Task stack = mRootWindowContainer.getTopDisplayFocusedRootTask();
            if (stack == null) {
            final Task rootTask = mRootWindowContainer.getTopDisplayFocusedRootTask();
            if (rootTask == null) {
                return this;
            }
            // Try to use the one which is closest to top.
            ActivityRecord r = stack.getResumedActivity();
            ActivityRecord r = rootTask.getResumedActivity();
            if (r == null) {
                r = stack.mPausingActivity;
                r = rootTask.getPausingActivity();
            }
            if (r != null) {
                return r;
@@ -5806,9 +5805,8 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A
            // This would be redundant.
            return false;
        }
        final Task stack = getRootTask();
        if (isState(RESUMED) || stack == null || this == stack.mPausingActivity || !mHaveState
                || !stopped) {
        if (isState(RESUMED) || getRootTask() == null || this == task.getPausingActivity()
                || !mHaveState || !stopped) {
            // We're not ready for this kind of thing.
            return false;
        }
+4 −3
Original line number Diff line number Diff line
@@ -1133,9 +1133,10 @@ public class ActivityTaskManagerService extends IActivityTaskManager.Stub {
        synchronized (mGlobalLock) {
            // If this is coming from the currently resumed activity, it is
            // effectively saying that app switches are allowed at this point.
            final Task stack = getTopDisplayFocusedRootTask();
            if (stack != null && stack.mResumedActivity != null
                    && stack.mResumedActivity.info.applicationInfo.uid == Binder.getCallingUid()) {
            final Task topFocusedRootTask = getTopDisplayFocusedRootTask();
            if (topFocusedRootTask != null && topFocusedRootTask.getResumedActivity() != null
                    && topFocusedRootTask.getResumedActivity().info.applicationInfo.uid
                    == Binder.getCallingUid()) {
                mAppSwitchesAllowedTime = 0;
            }
        }
+2 −2
Original line number Diff line number Diff line
@@ -2066,7 +2066,7 @@ public class ActivityTaskSupervisor implements RecentTasks.Callbacks {
    void updateTopResumedActivityIfNeeded() {
        final ActivityRecord prevTopActivity = mTopResumedActivity;
        final Task topStack = mRootWindowContainer.getTopDisplayFocusedRootTask();
        if (topStack == null || topStack.mResumedActivity == prevTopActivity) {
        if (topStack == null || topStack.getResumedActivity() == prevTopActivity) {
            if (mService.isSleepingLocked()) {
                // There won't be a next resumed activity. The top process should still be updated
                // according to the current top focused activity.
@@ -2088,7 +2088,7 @@ public class ActivityTaskSupervisor implements RecentTasks.Callbacks {
        }

        // Update the current top activity.
        mTopResumedActivity = topStack.mResumedActivity;
        mTopResumedActivity = topStack.getResumedActivity();
        scheduleTopResumedActivityStateIfNeeded();

        mService.updateTopApp(mTopResumedActivity);
+10 −9
Original line number Diff line number Diff line
@@ -1888,13 +1888,13 @@ class RootWindowContainer extends WindowContainer<DisplayContent>
        // First, found out what is currently the foreground app, so that we don't blow away the
        // previous app if this activity is being hosted by the process that is actually still the
        // foreground.
        WindowProcessController fgApp = getItemFromRootTasks(stack -> {
            if (isTopDisplayFocusedRootTask(stack)) {
                final ActivityRecord resumedActivity = stack.getResumedActivity();
        WindowProcessController fgApp = getItemFromRootTasks(rootTask -> {
            if (isTopDisplayFocusedRootTask(rootTask)) {
                final ActivityRecord resumedActivity = rootTask.getResumedActivity();
                if (resumedActivity != null) {
                    return resumedActivity.app;
                } else if (stack.mPausingActivity != null) {
                    return stack.mPausingActivity.app;
                } else if (rootTask.getPausingActivity() != null) {
                    return rootTask.getPausingActivity().app;
                }
            }
            return null;
@@ -2709,8 +2709,9 @@ class RootWindowContainer extends WindowContainer<DisplayContent>

        if (DEBUG_SWITCH) {
            Slog.v(TAG_SWITCH, "Destroying " + r + " in state " + r.getState()
                    + " resumed=" + r.getStack().mResumedActivity + " pausing="
                    + r.getStack().mPausingActivity + " for reason " + mDestroyAllActivitiesReason);
                    + " resumed=" + r.getTask().getResumedActivity() + " pausing="
                    + r.getTask().getPausingActivity() + " for reason "
                    + mDestroyAllActivitiesReason);
        }

        r.destroyImmediately(mDestroyAllActivitiesReason);
@@ -3301,8 +3302,8 @@ class RootWindowContainer extends WindowContainer<DisplayContent>

    boolean allPausedActivitiesComplete() {
        boolean[] pausing = {true};
        final boolean hasActivityNotCompleted = forAllRootTasks(stack -> {
            final ActivityRecord r = stack.mPausingActivity;
        final boolean hasActivityNotCompleted = forAllLeafTasks(task -> {
            final ActivityRecord r = task.getPausingActivity();
            if (r != null && !r.isState(PAUSED, STOPPED, STOPPING, FINISHING)) {
                ProtoLog.d(WM_DEBUG_STATES, "allPausedActivitiesComplete: "
                        + "r=%s state=%s", r, r.getState());
Loading