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

Commit e452dd69 authored by Ikram Gabiyev's avatar Ikram Gabiyev Committed by Android (Google) Code Review
Browse files

Merge "Properly propagate rotation onDisplayChange" into main

parents 906feec8 d3623f77
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;