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

Commit d3623f77 authored by Ikram Gabiyev's avatar Ikram Gabiyev
Browse files

Properly propagate rotation onDisplayChange

This CL does a couple of things:
  - when we receive IDisplayChangeWindowController remote
display change from Core, we should allow rotation changes
to be propagated into updating display layouts too.
  - when updateDisplayLayout() is run, if rotation has happened
along with display size change, the dimensions of endBounds are
already in the new orientation. So we should rotate the local
displayLayout before resizing it.

Bug: 432725672
Flag: EXEMPT bugfix
Test: manually repro the steps in the bug
Change-Id: I9c361609a9df896029026a155340e3bda440265f
parent 1df82b36
Loading
Loading
Loading
Loading
+3 −2
Original line number Diff line number Diff line
@@ -102,13 +102,14 @@ public class DisplayChangeController {
    void onDisplayChange(int displayId, int fromRotation, int toRotation,
            DisplayAreaInfo newDisplayAreaInfo, IDisplayChangeWindowCallback callback) {
        final DisplayLayout dl = mDisplayController.getDisplayLayout(displayId);
        if (dl != null && newDisplayAreaInfo != null) {
        if (dl != null) {
            // Note: there is a chance Transitions has triggered
            // DisplayController#onDisplayChangeRequested first, in which case layout was updated
            // and startBounds equals endBounds; then DisplayLayout size remains the same.
            // TODO(b/370721807): Remove DisplayChangeWindowControllerImpl and rely on transitions.
            final Rect startBounds = new Rect(0, 0, dl.width(), dl.height());
            final Rect endBounds = newDisplayAreaInfo.configuration.windowConfiguration.getBounds();
            final Rect endBounds = newDisplayAreaInfo != null
                    ? newDisplayAreaInfo.configuration.windowConfiguration.getBounds() : null;
            mDisplayController.updateDisplayLayout(displayId, startBounds, endBounds,
                    fromRotation, toRotation);
        }
+11 −6
Original line number Diff line number Diff line
@@ -247,13 +247,18 @@ public class DisplayController {
        final Context ctx = getDisplayContext(displayId);
        if (dl == null || ctx == null) return;

        if (endBounds != null) {
            // Note that endAbsBounds should ignore any potential rotation changes, so
            // we still need to rotate the layout after if needed.
            dl.resizeTo(ctx.getResources(), new Size(endBounds.width(), endBounds.height()));
        }
        if (fromRotation != toRotation && toRotation != ROTATION_UNDEFINED) {
        boolean hasRotationChanged = fromRotation != toRotation && toRotation != ROTATION_UNDEFINED;
        final Size endSize = endBounds != null
                ? new Size(endBounds.width(), endBounds.height()) : null;

        if (hasRotationChanged && endSize != null) {
            // If rotation and display size are happening in sync, we have to follow a convention
            // that DisplayLayout implements.
            dl.rotateAndResizeTo(ctx.getResources(), toRotation, endSize);
        } else if (hasRotationChanged) {
            dl.rotateTo(ctx.getResources(), toRotation);
        } else if (endBounds != null) {
            dl.resizeTo(ctx.getResources(), endSize);
        }
    }

+11 −0
Original line number Diff line number Diff line
@@ -277,6 +277,17 @@ public class DisplayLayout {
        recalcInsets(res);
    }

    /**
     * Apply a rotation to this layout followed up by an update to its dimensions in new rotation.
     */
    public void rotateAndResizeTo(Resources res, @Surface.Rotation int toRotation,
            @NonNull Size displaySize) {
        // The convention is that if attempting to rotate and resize in one go, the new size should
        // be in the final rotation; so rotate the layout in place first.
        rotateTo(res, toRotation);
        resizeTo(res, displaySize);
    }

    /** Update the global bounds of this layout, in DP. */
    public void setGlobalBoundsDp(RectF bounds) {
        mGlobalBoundsDp = bounds;