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

Commit 4c440498 authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge changes from topic "cherrypicker-L31500000961697753:N79800001383851094" into udc-qpr-dev

* changes:
  fix(magnification thumbnail): fix thumbnail area wrong when IME opens or orientation changes
  fix(magnification thumbnail): fix thumbnail not refreshing when orientation changes or IME opens
parents 0db49eb9 7ed014e0
Loading
Loading
Loading
Loading
+10 −6
Original line number Diff line number Diff line
@@ -319,6 +319,10 @@ public class FullScreenMagnificationController implements
                    FullScreenMagnificationController::onUserContextChanged,
                    FullScreenMagnificationController.this, mDisplayId);
            mControllerCtx.getHandler().sendMessage(m);

            synchronized (mLock) {
                refreshThumbnail();
            }
        }

        @Override
@@ -344,7 +348,7 @@ public class FullScreenMagnificationController implements
                    mMagnificationRegion.set(magnified);
                    mMagnificationRegion.getBounds(mMagnificationBounds);

                    refreshThumbnail(getScale(), getCenterX(), getCenterY());
                    refreshThumbnail();

                    // It's possible that our magnification spec is invalid with the new bounds.
                    // Adjust the current spec's offsets if necessary.
@@ -602,13 +606,13 @@ public class FullScreenMagnificationController implements
        }

        @GuardedBy("mLock")
        void refreshThumbnail(float scale, float centerX, float centerY) {
        void refreshThumbnail() {
            if (mMagnificationThumbnail != null) {
                mMagnificationThumbnail.setThumbnailBounds(
                        mMagnificationBounds,
                        scale,
                        centerX,
                        centerY
                        getScale(),
                        getCenterX(),
                        getCenterY()
                );
            }
        }
@@ -627,7 +631,7 @@ public class FullScreenMagnificationController implements
                // We call refreshThumbnail when the thumbnail is just created to set current
                // magnification bounds to thumbnail. It to prevent the thumbnail size has not yet
                // updated properly and thus shows with huge size. (b/276314641)
                refreshThumbnail(getScale(), getCenterX(), getCenterY());
                refreshThumbnail();
            }
        }

+17 −16
Original line number Diff line number Diff line
@@ -99,15 +99,17 @@ public class MagnificationThumbnail {
            Log.d(LOG_TAG, "setThumbnailBounds " + currentBounds);
        }
        mHandler.post(() -> {
            mWindowBounds = currentBounds;
            setBackgroundBounds();
            refreshBackgroundBounds(currentBounds);
            if (mVisible) {
                updateThumbnailMainThread(scale, centerX, centerY);
            }
        });
    }

    private void setBackgroundBounds() {
    @MainThread
    private void refreshBackgroundBounds(Rect currentBounds) {
        mWindowBounds = currentBounds;

        Point magnificationBoundary = getMagnificationThumbnailPadding(mContext);
        mThumbnailWidth = (int) (mWindowBounds.width() / BG_ASPECT_RATIO);
        mThumbnailHeight = (int) (mWindowBounds.height() / BG_ASPECT_RATIO);
@@ -117,6 +119,10 @@ public class MagnificationThumbnail {
        mBackgroundParams.height = mThumbnailHeight;
        mBackgroundParams.x = initX;
        mBackgroundParams.y = initY;

        if (mVisible) {
            mWindowManager.updateViewLayout(mThumbnailLayout, mBackgroundParams);
        }
    }

    @MainThread
@@ -264,21 +270,16 @@ public class MagnificationThumbnail {
            mThumbnailView.setScaleX(scaleDown);
            mThumbnailView.setScaleY(scaleDown);
        }
        float thumbnailWidth;
        float thumbnailHeight;
        if (mThumbnailView.getWidth() == 0 || mThumbnailView.getHeight() == 0) {
            // if the thumbnail view size is not updated correctly, we just use the cached values.
            thumbnailWidth = mThumbnailWidth;
            thumbnailHeight = mThumbnailHeight;
        } else {
            thumbnailWidth = mThumbnailView.getWidth();
            thumbnailHeight = mThumbnailView.getHeight();
        }
        if (!Float.isNaN(centerX)) {

        if (!Float.isNaN(centerX)
                && !Float.isNaN(centerY)
                && mThumbnailWidth > 0
                && mThumbnailHeight > 0
        ) {
            var padding = mThumbnailView.getPaddingTop();
            var ratio = 1f / BG_ASPECT_RATIO;
            var centerXScaled = centerX * ratio - (thumbnailWidth / 2f + padding);
            var centerYScaled = centerY * ratio - (thumbnailHeight / 2f + padding);
            var centerXScaled = centerX * ratio - (mThumbnailWidth / 2f + padding);
            var centerYScaled = centerY * ratio - (mThumbnailHeight / 2f + padding);

            if (DEBUG) {
                Log.d(
+58 −1
Original line number Diff line number Diff line
@@ -29,6 +29,7 @@ import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyFloat;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.atLeastOnce;
import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;
@@ -202,6 +203,7 @@ public class FullScreenMagnificationControllerTest {
        assertFalse(mFullScreenMagnificationController.isRegistered(DISPLAY_0));
        assertFalse(mFullScreenMagnificationController.isRegistered(DISPLAY_1));

        // Once for each display on unregister
        verify(mMockThumbnail, times(2)).hideThumbnail();
    }

@@ -543,7 +545,11 @@ public class FullScreenMagnificationControllerTest {
        // The first time is triggered when the thumbnail is just created.
        // The second time is triggered when the magnification region changed.
        verify(mMockThumbnail, times(2)).setThumbnailBounds(
                any(), anyFloat(), anyFloat(), anyFloat());
                /* currentBounds= */ any(),
                /* scale= */ anyFloat(),
                /* centerX= */ anyFloat(),
                /* centerY= */ anyFloat()
        );
    }

    @Test
@@ -681,6 +687,9 @@ public class FullScreenMagnificationControllerTest {
        checkActivatedAndMagnifying(/* activated= */ true, /* magnifying= */ true, displayId);
        assertTrue(mFullScreenMagnificationController.resetIfNeeded(displayId, SERVICE_ID_2));
        checkActivatedAndMagnifying(/* activated= */ false, /* magnifying= */ false, displayId);

        // Once on init before it's activated and once for reset
        verify(mMockThumbnail, times(2)).hideThumbnail();
    }

    @Test
@@ -783,6 +792,9 @@ public class FullScreenMagnificationControllerTest {
        mMessageCapturingHandler.sendAllMessages();
        checkActivatedAndMagnifying(/* activated= */ false, /* magnifying= */ false, DISPLAY_0);
        checkActivatedAndMagnifying(/* activated= */ false, /* magnifying= */ false, DISPLAY_1);

        // Twice for each display: once on init before it's activated and once for screen off
        verify(mMockThumbnail, times(4)).hideThumbnail();
    }

    @Test
@@ -847,6 +859,15 @@ public class FullScreenMagnificationControllerTest {
        mMessageCapturingHandler.sendAllMessages();
        checkActivatedAndMagnifying(
                /* activated= */ expectedActivated, /* magnifying= */ false, displayId);

        if (expectedActivated) {
            verify(mMockThumbnail, times(2)).setThumbnailBounds(
                    /* currentBounds= */ any(),
                    /* scale= */ anyFloat(),
                    /* centerX= */ anyFloat(),
                    /* centerY= */ anyFloat()
            );
        }
    }

    @Test
@@ -950,6 +971,13 @@ public class FullScreenMagnificationControllerTest {
                INITIAL_BOUNDS_LOWER_RIGHT_2X_CENTER, scale);
        assertThat(endSpec, closeTo(getMagnificationSpec(scale, expectedOffsets)));
        verify(mMockWindowManager).setMagnificationSpec(eq(displayId), argThat(closeTo(endSpec)));

        verify(mMockThumbnail, atLeastOnce()).setThumbnailBounds(
                /* currentBounds= */ any(),
                eq(scale),
                /* centerX= */ anyFloat(),
                /* centerY= */ anyFloat()
        );
    }

    @Test
@@ -984,6 +1012,13 @@ public class FullScreenMagnificationControllerTest {
                INITIAL_BOUNDS_LOWER_RIGHT_2X_CENTER, scale);
        assertThat(endSpec, closeTo(getMagnificationSpec(scale, expectedOffsets)));
        verify(mMockWindowManager).setMagnificationSpec(eq(displayId), argThat(closeTo(endSpec)));

        verify(mMockThumbnail, atLeastOnce()).setThumbnailBounds(
                /* currentBounds= */ any(),
                eq(scale),
                /* centerX= */ anyFloat(),
                /* centerY= */ anyFloat()
        );
    }

    @Test
@@ -1246,6 +1281,13 @@ public class FullScreenMagnificationControllerTest {
        callbacks.onImeWindowVisibilityChanged(true);
        mMessageCapturingHandler.sendAllMessages();
        verify(mRequestObserver).onImeWindowVisibilityChanged(eq(DISPLAY_0), eq(true));

        verify(mMockThumbnail, atLeastOnce()).setThumbnailBounds(
                /* currentBounds= */ any(),
                /* scale= */ anyFloat(),
                /* centerX= */ anyFloat(),
                /* centerY= */ anyFloat()
        );
    }

    @Test
@@ -1270,6 +1312,15 @@ public class FullScreenMagnificationControllerTest {
        mFullScreenMagnificationController.onUserContextChanged(DISPLAY_0);

        verify(mRequestObserver).onFullScreenMagnificationActivationState(eq(DISPLAY_0), eq(false));
        verify(mMockThumbnail).setThumbnailBounds(
                /* currentBounds= */ any(),
                /* scale= */ anyFloat(),
                /* centerX= */ anyFloat(),
                /* centerY= */ anyFloat()
        );

        // Once on init before it's activated and once for reset
        verify(mMockThumbnail, times(2)).hideThumbnail();
    }

    @Test
@@ -1281,6 +1332,12 @@ public class FullScreenMagnificationControllerTest {

        assertEquals(1.0f, mFullScreenMagnificationController.getScale(DISPLAY_0), 0);
        assertTrue(mFullScreenMagnificationController.isActivated(DISPLAY_0));
        verify(mMockThumbnail).setThumbnailBounds(
                /* currentBounds= */ any(),
                /* scale= */ anyFloat(),
                /* centerX= */ anyFloat(),
                /* centerY= */ anyFloat()
        );
    }

    private void setScaleToMagnifying() {
+23 −0
Original line number Diff line number Diff line
@@ -187,6 +187,29 @@ public class MagnificationThumbnailTest {
                .addView(eq(mMagnificationThumbnail.mThumbnailLayout), any());
        verify(mMockWindowManager, never())
                .removeView(eq(mMagnificationThumbnail.mThumbnailLayout));
        verify(mMockWindowManager, never())
                .updateViewLayout(eq(mMagnificationThumbnail.mThumbnailLayout), any());
    }

    @Test
    public void whenVisible_setBoundsUpdatesLayout() throws InterruptedException {
        runOnMainSync(() -> mMagnificationThumbnail.updateThumbnail(
                /* scale=   */ 2f,
                /* centerX= */ 5,
                /* centerY= */ 10
        ));
        runOnMainSync(() -> mMagnificationThumbnail.setThumbnailBounds(
                new Rect(),
                /* scale=   */ 2f,
                /* centerX= */ 5,
                /* centerY= */ 10
        ));
        idle();

        verify(mMockWindowManager).updateViewLayout(
                eq(mMagnificationThumbnail.mThumbnailLayout),
                /* params= */ any()
        );
    }

    private static void idle() {