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

Commit e75e191b authored by Hongwei Wang's avatar Hongwei Wang
Browse files

Fixes regression on preserving PiP position

The reentry fraction of PiP is used to be saved in
ActivityRecord.onConfigurationChanged when activity leaves PiP mode to
fullscreen. With ag/9539033, the pinned stack gets removed ahead of this
configuration change and therefore, there is no bounds to save.

The new approach is to move the saving logic to TaskRecord.reparent,
right before the pinned stack is removed due to reparenting.

Bug: 144099989
Test: atest PinnedStackTests#testEnterPictureInPictureSavePosition
Change-Id: Iceaf7244f16ed0ca1450e3117b85fd6b3d97313c
parent d660afae
Loading
Loading
Loading
Loading
+24 −32
Original line number Diff line number Diff line
@@ -42,9 +42,7 @@ import static android.app.WindowConfiguration.ACTIVITY_TYPE_RECENTS;
import static android.app.WindowConfiguration.ACTIVITY_TYPE_UNDEFINED;
import static android.app.WindowConfiguration.ROTATION_UNDEFINED;
import static android.app.WindowConfiguration.WINDOWING_MODE_FREEFORM;
import static android.app.WindowConfiguration.WINDOWING_MODE_PINNED;
import static android.app.WindowConfiguration.WINDOWING_MODE_SPLIT_SCREEN_PRIMARY;
import static android.app.WindowConfiguration.WINDOWING_MODE_UNDEFINED;
import static android.app.WindowConfiguration.activityTypeToString;
import static android.content.Intent.ACTION_MAIN;
import static android.content.Intent.CATEGORY_HOME;
@@ -6529,7 +6527,11 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A
            updateSurfacePosition();
        }

        adjustPinnedStackAndInitChangeTransitionIfNeeded(prevWinMode, getWindowingMode());
        final int newWinMode = getWindowingMode();
        if ((prevWinMode != newWinMode) && (mDisplayContent != null)
                && shouldStartChangeTransition(prevWinMode, newWinMode)) {
            initializeChangeTransition(mTmpPrevBounds);
        }

        // Configuration's equality doesn't consider seq so if only seq number changes in resolved
        // override configuration. Therefore ConfigurationContainer doesn't change merged override
@@ -6563,17 +6565,11 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A
        }
    }

    private void adjustPinnedStackAndInitChangeTransitionIfNeeded(int prevWinMode, int winMode) {
        if (prevWinMode == winMode || mDisplayContent == null) {
            return;
        }

        if (prevWinMode == WINDOWING_MODE_PINNED && winMode != WINDOWING_MODE_UNDEFINED
                && !isHidden()) {
    void savePinnedStackBounds() {
        // Leaving PiP to fullscreen, save the snap fraction based on the pre-animation bounds
        // for the next re-entry into PiP (assuming the activity is not hidden or destroyed)
        final TaskStack pinnedStack = mDisplayContent.getPinnedStack();
            if (pinnedStack != null) {
        if (pinnedStack == null) return;
        final Rect stackBounds;
        if (pinnedStack.lastAnimatingBoundsWasToFullscreen()) {
            // We are animating the bounds, use the pre-animation bounds to save the snap
@@ -6589,10 +6585,6 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A
        mDisplayContent.mPinnedStackControllerLocked.saveReentrySnapFraction(
                mActivityComponent, stackBounds);
    }
        } else if (shouldStartChangeTransition(prevWinMode, winMode)) {
            initializeChangeTransition(mTmpPrevBounds);
        }
    }

    /** Returns true if the configuration is compatible with this activity. */
    boolean isConfigurationCompatible(Configuration config) {
+7 −0
Original line number Diff line number Diff line
@@ -587,6 +587,13 @@ class TaskRecord extends Task {
        boolean kept = true;
        try {
            final ActivityRecord r = topRunningActivityLocked();
            // give pinned stack a chance to save current bounds, this needs to be before the
            // actual reparent.
            if (inPinnedWindowingMode()
                    && !(toStackWindowingMode == WINDOWING_MODE_UNDEFINED)
                    && !r.isHidden()) {
                r.savePinnedStackBounds();
            }
            final boolean wasFocused = r != null && root.isTopDisplayFocusedStack(sourceStack)
                    && (topRunningActivityLocked() == r);
            final boolean wasResumed = r != null && sourceStack.getResumedActivity() == r;