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

Commit 061ce29f authored by Riddle Hsu's avatar Riddle Hsu
Browse files

Make the condition of preserveWindows consistent

Remove preserveWindows:
 It was confusing that the callers pass the parameter randomly.
 But the final condition is still filtered by
  "isResizeOnlyChange(changes) && !mFreezingScreen;"
 in AR#ensureActivityConfiguration.
 So concentrate the decision there. Also add a condition to
 not preserve for rotation change temporarily, until the
 problem of re-show IME is resolved.

Remove globalChanges:
 It is used for freezing screen that is no-op with shell transition.
 Temporarily use UpdateConfigurationResult to keep original behavior.

Bug: 258618073
Test: ActivityRecordTests DisplayContentTests

Change-Id: Ifa95f4d74551a30650ea1f046f0e5f25400cb84d
parent 96bbd316
Loading
Loading
Loading
Loading
+32 −38
Original line number Diff line number Diff line
@@ -222,7 +222,6 @@ import static com.android.server.wm.ActivityTaskManagerService.RELAUNCH_REASON_F
import static com.android.server.wm.ActivityTaskManagerService.RELAUNCH_REASON_NONE;
import static com.android.server.wm.ActivityTaskManagerService.RELAUNCH_REASON_WINDOWING_MODE_RESIZE;
import static com.android.server.wm.ActivityTaskManagerService.getInputDispatchingTimeoutMillisLocked;
import static com.android.server.wm.ActivityTaskSupervisor.PRESERVE_WINDOWS;
import static com.android.server.wm.IdentifierProto.HASH_CODE;
import static com.android.server.wm.IdentifierProto.TITLE;
import static com.android.server.wm.IdentifierProto.USER_ID;
@@ -947,7 +946,7 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A
    private int mConfigurationSeq;

    /**
     * Temp configs used in {@link #ensureActivityConfiguration(int, boolean)}
     * Temp configs used in {@link #ensureActivityConfiguration()}
     */
    private final Configuration mTmpConfig = new Configuration();
    private final Rect mTmpBounds = new Rect();
@@ -1509,7 +1508,7 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A
                updatePictureInPictureMode(null, false);
            } else {
                mLastReportedMultiWindowMode = inMultiWindowMode;
                ensureActivityConfiguration(0 /* globalChanges */, PRESERVE_WINDOWS);
                ensureActivityConfiguration();
            }
        }
    }
@@ -1528,8 +1527,7 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A
            // precede the configuration change from the resize.
            mLastReportedPictureInPictureMode = inPictureInPictureMode;
            mLastReportedMultiWindowMode = inPictureInPictureMode;
            ensureActivityConfiguration(0 /* globalChanges */, PRESERVE_WINDOWS,
                    true /* ignoreVisibility */);
            ensureActivityConfiguration(true /* ignoreVisibility */);
            if (inPictureInPictureMode && findMainWindow() == null) {
                // Prevent malicious app entering PiP without valid WindowState, which can in turn
                // result a non-touchable PiP window since the InputConsumer for PiP requires it.
@@ -3105,7 +3103,7 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A
        // {@link #returningOptions} of the activity under this one can be applied in
        // {@link #handleAlreadyVisible()}.
        if (changed || !occludesParent) {
            mRootWindowContainer.ensureActivitiesVisible(null, 0, !PRESERVE_WINDOWS);
            mRootWindowContainer.ensureActivitiesVisible();
        }
        return changed;
    }
@@ -3745,8 +3743,8 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A
            }

            if (ensureVisibility) {
                mDisplayContent.ensureActivitiesVisible(null /* starting */, 0 /* configChanges */,
                        false /* preserveWindows */, true /* notifyClients */);
                mDisplayContent.ensureActivitiesVisible(null /* starting */,
                        true /* notifyClients */);
            }
        }

@@ -4163,8 +4161,7 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A
        if (rootTask != null && rootTask.shouldSleepOrShutDownActivities()) {
            // Activity is always relaunched to either resumed or paused state. If it was
            // relaunched while hidden (by keyguard or smth else), it should be stopped.
            rootTask.ensureActivitiesVisible(null /* starting */, 0 /* configChanges */,
                    false /* preserveWindows */);
            rootTask.ensureActivitiesVisible(null /* starting */);
        }
    }

@@ -4679,14 +4676,12 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A

    void setShowWhenLocked(boolean showWhenLocked) {
        mShowWhenLocked = showWhenLocked;
        mAtmService.mRootWindowContainer.ensureActivitiesVisible(null /* starting */,
                0 /* configChanges */, false /* preserveWindows */);
        mAtmService.mRootWindowContainer.ensureActivitiesVisible();
    }

    void setInheritShowWhenLocked(boolean inheritShowWhenLocked) {
        mInheritShownWhenLocked = inheritShowWhenLocked;
        mAtmService.mRootWindowContainer.ensureActivitiesVisible(null /* starting */,
                0 /* configChanges */, false /* preserveWindows */);
        mAtmService.mRootWindowContainer.ensureActivitiesVisible();
    }

    /**
@@ -6406,7 +6401,7 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A
        }

        mDisplayContent.handleActivitySizeCompatModeIfNeeded(this);
        mRootWindowContainer.ensureActivitiesVisible(null, 0, !PRESERVE_WINDOWS);
        mRootWindowContainer.ensureActivitiesVisible();
    }

    /**
@@ -7887,7 +7882,7 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A
    void applyFixedRotationTransform(DisplayInfo info, DisplayFrames displayFrames,
            Configuration config) {
        super.applyFixedRotationTransform(info, displayFrames, config);
        ensureActivityConfiguration(0 /* globalChanges */, false /* preserveWindow */);
        ensureActivityConfiguration();
    }

    /**
@@ -7982,7 +7977,7 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A
        startFreezingScreen(originalDisplayRotation);
        // This activity may relaunch or perform configuration change so once it has reported drawn,
        // the screen can be unfrozen.
        ensureActivityConfiguration(0 /* globalChanges */, !PRESERVE_WINDOWS);
        ensureActivityConfiguration();
        if (mTransitionController.isCollecting(this)) {
            // In case the task was changed from PiP but still keeps old transform.
            task.resetSurfaceControlTransforms();
@@ -8010,7 +8005,7 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A
        // the request is handled at task level with letterbox.
        if (!getMergedOverrideConfiguration().equals(
                mLastReportedConfiguration.getMergedConfiguration())) {
            ensureActivityConfiguration(0 /* globalChanges */, false /* preserveWindow */,
            ensureActivityConfiguration(
                    false /* ignoreVisibility */, true /* isRequestedOrientationChanged */);
            if (mTransitionController.inPlayingTransition(this)) {
                mTransitionController.mValidateActivityCompat.add(this);
@@ -9518,14 +9513,12 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A
        return mLastReportedDisplayId != getDisplayId();
    }

    boolean ensureActivityConfiguration(int globalChanges, boolean preserveWindow) {
        return ensureActivityConfiguration(globalChanges, preserveWindow,
                false /* ignoreVisibility */, false /* isRequestedOrientationChanged */);
    boolean ensureActivityConfiguration() {
        return ensureActivityConfiguration(false /* ignoreVisibility */);
    }

    boolean ensureActivityConfiguration(int globalChanges, boolean preserveWindow,
            boolean ignoreVisibility) {
        return ensureActivityConfiguration(globalChanges, preserveWindow, ignoreVisibility,
    boolean ensureActivityConfiguration(boolean ignoreVisibility) {
        return ensureActivityConfiguration(ignoreVisibility,
                false /* isRequestedOrientationChanged */);
    }

@@ -9533,9 +9526,6 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A
     * Make sure the given activity matches the current configuration. Ensures the HistoryRecord
     * is updated with the correct configuration and all other bookkeeping is handled.
     *
     * @param globalChanges The changes to the global configuration.
     * @param preserveWindow If the activity window should be preserved on screen if the activity
     *                       is relaunched.
     * @param ignoreVisibility If we should try to relaunch the activity even if it is invisible
     *                         (stopped state). This is useful for the case where we know the
     *                         activity will be visible soon and we want to ensure its configuration
@@ -9545,8 +9535,8 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A
     * @return False if the activity was relaunched and true if it wasn't relaunched because we
     *         can't or the app handles the specific configuration that is changing.
     */
    boolean ensureActivityConfiguration(int globalChanges, boolean preserveWindow,
            boolean ignoreVisibility, boolean isRequestedOrientationChanged) {
    boolean ensureActivityConfiguration(boolean ignoreVisibility,
            boolean isRequestedOrientationChanged) {
        final Task rootTask = getRootTask();
        if (rootTask.mConfigWillChange) {
            ProtoLog.v(WM_DEBUG_CONFIGURATION, "Skipping config check "
@@ -9660,10 +9650,21 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A
        if (shouldRelaunchLocked(changes, mTmpConfig)) {
            // Aha, the activity isn't handling the change, so DIE DIE DIE.
            configChangeFlags |= changes;
            startFreezingScreenLocked(globalChanges);
            if (mVisible && mAtmService.mTmpUpdateConfigurationResult.mIsUpdating
                    && !mTransitionController.isShellTransitionsEnabled()) {
                startFreezingScreenLocked(mAtmService.mTmpUpdateConfigurationResult.changes);
            }
            final boolean displayMayChange = mTmpConfig.windowConfiguration.getDisplayRotation()
                    != getWindowConfiguration().getDisplayRotation()
                    || !mTmpConfig.windowConfiguration.getMaxBounds().equals(
                            getWindowConfiguration().getMaxBounds());
            final boolean isAppResizeOnly = !displayMayChange
                    && (changes & ~(CONFIG_SCREEN_SIZE | CONFIG_SMALLEST_SCREEN_SIZE
                            | CONFIG_ORIENTATION | CONFIG_SCREEN_LAYOUT)) == 0;
            // Do not preserve window if it is freezing screen because the original window won't be
            // able to update drawn state that causes freeze timeout.
            preserveWindow &= isResizeOnlyChange(changes) && !mFreezingScreen;
            // TODO(b/258618073): Always preserve if possible.
            final boolean preserveWindow = isAppResizeOnly && !mFreezingScreen;
            final boolean hasResizeChange = hasResizeChange(changes & ~info.getRealConfigChanged());
            if (hasResizeChange) {
                final boolean isDragResizing = task.isDragResizing();
@@ -9827,11 +9828,6 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A
        return changes;
    }

    private static boolean isResizeOnlyChange(int change) {
        return (change & ~(CONFIG_SCREEN_SIZE | CONFIG_SMALLEST_SCREEN_SIZE | CONFIG_ORIENTATION
                | CONFIG_SCREEN_LAYOUT)) == 0;
    }

    private static boolean hasResizeChange(int change) {
        return (change & (CONFIG_SCREEN_SIZE | CONFIG_SMALLEST_SCREEN_SIZE | CONFIG_ORIENTATION
                | CONFIG_SCREEN_LAYOUT)) != 0;
@@ -9875,8 +9871,6 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A
                    task.mTaskId, shortComponentName, Integer.toHexString(configChangeFlags));
        }

        startFreezingScreenLocked(0);

        try {
            ProtoLog.i(WM_DEBUG_STATES, "Moving to %s Relaunching %s callers=%s" ,
                    (andResume ? "RESUMED" : "PAUSED"), this, Debug.getCallers(6));
+2 −4
Original line number Diff line number Diff line
@@ -73,7 +73,6 @@ import static com.android.server.wm.ActivityTaskManagerDebugConfig.TAG_WITH_CLAS
import static com.android.server.wm.ActivityTaskManagerService.ANIMATE;
import static com.android.server.wm.ActivityTaskSupervisor.DEFER_RESUME;
import static com.android.server.wm.ActivityTaskSupervisor.ON_TOP;
import static com.android.server.wm.ActivityTaskSupervisor.PRESERVE_WINDOWS;
import static com.android.server.wm.BackgroundActivityStartController.BAL_ALLOW_DEFAULT;
import static com.android.server.wm.BackgroundActivityStartController.BAL_BLOCK;
import static com.android.server.wm.LaunchParamsController.LaunchParamsModifier.PHASE_BOUNDS;
@@ -1848,8 +1847,7 @@ class ActivityStarter {
                // over is removed.
                // Passing {@code null} as the start parameter ensures all activities are made
                // visible.
                mTargetRootTask.ensureActivitiesVisible(null /* starting */,
                        0 /* configChanges */, !PRESERVE_WINDOWS);
                mTargetRootTask.ensureActivitiesVisible(null /* starting */);
                // Go ahead and tell window manager to execute app transition for this activity
                // since the app transition will not be triggered through the resume channel.
                mTargetRootTask.mDisplayContent.executeAppTransition();
@@ -2856,7 +2854,7 @@ class ActivityStarter {
                mRootWindowContainer.resumeFocusedTasksTopActivities(mTargetRootTask, null,
                        mOptions, mTransientLaunch);
            } else {
                mRootWindowContainer.ensureActivitiesVisible(null, 0, !PRESERVE_WINDOWS);
                mRootWindowContainer.ensureActivitiesVisible();
            }
        } else {
            ActivityOptions.abort(mOptions);
+10 −25
Original line number Diff line number Diff line
@@ -117,7 +117,6 @@ import static com.android.server.wm.ActivityTaskManagerService.H.REPORT_TIME_TRA
import static com.android.server.wm.ActivityTaskManagerService.UiHandler.DISMISS_DIALOG_UI_MSG;
import static com.android.server.wm.ActivityTaskSupervisor.DEFER_RESUME;
import static com.android.server.wm.ActivityTaskSupervisor.ON_TOP;
import static com.android.server.wm.ActivityTaskSupervisor.PRESERVE_WINDOWS;
import static com.android.server.wm.ActivityTaskSupervisor.REMOVE_FROM_RECENTS;
import static com.android.server.wm.BackgroundActivityStartController.BalVerdict;
import static com.android.server.wm.LockTaskController.LOCK_TASK_AUTH_DONT_LOCK;
@@ -495,16 +494,13 @@ public class ActivityTaskManagerService extends IActivityTaskManager.Stub {
    final UpdateConfigurationResult mTmpUpdateConfigurationResult =
            new UpdateConfigurationResult();

    // TODO(b/258618073): Remove this and make the related methods return whether config is changed.
    static final class UpdateConfigurationResult {
        // Configuration changes that were updated.
        int changes;
        // If the activity was relaunched to match the new configuration.
        boolean activityRelaunched;

        void reset() {
            changes = 0;
            activityRelaunched = false;
        }
        boolean mIsUpdating;
    }

    /** Current sequencing integer of the configuration, for skipping old configurations. */
@@ -3828,8 +3824,7 @@ public class ActivityTaskManagerService extends IActivityTaskManager.Stub {
                    Settings.System.clearConfiguration(values);
                }
                updateConfigurationLocked(values, null, false, false /* persistent */,
                        UserHandle.USER_NULL, false /* deferResume */,
                        mTmpUpdateConfigurationResult);
                        UserHandle.USER_NULL, false /* deferResume */);
                return mTmpUpdateConfigurationResult.changes != 0;
            } finally {
                Binder.restoreCallingIdentity(origId);
@@ -4501,12 +4496,6 @@ public class ActivityTaskManagerService extends IActivityTaskManager.Stub {
        }
    }

    private boolean updateConfigurationLocked(Configuration values, ActivityRecord starting,
            boolean initLocale, boolean persistent, int userId, boolean deferResume) {
        return updateConfigurationLocked(values, starting, initLocale, persistent, userId,
                deferResume, null /* result */);
    }

    /**
     * Do either or both things: (1) change the current configuration, and (2)
     * make sure the given activity is running with the (now) current
@@ -4518,8 +4507,7 @@ public class ActivityTaskManagerService extends IActivityTaskManager.Stub {
     *               for that particular user
     */
    boolean updateConfigurationLocked(Configuration values, ActivityRecord starting,
            boolean initLocale, boolean persistent, int userId, boolean deferResume,
            ActivityTaskManagerService.UpdateConfigurationResult result) {
            boolean initLocale, boolean persistent, int userId, boolean deferResume) {
        int changes = 0;
        boolean kept = true;

@@ -4527,19 +4515,18 @@ public class ActivityTaskManagerService extends IActivityTaskManager.Stub {
        try {
            if (values != null) {
                changes = updateGlobalConfigurationLocked(values, initLocale, persistent, userId);
                mTmpUpdateConfigurationResult.changes = changes;
                mTmpUpdateConfigurationResult.mIsUpdating = true;
            }

            if (!deferResume) {
                kept = ensureConfigAndVisibilityAfterUpdate(starting, changes);
            }
        } finally {
            mTmpUpdateConfigurationResult.mIsUpdating = false;
            continueWindowLayout();
        }

        if (result != null) {
            result.changes = changes;
            result.activityRelaunched = !kept;
        }
        mTmpUpdateConfigurationResult.activityRelaunched = !kept;
        return kept;
    }

@@ -5319,12 +5306,10 @@ public class ActivityTaskManagerService extends IActivityTaskManager.Stub {
            }

            if (starting != null) {
                kept = starting.ensureActivityConfiguration(changes,
                        false /* preserveWindow */);
                kept = starting.ensureActivityConfiguration();
                // And we need to make sure at this point that all other activities
                // are made visible with the correct configuration.
                mRootWindowContainer.ensureActivitiesVisible(starting, changes,
                        !PRESERVE_WINDOWS);
                mRootWindowContainer.ensureActivitiesVisible(starting);
            }
        }

+5 −5
Original line number Diff line number Diff line
@@ -1462,7 +1462,7 @@ public class ActivityTaskSupervisor implements RecentTasks.Callbacks {
                }
                mLaunchingActivityWakeLock.release();
            }
            mRootWindowContainer.ensureActivitiesVisible(null, 0, !PRESERVE_WINDOWS);
            mRootWindowContainer.ensureActivitiesVisible();
        }

        // Atomically retrieve all of the other things to do.
@@ -1603,7 +1603,7 @@ public class ActivityTaskSupervisor implements RecentTasks.Callbacks {
         */
        rootTask.cancelAnimation();
        rootTask.setForceHidden(FLAG_FORCE_HIDDEN_FOR_PINNED_TASK, true /* set */);
        rootTask.ensureActivitiesVisible(null, 0, PRESERVE_WINDOWS);
        rootTask.ensureActivitiesVisible(null /* starting */);
        activityIdleInternal(null /* idleActivity */, false /* fromTimeout */,
                true /* processPausingActivities */, null /* configuration */);

@@ -1622,7 +1622,7 @@ public class ActivityTaskSupervisor implements RecentTasks.Callbacks {
            // Follow on the workaround: activities are kept force hidden till the new windowing
            // mode is set.
            rootTask.setForceHidden(FLAG_FORCE_HIDDEN_FOR_PINNED_TASK, false /* set */);
            mRootWindowContainer.ensureActivitiesVisible(null, 0, PRESERVE_WINDOWS);
            mRootWindowContainer.ensureActivitiesVisible();
            mRootWindowContainer.resumeFocusedTasksTopActivities();
        } finally {
            mService.continueWindowLayout();
@@ -2026,7 +2026,7 @@ public class ActivityTaskSupervisor implements RecentTasks.Callbacks {

        final Task rootTask = r.getRootTask();
        if (rootTask.getDisplayArea().allResumedActivitiesComplete()) {
            mRootWindowContainer.ensureActivitiesVisible(null, 0, !PRESERVE_WINDOWS);
            mRootWindowContainer.ensureActivitiesVisible();
            // Make sure activity & window visibility should be identical
            // for all displays in this stage.
            mRootWindowContainer.executeAppTransitionForAllDisplay();
@@ -2042,7 +2042,7 @@ public class ActivityTaskSupervisor implements RecentTasks.Callbacks {

        mRecentTasks.add(task);
        mService.getTaskChangeNotificationController().notifyTaskStackChanged();
        rootTask.ensureActivitiesVisible(null, 0, !PRESERVE_WINDOWS);
        rootTask.ensureActivitiesVisible(null /* starting */);

        // When launching tasks behind, update the last active time of the top task after the new
        // task has been shown briefly
+1 −1
Original line number Diff line number Diff line
@@ -1614,7 +1614,7 @@ class BackNavigationController {
                "Setting Activity.mLauncherTaskBehind to true. Activity=%s", activity);
        activity.mTaskSupervisor.mStoppingActivities.remove(activity);
        activity.getDisplayContent().ensureActivitiesVisible(null /* starting */,
                0 /* configChanges */, false /* preserveWindows */, true);
                true /* notifyClients */);
    }

    private static void restoreLaunchBehind(@NonNull ActivityRecord activity) {
Loading