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

Commit 827247ab authored by ryanlwlin's avatar ryanlwlin
Browse files

Fix incorrect border after folding/unfolding the device

The display size is changed after folding/unfolding the device.
We need to refetch the size to draw the correct boundary on
the screen. Display#realSize is not updated in time, so we get the
bounds directly from windowConfiguration.

Bug: 190007130
Test: manual test
Change-Id: I942e333f62510650eec8b49d77ccf46a85a7457e
parent b6bfa268
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -283,7 +283,7 @@ public class FullScreenMagnificationController {
        }

        @Override
        public void onRotationChanged(int rotation) {
        public void onDisplaySizeChanged() {
            // Treat as context change and reset
            final Message m = PooledLambda.obtainMessage(
                    FullScreenMagnificationController::resetIfNeeded,
+25 −17
Original line number Diff line number Diff line
@@ -326,7 +326,8 @@ final class AccessibilityController {
        }
    }

    void onRotationChanged(DisplayContent displayContent) {
    void onDisplaySizeChanged(DisplayContent displayContent) {

        if (mAccessibilityTracing.isTracingEnabled(FLAGS_MAGNIFICATION_CALLBACK
                | FLAGS_WINDOWS_FOR_ACCESSIBILITY_CALLBACK)) {
            mAccessibilityTracing.logTrace(TAG + ".onRotationChanged",
@@ -336,7 +337,7 @@ final class AccessibilityController {
        final int displayId = displayContent.getDisplayId();
        final DisplayMagnifier displayMagnifier = mDisplayMagnifiers.get(displayId);
        if (displayMagnifier != null) {
            displayMagnifier.onRotationChanged(displayContent);
            displayMagnifier.onDisplaySizeChanged(displayContent);
        }
        final WindowsForAccessibilityObserver windowsForA11yObserver =
                mWindowsForAccessibilityObserver.get(displayId);
@@ -608,7 +609,7 @@ final class AccessibilityController {
        private static final String LOG_TAG = TAG_WITH_CLASS_NAME ? "DisplayMagnifier" : TAG_WM;

        private static final boolean DEBUG_WINDOW_TRANSITIONS = false;
        private static final boolean DEBUG_ROTATION = false;
        private static final boolean DEBUG_DISPLAY_SIZE = false;
        private static final boolean DEBUG_LAYERS = false;
        private static final boolean DEBUG_RECTANGLE_REQUESTED = false;
        private static final boolean DEBUG_VIEWPORT_WINDOW = false;
@@ -725,18 +726,18 @@ final class AccessibilityController {
            mService.scheduleAnimationLocked();
        }

        void onRotationChanged(DisplayContent displayContent) {
        void onDisplaySizeChanged(DisplayContent displayContent) {
            if (mAccessibilityTracing.isTracingEnabled(FLAGS_MAGNIFICATION_CALLBACK)) {
                mAccessibilityTracing.logTrace(LOG_TAG + ".onRotationChanged",
                mAccessibilityTracing.logTrace(LOG_TAG + ".onDisplaySizeChanged",
                        FLAGS_MAGNIFICATION_CALLBACK, "displayContent={" + displayContent + "}");
            }
            if (DEBUG_ROTATION) {
            if (DEBUG_DISPLAY_SIZE) {
                final int rotation = displayContent.getRotation();
                Slog.i(LOG_TAG, "Rotation: " + Surface.rotationToString(rotation)
                        + " displayId: " + displayContent.getDisplayId());
            }
            mMagnifedViewport.onRotationChanged();
            mHandler.sendEmptyMessage(MyHandler.MESSAGE_NOTIFY_ROTATION_CHANGED);
            mMagnifedViewport.onDisplaySizeChanged();
            mHandler.sendEmptyMessage(MyHandler.MESSAGE_NOTIFY_DISPLAY_SIZE_CHANGED);
        }

        void onAppWindowTransition(int displayId, int transition) {
@@ -923,7 +924,8 @@ final class AccessibilityController {

                if (mDisplayContext.getResources().getConfiguration().isScreenRound()) {
                    mCircularPath = new Path();
                    mDisplay.getRealSize(mScreenSize);

                    getDisplaySizeLocked(mScreenSize);
                    final int centerXY = mScreenSize.x / 2;
                    mCircularPath.addCircle(centerXY, centerXY, centerXY, Path.Direction.CW);
                } else {
@@ -953,7 +955,7 @@ final class AccessibilityController {
            }

            void recomputeBounds() {
                mDisplay.getRealSize(mScreenSize);
                getDisplaySizeLocked(mScreenSize);
                final int screenWidth = mScreenSize.x;
                final int screenHeight = mScreenSize.y;

@@ -1088,9 +1090,10 @@ final class AccessibilityController {
                        || windowType == TYPE_ACCESSIBILITY_MAGNIFICATION_OVERLAY;
            }

            void onRotationChanged() {
            void onDisplaySizeChanged() {
                // If we are showing the magnification border, hide it immediately so
                // the user does not see strange artifacts during rotation. The screenshot
                // the user does not see strange artifacts during display size changed caused by
                // rotation or folding/unfolding the device. In the rotation case, the screenshot
                // used for rotation already has the border. After the rotation is complete
                // we will show the border.
                if (isMagnifying() || isForceShowingMagnifiableBounds()) {
@@ -1148,6 +1151,12 @@ final class AccessibilityController {
                }, false /* traverseTopToBottom */ );
            }

            private void getDisplaySizeLocked(Point outSize) {
                final Rect bounds =
                        mDisplayContent.getConfiguration().windowConfiguration.getBounds();
                outSize.set(bounds.width(), bounds.height());
            }

            void dump(PrintWriter pw, String prefix) {
                mWindow.dump(pw, prefix);
            }
@@ -1262,7 +1271,7 @@ final class AccessibilityController {

                void updateSize() {
                    synchronized (mService.mGlobalLock) {
                        mDisplay.getRealSize(mScreenSize);
                        getDisplaySizeLocked(mScreenSize);
                        mBlastBufferQueue.update(mSurfaceControl, mScreenSize.x, mScreenSize.y,
                                PixelFormat.RGBA_8888);
                        invalidate(mDirtyRect);
@@ -1401,7 +1410,7 @@ final class AccessibilityController {
            public static final int MESSAGE_NOTIFY_MAGNIFICATION_REGION_CHANGED = 1;
            public static final int MESSAGE_NOTIFY_RECTANGLE_ON_SCREEN_REQUESTED = 2;
            public static final int MESSAGE_NOTIFY_USER_CONTEXT_CHANGED = 3;
            public static final int MESSAGE_NOTIFY_ROTATION_CHANGED = 4;
            public static final int MESSAGE_NOTIFY_DISPLAY_SIZE_CHANGED = 4;
            public static final int MESSAGE_SHOW_MAGNIFIED_REGION_BOUNDS_IF_NEEDED = 5;
            public static final int MESSAGE_NOTIFY_IME_WINDOW_VISIBILITY_CHANGED = 6;

@@ -1433,9 +1442,8 @@ final class AccessibilityController {
                        mCallbacks.onUserContextChanged();
                    } break;

                    case MESSAGE_NOTIFY_ROTATION_CHANGED: {
                        final int rotation = message.arg1;
                        mCallbacks.onRotationChanged(rotation);
                    case MESSAGE_NOTIFY_DISPLAY_SIZE_CHANGED: {
                        mCallbacks.onDisplaySizeChanged();
                    } break;

                    case MESSAGE_SHOW_MAGNIFIED_REGION_BOUNDS_IF_NEEDED : {
+8 −4
Original line number Diff line number Diff line
@@ -1897,10 +1897,6 @@ class DisplayContent extends RootDisplayArea implements WindowManagerPolicy.Disp
                }
            }
        }

        if (mWmService.mAccessibilityController != null) {
            mWmService.mAccessibilityController.onRotationChanged(this);
        }
    }

    void configureDisplayPolicy() {
@@ -5572,6 +5568,14 @@ class DisplayContent extends RootDisplayArea implements WindowManagerPolicy.Disp
                ActivityTaskManagerService.LAYOUT_REASON_CONFIG_CHANGED);
    }

    @Override
    void onResize() {
        super.onResize();
        if (mWmService.mAccessibilityController != null) {
            mWmService.mAccessibilityController.onDisplaySizeChanged(this);
        }
    }

    /**
     * If the launching rotated activity ({@link #mFixedRotationLaunchingApp}) is null, it simply
     * applies the rotation to display. Otherwise because the activity has shown as rotated, the
+3 −3
Original line number Diff line number Diff line
@@ -160,11 +160,11 @@ public abstract class WindowManagerInternal {
        void onRectangleOnScreenRequested(int left, int top, int right, int bottom);

        /**
         * Notifies that the rotation changed.
         * Notifies that the display size is changed when rotation or the
         * logical display is changed.
         *
         * @param rotation The current rotation.
         */
        void onRotationChanged(int rotation);
        void onDisplaySizeChanged();

        /**
         * Notifies that the context of the user changed. For example, an application
+4 −4
Original line number Diff line number Diff line
@@ -777,20 +777,20 @@ public class FullScreenMagnificationControllerTest {
    }

    @Test
    public void testRotation_resetsMagnification() {
    public void testDisplaySizeChanged_resetsMagnification() {
        for (int i = 0; i < DISPLAY_COUNT; i++) {
            rotation_resetsMagnification(i);
            changeDisplaySize_resetsMagnification(i);
            resetMockWindowManager();
        }
    }

    private void rotation_resetsMagnification(int displayId) {
    private void changeDisplaySize_resetsMagnification(int displayId) {
        register(displayId);
        MagnificationCallbacks callbacks = getMagnificationCallbacks(displayId);
        zoomIn2xToMiddle(displayId);
        mMessageCapturingHandler.sendAllMessages();
        assertTrue(mFullScreenMagnificationController.isMagnifying(displayId));
        callbacks.onRotationChanged(0);
        callbacks.onDisplaySizeChanged();
        mMessageCapturingHandler.sendAllMessages();
        assertFalse(mFullScreenMagnificationController.isMagnifying(displayId));
    }