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

Commit 441cb423 authored by wilsonshih's avatar wilsonshih
Browse files

[Back Navi] Fix fixed rotation doesn't work for cross animation.

Core will need to start fixed rotation on previous activity before
create animation leash, otherwise there won't do updateSurfaceRotation
if animation leash was create.
Also preventing from layout letterbox if the activity is stopped.
Currently there will layout letterbox to the closed activity in
destroySurface, and if the orientation of the closed activity isn't
align with display, the letterbox would be weird. But after all, the
letterbox should be hide at that moment.
Ref: ag/3381739, ag/22335688

Bug: 320902067
Test: verify the skew transfer will apply on opening target for both
cross-task and cross-activity animation.
Test: atest LetterboxUiControllerTest

Change-Id: Ic2d85fde708fb079242b1870da0780251d2ba741
parent 456d99d8
Loading
Loading
Loading
Loading
+14 −4
Original line number Diff line number Diff line
@@ -2631,10 +2631,20 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A
        if (snapshot == null) {
            return false;
        }
        if (!snapshot.getTopActivityComponent().equals(mActivityComponent)) {
            // Obsoleted snapshot.
            return false;
        return isSnapshotComponentCompatible(snapshot) && isSnapshotOrientationCompatible(snapshot);
    }

    /**
     * Returns {@code true} if the top activity component of task snapshot equals to this activity.
     */
    boolean isSnapshotComponentCompatible(@NonNull TaskSnapshot snapshot) {
        return snapshot.getTopActivityComponent().equals(mActivityComponent);
    }

    /**
     * Returns {@code true} if the orientation of task snapshot is compatible with this activity.
     */
    boolean isSnapshotOrientationCompatible(@NonNull TaskSnapshot snapshot) {
        final int rotation = mDisplayContent.rotationForActivityInDifferentOrientation(this);
        final int currentRotation = task.getWindowConfiguration().getRotation();
        final int targetRotation = rotation != ROTATION_UNDEFINED
+35 −16
Original line number Diff line number Diff line
@@ -938,6 +938,18 @@ class BackNavigationController {
                return;
            }

            // Start fixed rotation for previous activity before create animation.
            if (openingActivities.length == 1) {
                final ActivityRecord next = openingActivities[0];
                final DisplayContent dc = next.mDisplayContent;
                dc.rotateInDifferentOrientationIfNeeded(next);
                if (next.hasFixedRotationTransform()) {
                    // Set the record so we can recognize it to continue to update display
                    // orientation if the previous activity becomes the top later.
                    dc.setFixedRotationLaunchingApp(next,
                            next.getWindowConfiguration().getRotation());
                }
            }
            mOpenAnimAdaptor = new BackWindowAnimationAdaptorWrapper(true, mSwitchType, open);
            if (!mOpenAnimAdaptor.isValid()) {
                Slog.w(TAG, "compose animations fail, skip");
@@ -1603,16 +1615,6 @@ class BackNavigationController {
        }
        activity.mLaunchTaskBehind = true;

        // Handle fixed rotation launching app.
        final DisplayContent dc = activity.mDisplayContent;
        dc.rotateInDifferentOrientationIfNeeded(activity);
        if (activity.hasFixedRotationTransform()) {
            // Set the record so we can recognize it to continue to update display
            // orientation if the previous activity becomes the top later.
            dc.setFixedRotationLaunchingApp(activity,
                    activity.getWindowConfiguration().getRotation());
        }

        ProtoLog.d(WM_DEBUG_BACK_PREVIEW,
                "Setting Activity.mLauncherTaskBehind to true. Activity=%s", activity);
        activity.mTaskSupervisor.mStoppingActivities.remove(activity);
@@ -1680,20 +1682,37 @@ class BackNavigationController {

    static TaskSnapshot getSnapshot(@NonNull WindowContainer w,
            ActivityRecord[] visibleOpenActivities) {
        TaskSnapshot snapshot = null;
        if (w.asTask() != null) {
            final Task task = w.asTask();
            return task.mRootWindowContainer.mWindowManager.mTaskSnapshotController.getSnapshot(
            snapshot = task.mRootWindowContainer.mWindowManager.mTaskSnapshotController.getSnapshot(
                    task.mTaskId, task.mUserId, false /* restoreFromDisk */,
                    false /* isLowResolution */);
        }

        if (w.asActivityRecord() != null) {
        } else if (w.asActivityRecord() != null) {
            final ActivityRecord ar = w.asActivityRecord();
            return ar.mWmService.mSnapshotController.mActivitySnapshotController
            snapshot = ar.mWmService.mSnapshotController.mActivitySnapshotController
                    .getSnapshot(visibleOpenActivities);
        }
        return null;

        return isSnapshotCompatible(snapshot, visibleOpenActivities) ? snapshot : null;
    }

    static boolean isSnapshotCompatible(@NonNull TaskSnapshot snapshot,
            @NonNull ActivityRecord[] visibleOpenActivities) {
        if (snapshot == null) {
            return false;
        }
        boolean oneComponentMatch = false;
        for (int i = visibleOpenActivities.length - 1; i >= 0; --i) {
            final ActivityRecord ar = visibleOpenActivities[i];
            if (!ar.isSnapshotOrientationCompatible(snapshot)) {
                return false;
            }
            oneComponentMatch |= ar.isSnapshotComponentCompatible(snapshot);
        }
        return oneComponentMatch;
    }


    void setWindowManager(WindowManagerService wm) {
        mWindowManagerService = wm;
+1 −8
Original line number Diff line number Diff line
@@ -1424,7 +1424,7 @@ final class LetterboxUiController {

    @VisibleForTesting
    boolean shouldShowLetterboxUi(WindowState mainWindow) {
        if (mIsRelaunchingAfterRequestedOrientationChanged || !isSurfaceReadyToShow(mainWindow)) {
        if (mIsRelaunchingAfterRequestedOrientationChanged) {
            return mLastShouldShowLetterboxUi;
        }

@@ -1441,13 +1441,6 @@ final class LetterboxUiController {
        return shouldShowLetterboxUi;
    }

    @VisibleForTesting
    boolean isSurfaceReadyToShow(WindowState mainWindow) {
        return mainWindow.isDrawn() // Regular case
                // Waiting for relayoutWindow to call preserveSurface
                || mainWindow.isDragResizeChanged();
    }

    @VisibleForTesting
    boolean isSurfaceVisible(WindowState mainWindow) {
        return mainWindow.isOnScreen() && (mActivityRecord.isVisible()
+0 −2
Original line number Diff line number Diff line
@@ -881,8 +881,6 @@ public class SizeCompatTests extends WindowTestsBase {
        assertEquals(window, mActivity.findMainWindow());

        spyOn(mActivity.mLetterboxUiController);
        doReturn(true).when(mActivity.mLetterboxUiController)
                .isSurfaceReadyToShow(any());
        doReturn(true).when(mActivity.mLetterboxUiController)
                .isSurfaceVisible(any());