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

Commit b96eadd5 authored by Riddle Hsu's avatar Riddle Hsu Committed by Automerger Merge Worker
Browse files

Merge "Consider requested orientation for snapshot compatible" into tm-dev am:...

Merge "Consider requested orientation for snapshot compatible" into tm-dev am: 17bfd524 am: 05ea0373

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/17856864



Change-Id: Ife19c0a1f5b2096571d2eea3d7871361d5fe71a0
Ignore-AOSP-First: this is an automerge
Signed-off-by: default avatarAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
parents 2e189a52 05ea0373
Loading
Loading
Loading
Loading
+18 −9
Original line number Original line Diff line number Diff line
@@ -2452,20 +2452,29 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A
            // Obsoleted snapshot.
            // Obsoleted snapshot.
            return false;
            return false;
        }
        }
        final Rect taskBounds = task.getBounds();
        final Point taskSize = snapshot.getTaskSize();
        // Task size has changed? e.g. foldable device.
        if (Math.abs(((float) taskSize.x / Math.max(taskSize.y, 1))
                - ((float) taskBounds.width() / Math.max(taskBounds.height(), 1))) > 0.01f) {
            return false;
        }
        final int rotation = mDisplayContent.rotationForActivityInDifferentOrientation(this);
        final int rotation = mDisplayContent.rotationForActivityInDifferentOrientation(this);
        final int currentRotation = task.getWindowConfiguration().getRotation();
        final int targetRotation = rotation != ROTATION_UNDEFINED
        final int targetRotation = rotation != ROTATION_UNDEFINED
                // The display may rotate according to the orientation of this activity.
                // The display may rotate according to the orientation of this activity.
                ? rotation
                ? rotation
                // The activity won't change display orientation.
                // The activity won't change display orientation.
                : task.getWindowConfiguration().getRotation();
                : currentRotation;
        return snapshot.getRotation() == targetRotation;
        if (snapshot.getRotation() != targetRotation) {
            return false;
        }
        final Rect taskBounds = task.getBounds();
        int w = taskBounds.width();
        int h = taskBounds.height();
        final Point taskSize = snapshot.getTaskSize();
        if ((Math.abs(currentRotation - targetRotation) % 2) == 1) {
            // Flip the size if the activity will show in 90 degree difference.
            final int t = w;
            w = h;
            h = t;
        }
        // Task size might be changed with the same rotation such as on a foldable device.
        return Math.abs(((float) taskSize.x / Math.max(taskSize.y, 1))
                - ((float) w / Math.max(h, 1))) <= 0.01f;
    }
    }


    /**
    /**
+17 −2
Original line number Original line Diff line number Diff line
@@ -1896,10 +1896,13 @@ public class ActivityRecordTests extends WindowTestsBase {
        final ActivityRecord activity = createActivityWithTask();
        final ActivityRecord activity = createActivityWithTask();
        final Task task = activity.getTask();
        final Task task = activity.getTask();
        final Rect taskBounds = task.getBounds();
        final Rect taskBounds = task.getBounds();
        final int currentRotation = mDisplayContent.getRotation();
        final int w = taskBounds.width();
        final int h = taskBounds.height();
        final TaskSnapshot snapshot = new TaskSnapshotPersisterTestBase.TaskSnapshotBuilder()
        final TaskSnapshot snapshot = new TaskSnapshotPersisterTestBase.TaskSnapshotBuilder()
                .setTopActivityComponent(activity.mActivityComponent)
                .setTopActivityComponent(activity.mActivityComponent)
                .setRotation(activity.getWindowConfiguration().getRotation())
                .setRotation(currentRotation)
                .setTaskSize(taskBounds.width(), taskBounds.height())
                .setTaskSize(w, h)
                .build();
                .build();


        assertTrue(activity.isSnapshotCompatible(snapshot));
        assertTrue(activity.isSnapshotCompatible(snapshot));
@@ -1909,6 +1912,18 @@ public class ActivityRecordTests extends WindowTestsBase {
        activity.getWindowConfiguration().setBounds(taskBounds);
        activity.getWindowConfiguration().setBounds(taskBounds);


        assertFalse(activity.isSnapshotCompatible(snapshot));
        assertFalse(activity.isSnapshotCompatible(snapshot));

        // Flipped size should be accepted if the activity will show with 90 degree rotation.
        final int targetRotation = currentRotation + 1;
        doReturn(targetRotation).when(mDisplayContent)
                .rotationForActivityInDifferentOrientation(any());
        final TaskSnapshot rotatedSnapshot = new TaskSnapshotPersisterTestBase.TaskSnapshotBuilder()
                .setTopActivityComponent(activity.mActivityComponent)
                .setRotation(targetRotation)
                .setTaskSize(h, w)
                .build();
        task.getWindowConfiguration().getBounds().set(0, 0, w, h);
        assertTrue(activity.isSnapshotCompatible(rotatedSnapshot));
    }
    }


    @Test
    @Test