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

Commit 6c0af1a1 authored by Minche Li's avatar Minche Li Committed by Android (Google) Code Review
Browse files

Merge changes from topic "magnification_btn" into sc-dev

* changes:
  Updates magnification button after magnification mode transition is done
  Also regarded as magnification activated when it is forced to show magnification bounds
parents 447ee0cc 97237d81
Loading
Loading
Loading
Loading
+24 −0
Original line number Diff line number Diff line
@@ -114,6 +114,8 @@ public class FullScreenMagnificationController {
        private boolean mUnregisterPending;
        private boolean mDeleteAfterUnregister;

        private boolean mForceShowMagnifiableBounds;

        private final int mDisplayId;

        private static final int INVALID_ID = -1;
@@ -420,11 +422,17 @@ public class FullScreenMagnificationController {
        @GuardedBy("mLock")
        void setForceShowMagnifiableBounds(boolean show) {
            if (mRegistered) {
                mForceShowMagnifiableBounds = show;
                mControllerCtx.getWindowManager().setForceShowMagnifiableBounds(
                        mDisplayId, show);
            }
        }

        @GuardedBy("mLock")
        boolean isForceShowMagnifiableBounds() {
            return mRegistered && mForceShowMagnifiableBounds;
        }

        @GuardedBy("mLock")
        boolean reset(boolean animate) {
            return reset(transformToStubCallback(animate));
@@ -442,6 +450,7 @@ public class FullScreenMagnificationController {
                onMagnificationChangedLocked();
            }
            mIdOfLastServiceToMagnify = INVALID_ID;
            mForceShowMagnifiableBounds = false;
            sendSpecToAnimation(spec, animationCallback);
            return changed;
        }
@@ -1158,6 +1167,21 @@ public class FullScreenMagnificationController {
        }
    }

    /**
     * Returns {@code true} if the magnifiable regions of the display is forced to be shown.
     *
     * @param displayId The logical display id.
     */
    public boolean isForceShowMagnifiableBounds(int displayId) {
        synchronized (mLock) {
            final DisplayMagnification display = mDisplays.get(displayId);
            if (display == null) {
                return false;
            }
            return display.isForceShowMagnifiableBounds();
        }
    }

    private void onScreenTurnedOff() {
        final Message m = PooledLambda.obtainMessage(
                FullScreenMagnificationController::resetAllIfNeeded, this, false);
+7 −1
Original line number Diff line number Diff line
@@ -52,6 +52,9 @@ import com.android.server.accessibility.AccessibilityManagerService;
 *   <li> 4. {@link #onTripleTapped} updates magnification switch UI depending on magnification
 *   capabilities and magnification active state when triple-tap gesture is detected. </li>
 * </ol>
 *
 *  <b>Note</b>  Updates magnification switch UI when magnification mode transition
 *  is done {@link DisableMagnificationCallback#onResult}.
 */
public class MagnificationController implements WindowMagnificationManager.Callback,
        MagnificationGestureHandler.Callback,
@@ -358,7 +361,8 @@ public class MagnificationController implements WindowMagnificationManager.Callb
        boolean isActivated = false;
        if (mode == ACCESSIBILITY_MAGNIFICATION_MODE_FULLSCREEN
                && mFullScreenMagnificationController != null) {
            isActivated = mFullScreenMagnificationController.isMagnifying(displayId);
            isActivated = mFullScreenMagnificationController.isMagnifying(displayId)
                    || mFullScreenMagnificationController.isForceShowMagnifiableBounds(displayId);
        } else if (mode == ACCESSIBILITY_MAGNIFICATION_MODE_WINDOW
                && mWindowMagnificationMgr != null) {
            isActivated = mWindowMagnificationMgr.isWindowMagnifierEnabled(displayId);
@@ -400,6 +404,7 @@ public class MagnificationController implements WindowMagnificationManager.Callb
                    adjustCurrentCenterIfNeededLocked();
                    applyMagnificationModeLocked(mTargetMode);
                }
                updateMagnificationButton(mDisplayId, mTargetMode);
                mTransitionCallBack.onResult(success);
            }
        }
@@ -424,6 +429,7 @@ public class MagnificationController implements WindowMagnificationManager.Callb
                }
                setExpiredAndRemoveFromListLocked();
                applyMagnificationModeLocked(mCurrentMode);
                updateMagnificationButton(mDisplayId, mCurrentMode);
                mTransitionCallBack.onResult(true);
            }
        }
+22 −9
Original line number Diff line number Diff line
@@ -65,7 +65,6 @@ import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.ArgumentCaptor;
import org.mockito.Mockito;
import org.mockito.invocation.InvocationOnMock;
import org.mockito.stubbing.Answer;

import java.util.Locale;
@@ -1114,6 +1113,23 @@ public class FullScreenMagnificationControllerTest {
                argThat(closeTo(newEndSpec)));
    }

    @Test
    public void testSetForceShowMagnifiableBounds() {
        register(DISPLAY_0);

        mFullScreenMagnificationController.setForceShowMagnifiableBounds(DISPLAY_0, true);

        verify(mMockWindowManager).setForceShowMagnifiableBounds(DISPLAY_0, true);
    }

    @Test
    public void testIsForceShowMagnifiableBounds() {
        register(DISPLAY_0);
        mFullScreenMagnificationController.setForceShowMagnifiableBounds(DISPLAY_0, true);

        assertTrue(mFullScreenMagnificationController.isForceShowMagnifiableBounds(DISPLAY_0));
    }

    @Test
    public void testSetScale_toMagnifying_shouldNotifyActivatedState() {
        setScaleToMagnifying();
@@ -1142,14 +1158,11 @@ public class FullScreenMagnificationControllerTest {
        for (int i = 0; i < DISPLAY_COUNT; i++) {
            when(mMockWindowManager.setMagnificationCallbacks(eq(i), any())).thenReturn(true);
        }
        doAnswer(new Answer<Void>() {
            @Override
            public Void answer(InvocationOnMock invocationOnMock) throws Throwable {
        doAnswer((Answer<Void>) invocationOnMock -> {
            Object[] args = invocationOnMock.getArguments();
            Region regionArg = (Region) args[1];
            regionArg.set(INITIAL_MAGNIFICATION_REGION);
            return null;
            }
        }).when(mMockWindowManager).getMagnificationRegion(anyInt(), (Region) anyObject());
    }

+67 −1
Original line number Diff line number Diff line
@@ -25,6 +25,7 @@ import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyBoolean;
import static org.mockito.ArgumentMatchers.anyFloat;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.ArgumentMatchers.anyLong;
@@ -173,6 +174,23 @@ public class MagnificationControllerTest {
        assertEquals(MAGNIFIED_CENTER_Y, mWindowMagnificationManager.getCenterY(TEST_DISPLAY), 0);
    }

    @Test
    public void transitionToWindowMode_disablingWindowMode_showMagnificationButton()
            throws RemoteException {
        setMagnificationEnabled(MODE_WINDOW);
        mMagnificationController.transitionMagnificationModeLocked(TEST_DISPLAY,
                MODE_FULLSCREEN,
                mTransitionCallBack);

        mMagnificationController.transitionMagnificationModeLocked(TEST_DISPLAY,
                MODE_WINDOW,
                mTransitionCallBack);

        mMockConnection.invokeCallbacks();
        verify(mWindowMagnificationManager).showMagnificationButton(eq(TEST_DISPLAY),
                eq(MODE_WINDOW));
    }

    @Test
    public void transitionToFullScreenMode_windowMagnifying_disableWindowAndEnableFullScreen()
            throws RemoteException {
@@ -228,7 +246,6 @@ public class MagnificationControllerTest {
        verify(mTransitionCallBack).onResult(true);
    }


    @Test
    public void interruptDuringTransitionToFullScreenMode_windowMagnifying_notifyTransitionFailed()
            throws RemoteException {
@@ -365,6 +382,19 @@ public class MagnificationControllerTest {
                eq(MODE_FULLSCREEN));
    }


    @Test
    public void onTouchInteractionChanged_fullscreenNotActivated_notShowMagnificationButton()
            throws RemoteException {
        setMagnificationModeSettings(MODE_FULLSCREEN);

        mMagnificationController.onTouchInteractionStart(TEST_DISPLAY, MODE_FULLSCREEN);
        mMagnificationController.onTouchInteractionEnd(TEST_DISPLAY, MODE_FULLSCREEN);

        verify(mWindowMagnificationManager, never()).showMagnificationButton(eq(TEST_DISPLAY),
                eq(MODE_FULLSCREEN));
    }

    @Test
    public void onShortcutTriggered_windowModeEnabledAndCapabilitiesAll_showMagnificationButton()
            throws RemoteException {
@@ -427,6 +457,35 @@ public class MagnificationControllerTest {
        verify(mWindowMagnificationManager).removeMagnificationButton(eq(TEST_DISPLAY));
    }

    @Test
    public void transitionToFullScreenMode_fullscreenModeActivated_showMagnificationButton()
            throws RemoteException {
        setMagnificationEnabled(MODE_WINDOW);

        mMagnificationController.transitionMagnificationModeLocked(TEST_DISPLAY,
                MODE_FULLSCREEN, mTransitionCallBack);
        mMockConnection.invokeCallbacks();

        verify(mWindowMagnificationManager).showMagnificationButton(eq(TEST_DISPLAY),
                eq(MODE_FULLSCREEN));
    }

    @Test
    public void transitionToWindow_windowModeActivated_showMagnificationButton()
            throws RemoteException {
        setMagnificationEnabled(MODE_FULLSCREEN);

        mMagnificationController.transitionMagnificationModeLocked(TEST_DISPLAY,
                MODE_WINDOW, mTransitionCallBack);

        verify(mScreenMagnificationController).reset(eq(TEST_DISPLAY),
                mCallbackArgumentCaptor.capture());
        mCallbackArgumentCaptor.getValue().onResult(true);
        mMockConnection.invokeCallbacks();
        verify(mWindowMagnificationManager).showMagnificationButton(eq(TEST_DISPLAY),
                eq(MODE_WINDOW));
    }

    private void setMagnificationEnabled(int mode) throws RemoteException {

        setMagnificationEnabled(mode, MAGNIFIED_CENTER_X, MAGNIFIED_CENTER_Y);
@@ -450,6 +509,8 @@ public class MagnificationControllerTest {
        }
        if (mode == MODE_FULLSCREEN) {
            when(mScreenMagnificationController.isMagnifying(TEST_DISPLAY)).thenReturn(true);
            when(mScreenMagnificationController.isForceShowMagnifiableBounds(
                    TEST_DISPLAY)).thenReturn(true);
            when(mScreenMagnificationController.getPersistedScale()).thenReturn(DEFAULT_SCALE);
            when(mScreenMagnificationController.getScale(TEST_DISPLAY)).thenReturn(DEFAULT_SCALE);
            when(mScreenMagnificationController.getCenterX(TEST_DISPLAY)).thenReturn(
@@ -457,6 +518,11 @@ public class MagnificationControllerTest {
            when(mScreenMagnificationController.getCenterY(TEST_DISPLAY)).thenReturn(
                    centerY);
        } else {
            doAnswer(invocation -> {
                when(mScreenMagnificationController.isMagnifying(TEST_DISPLAY)).thenReturn(true);
                return null;
            }).when(mScreenMagnificationController).setScaleAndCenter(eq(TEST_DISPLAY),
                    eq(DEFAULT_SCALE), anyFloat(), anyFloat(), anyBoolean(), anyInt());
            mWindowMagnificationManager.enableWindowMagnification(TEST_DISPLAY, DEFAULT_SCALE,
                    centerX, centerY, null);
            mMockConnection.invokeCallbacks();