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

Commit ca8afc4c authored by Riddle Hsu's avatar Riddle Hsu
Browse files

Simplify some legacy path of resume activity

- Simplify the "notUpdated" logic in resumeTopActivity. Because
  configuration change should only either relaunch or dispatch
  change to activity, the purpose of early return is only to
  avoid scheduling. The diff-top condition never satisfies.
- Pass DisplayContent directly to ensureVisibilityAndConfig
  since ATM/WM hierarchy is unified.
- Simplify usages if completeResumeLocked. It doesn't contain
  any IPC so it should never throw exception. And the visibility
  should be set by the callers (resumeTopActivity/realStartActivity)
  rather than itself. That reduces redundant visibility changes
  when launching acitivity while device is locked.

Bug: 163976519
Test: RootWindowContainerTests

Change-Id: I90d68e90ea89bb87171f8f52e74b8b51fae057c8
parent d7c542d1
Loading
Loading
Loading
Loading
+2 −8
Original line number Diff line number Diff line
@@ -659,7 +659,7 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A

    boolean mVoiceInteraction;

    private int mPendingRelaunchCount;
    int mPendingRelaunchCount;
    long mRelaunchStartTime;

    // True if we are current in the process of removing this app token from the display
@@ -3988,7 +3988,7 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A
        // If the display does not have running activity, the configuration may need to be
        // updated for restoring original orientation of the display.
        if (next == null) {
            mRootWindowContainer.ensureVisibilityAndConfig(next, getDisplayId(),
            mRootWindowContainer.ensureVisibilityAndConfig(null /* starting */, mDisplayContent,
                    true /* deferResume */);
        }
        if (activityRemoved) {
@@ -6465,12 +6465,6 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A
     * state to match that fact.
     */
    void completeResumeLocked() {
        final boolean wasVisible = mVisibleRequested;
        setVisibility(true);
        if (!wasVisible) {
            // Visibility has changed, so take a note of it so we call the TaskStackChangedListener
            mTaskSupervisor.mAppVisibilitiesChangedSinceLastPause = true;
        }
        idle = false;
        results = null;
        if (newIntents != null && newIntents.size() > 0) {
+1 −1
Original line number Diff line number Diff line
@@ -1625,7 +1625,7 @@ class ActivityStarter {
        final ActivityRecord currentTop = startedActivityRootTask.topRunningActivity();
        if (currentTop != null && currentTop.shouldUpdateConfigForDisplayChanged()) {
            mRootWindowContainer.ensureVisibilityAndConfig(
                    currentTop, currentTop.getDisplayId(), false /* deferResume */);
                    currentTop, currentTop.mDisplayContent, false /* deferResume */);
        }

        if (!avoidMoveToFront() && mDoResume && mRootWindowContainer
+3 −2
Original line number Diff line number Diff line
@@ -842,7 +842,7 @@ public class ActivityTaskSupervisor implements RecentTasks.Callbacks {
                // Deferring resume here because we're going to launch new activity shortly.
                // We don't want to perform a redundant launch of the same record while ensuring
                // configurations and trying to resume top activity of focused root task.
                mRootWindowContainer.ensureVisibilityAndConfig(r, r.getDisplayId(),
                mRootWindowContainer.ensureVisibilityAndConfig(r, r.mDisplayContent,
                        true /* deferResume */);
            }

@@ -1011,7 +1011,8 @@ public class ActivityTaskSupervisor implements RecentTasks.Callbacks {
        if (andResume && readyToResume()) {
            // As part of the process of launching, ActivityThread also performs
            // a resume.
            rootTask.minimalResumeActivityLocked(r);
            r.setState(RESUMED, "realStartActivityLocked");
            r.completeResumeLocked();
        } else {
            // This activity is not starting in the resumed state... which should look like we asked
            // it to pause+stop (but remain visible), and it has done so and reported back the
+7 −21
Original line number Diff line number Diff line
@@ -1742,30 +1742,21 @@ class RootWindowContainer extends WindowContainer<DisplayContent>
     *
     * @param starting                  The currently starting activity or {@code null} if there is
     *                                  none.
     * @param displayId                 The id of the display where operation is executed.
     * @param displayContent            The display where the operation is executed.
     * @param deferResume               Whether to defer resume while updating config.
     * @return 'true' if starting activity was kept or wasn't provided, 'false' if it was relaunched
     * because of configuration update.
     */
    boolean ensureVisibilityAndConfig(ActivityRecord starting, int displayId, boolean deferResume) {
    void ensureVisibilityAndConfig(@Nullable ActivityRecord starting,
            @NonNull DisplayContent displayContent, boolean deferResume) {
        // First ensure visibility without updating the config just yet. We need this to know what
        // activities are affecting configuration now.
        // Passing null here for 'starting' param value, so that visibility of actual starting
        // activity will be properly updated.
        ensureActivitiesVisible(null /* starting */, false /* notifyClients */);

        if (displayId == INVALID_DISPLAY) {
            // The caller didn't provide a valid display id, skip updating config.
            return true;
        }

        // Force-update the orientation from the WindowManager, since we need the true configuration
        // to send to the client now.
        final DisplayContent displayContent = getDisplayContent(displayId);
        Configuration config = null;
        if (displayContent != null) {
            config = displayContent.updateOrientation(starting, true /* forceUpdate */);
        }
        final Configuration config =
                displayContent.updateOrientation(starting, true /* forceUpdate */);
        // Visibilities may change so let the starting activity have a chance to report. Can't do it
        // when visibility is changed in each AppWindowToken because it may trigger wrong
        // configuration push because the visibility of some activities may not be updated yet.
@@ -1773,13 +1764,8 @@ class RootWindowContainer extends WindowContainer<DisplayContent>
            starting.reportDescendantOrientationChangeIfNeeded();
        }

        if (displayContent != null) {
        // Update the configuration of the activities on the display.
            return displayContent.updateDisplayOverrideConfigurationLocked(config, starting,
                    deferResume);
        } else {
            return true;
        }
        displayContent.updateDisplayOverrideConfigurationLocked(config, starting, deferResume);
    }

    /**
+1 −8
Original line number Diff line number Diff line
@@ -4946,13 +4946,6 @@ class Task extends TaskFragment {
        }
    }

    void minimalResumeActivityLocked(ActivityRecord r) {
        ProtoLog.v(WM_DEBUG_STATES, "Moving to RESUMED: %s (starting new instance) "
                + "callers=%s", r, Debug.getCallers(5));
        r.setState(RESUMED, "minimalResumeActivityLocked");
        r.completeResumeLocked();
    }

    void checkReadyForSleep() {
        if (shouldSleepActivities() && goToSleepIfPossible(false /* shuttingDown */)) {
            mTaskSupervisor.checkReadyForSleepLocked(true /* allowDelay */);
@@ -5861,7 +5854,7 @@ class Task extends TaskFragment {
            }

            mRootWindowContainer.ensureVisibilityAndConfig(null /* starting */,
                    mDisplayContent.mDisplayId, false /* deferResume */);
                    mDisplayContent, false /* deferResume */);
        } finally {
            if (mTransitionController.isShellTransitionsEnabled()) {
                mAtmService.continueWindowLayout();
Loading