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

Commit 5cef3871 authored by Tyler Freeman's avatar Tyler Freeman Committed by Cherrypicker Worker
Browse files

fix(magnification thumbnail): fix thumbnail not refreshing when orientation changes or IME opens

Fix: b/279538599
Fix: b/279538852
Fix: b/279527264

Test: manual
(cherry picked from https://googleplex-android-review.googlesource.com/q/commit:602b563ad69f508ada7fed55b9b19d339a3cd7e0)
Merged-In: Idb0855b78a867d120ac0911fba1b5f8c66da1c13
Change-Id: Idb0855b78a867d120ac0911fba1b5f8c66da1c13
parent d2a48276
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();
            }
        }

+9 −3
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
+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() {