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

Commit 77128057 authored by mincheli's avatar mincheli Committed by Minche Li
Browse files

The legacy magnification controller APIs controls only full-screen magnification

See go/b200769372 - the legacy public methods
The legacy magnification controller methods,
  setScale(), setCenter(),
  getScale(), getCenterX(), getCenterY(),
  getMagnificationRegion(),
  reset(),
will keep the behavior before that control
only full-screen magnification.

To make the service able to control the actiavted magnifier
on the display, the service should use the new public APIs,
 1. setMagnificationConfig(),
 2. getMagnificationConfig(),
 3. getCurrentMagnificationRegion()
instead of the legacy APIs.

This change
1. Updates the doc of the legcacy APIs.
2. The legacy APIs controls only fullscreen magnification

TODO: Add new public methods, getCurrentMagnificationRegion(),
 resetCurrentMagnification() for the current controlling magnifier

Bug: 210069654
Test: atest MagnificationProcessorTest,
    atest AbstractAccessibilityServiceConnectionTest,
    atest AccessibilityMagnificationTest,
Change-Id: Ia157971d2c9716df7aa14024525ee0adfdc0d46f
parent fc8cd1d6
Loading
Loading
Loading
Loading
+29 −0
Original line number Diff line number Diff line
@@ -1392,6 +1392,12 @@ public abstract class AccessibilityService extends Service {
         * {@link AccessibilityService#onServiceConnected()} has not yet been
         * called) or the service has been disconnected, this method will
         * return a default value of {@code 1.0f}.
         * </p>
         * <p>
         * <strong>Note:</strong> This legacy API gets the scale of full-screen
         * magnification. To get the scale of the current controlling magnifier,
         * use {@link #getMagnificationConfig} instead.
         * </p>
         *
         * @return the current magnification scale
         */
@@ -1420,6 +1426,12 @@ public abstract class AccessibilityService extends Service {
         * {@link AccessibilityService#onServiceConnected()} has not yet been
         * called) or the service has been disconnected, this method will
         * return a default value of {@code 0.0f}.
         * </p>
         * <p>
         * <strong>Note:</strong> This legacy API gets the center position of full-screen
         * magnification. To get the magnification center of the current controlling magnifier,
         * use {@link #getMagnificationConfig} instead.
         * </p>
         *
         * @return the unscaled screen-relative X coordinate of the center of
         *         the magnified region
@@ -1449,6 +1461,12 @@ public abstract class AccessibilityService extends Service {
         * {@link AccessibilityService#onServiceConnected()} has not yet been
         * called) or the service has been disconnected, this method will
         * return a default value of {@code 0.0f}.
         * </p>
         * <p>
         * <strong>Note:</strong> This legacy API gets the center position of full-screen
         * magnification. To get the magnification center of the current controlling magnifier,
         * use {@link #getMagnificationConfig} instead.
         * </p>
         *
         * @return the unscaled screen-relative Y coordinate of the center of
         *         the magnified region
@@ -1569,6 +1587,11 @@ public abstract class AccessibilityService extends Service {
         * {@link AccessibilityService#onServiceConnected()} has not yet been
         * called) or the service has been disconnected, this method will have
         * no effect and return {@code false}.
         * <p>
         * <strong>Note:</strong> This legacy API sets the scale of full-screen
         * magnification. To set the scale of the specified magnifier,
         * use {@link #setMagnificationConfig} instead.
         * </p>
         *
         * @param scale the magnification scale to set, must be >= 1 and <= 8
         * @param animate {@code true} to animate from the current scale or
@@ -1600,6 +1623,12 @@ public abstract class AccessibilityService extends Service {
         * {@link AccessibilityService#onServiceConnected()} has not yet been
         * called) or the service has been disconnected, this method will have
         * no effect and return {@code false}.
         * </p>
         * <p>
         * <strong>Note:</strong> This legacy API sets the center of full-screen
         * magnification. To set the center of the specified magnifier,
         * use {@link #setMagnificationConfig} instead.
         * </p>
         *
         * @param centerX the unscaled screen-relative X coordinate on which to
         *                center the viewport
+3 −3
Original line number Diff line number Diff line
@@ -1027,8 +1027,8 @@ abstract class AbstractAccessibilityServiceConnection extends IAccessibilityServ
                    mSystemSupport.getMagnificationProcessor();
            final long identity = Binder.clearCallingIdentity();
            try {
                magnificationProcessor.getMagnificationRegion(displayId, region,
                        mSecurityPolicy.canControlMagnification(this));
                magnificationProcessor.getFullscreenMagnificationRegion(displayId,
                        region, mSecurityPolicy.canControlMagnification(this));
                return region;
            } finally {
                Binder.restoreCallingIdentity(identity);
@@ -1095,7 +1095,7 @@ abstract class AbstractAccessibilityServiceConnection extends IAccessibilityServ
        try {
            MagnificationProcessor magnificationProcessor =
                    mSystemSupport.getMagnificationProcessor();
            return (magnificationProcessor.reset(displayId, animate)
            return (magnificationProcessor.resetFullscreenMagnification(displayId, animate)
                    || !magnificationProcessor.isMagnifying(displayId));
        } finally {
            Binder.restoreCallingIdentity(identity);
+49 −72
Original line number Diff line number Diff line
@@ -119,6 +119,18 @@ public class MagnificationProcessor {
        return false;
    }

    private boolean setScaleAndCenterForFullScreenMagnification(int displayId, float scale,
            float centerX, float centerY,
            boolean animate, int id) {
        if (!isRegistered(displayId)) {
            register(displayId);
        }
        return mController.getFullScreenMagnificationController().setScaleAndCenter(
                displayId,
                scale,
                centerX, centerY, animate, id);
    }

    /**
     * Returns {@code true} if transition magnification mode needed. And it is no need to transition
     * mode when the controlling mode is unchanged or the controlling magnifier is not activated.
@@ -135,24 +147,18 @@ public class MagnificationProcessor {
    }

    /**
     * Returns the magnification scale. If an animation is in progress,
     * this reflects the end state of the animation.
     * Returns the magnification scale of full-screen magnification on the display.
     * If an animation is in progress, this reflects the end state of the animation.
     *
     * @param displayId The logical display id.
     * @return the scale
     */
    public float getScale(int displayId) {
        int mode = getControllingMode(displayId);
        if (mode == MAGNIFICATION_MODE_FULLSCREEN) {
        return mController.getFullScreenMagnificationController().getScale(displayId);
        } else if (mode == MAGNIFICATION_MODE_WINDOW) {
            return mController.getWindowMagnificationMgr().getScale(displayId);
        }
        return 0;
    }

    /**
     * Returns the magnification center in X coordinate of the controlling magnification mode.
     * Returns the magnification center in X coordinate of full-screen magnification.
     * If the service can control magnification but fullscreen magnifier is not registered, it will
     * register the magnifier for this call then unregister the magnifier finally to make the
     * magnification center correct.
@@ -162,8 +168,6 @@ public class MagnificationProcessor {
     * @return the X coordinate
     */
    public float getCenterX(int displayId, boolean canControlMagnification) {
        int mode = getControllingMode(displayId);
        if (mode == MAGNIFICATION_MODE_FULLSCREEN) {
        boolean registeredJustForThisCall = registerDisplayMagnificationIfNeeded(displayId,
                canControlMagnification);
        try {
@@ -173,14 +177,10 @@ public class MagnificationProcessor {
                unregister(displayId);
            }
        }
        } else if (mode == MAGNIFICATION_MODE_WINDOW) {
            return mController.getWindowMagnificationMgr().getCenterX(displayId);
        }
        return 0;
    }

    /**
     * Returns the magnification center in Y coordinate of the controlling magnification mode.
     * Returns the magnification center in Y coordinate of full-screen magnification.
     * If the service can control magnification but fullscreen magnifier is not registered, it will
     * register the magnifier for this call then unregister the magnifier finally to make the
     * magnification center correct.
@@ -190,8 +190,6 @@ public class MagnificationProcessor {
     * @return the Y coordinate
     */
    public float getCenterY(int displayId, boolean canControlMagnification) {
        int mode = getControllingMode(displayId);
        if (mode == MAGNIFICATION_MODE_FULLSCREEN) {
        boolean registeredJustForThisCall = registerDisplayMagnificationIfNeeded(displayId,
                canControlMagnification);
        try {
@@ -201,38 +199,16 @@ public class MagnificationProcessor {
                unregister(displayId);
            }
        }
        } else if (mode == MAGNIFICATION_MODE_WINDOW) {
            return mController.getWindowMagnificationMgr().getCenterY(displayId);
        }
        return 0;
    }

    /**
     * Return the magnification bounds of the current controlling magnification on the given
     * display. If the magnifier is not enabled, it returns an empty region.
     * If the service can control magnification but fullscreen magnifier is not registered, it will
     * register the magnifier for this call then unregister the magnifier finally to make
     * the magnification region correct.
     * Returns the magnification bounds of full-screen magnification on the given display.
     *
     * @param displayId The logical display id
     * @param outRegion the region to populate
     * @param canControlMagnification Whether the service can control magnification
     * @return outRegion the magnification bounds of full-screen magnifier or the magnification
     * source bounds of window magnifier
     */
    public Region getMagnificationRegion(int displayId, @NonNull Region outRegion,
            boolean canControlMagnification) {
        int mode = getControllingMode(displayId);
        if (mode == MAGNIFICATION_MODE_FULLSCREEN) {
            getFullscreenMagnificationRegion(displayId, outRegion, canControlMagnification);
        } else if (mode == MAGNIFICATION_MODE_WINDOW) {
            mController.getWindowMagnificationMgr().getMagnificationSourceBounds(displayId,
                    outRegion);
        }
        return outRegion;
    }

    private void getFullscreenMagnificationRegion(int displayId, @NonNull Region outRegion,
    public void getFullscreenMagnificationRegion(int displayId, @NonNull Region outRegion,
            boolean canControlMagnification) {
        boolean registeredJustForThisCall = registerDisplayMagnificationIfNeeded(displayId,
                canControlMagnification);
@@ -246,21 +222,9 @@ public class MagnificationProcessor {
        }
    }

    private boolean setScaleAndCenterForFullScreenMagnification(int displayId, float scale,
            float centerX, float centerY,
            boolean animate, int id) {
        if (!isRegistered(displayId)) {
            register(displayId);
        }
        return mController.getFullScreenMagnificationController().setScaleAndCenter(
                displayId,
                scale,
                centerX, centerY, animate, id);
    }

    /**
     * Resets the magnification on the given display. The reset mode could be full-screen or
     * window if it is activated.
     * Resets the current magnification on the given display. The reset mode could be
     * full-screen or window if it is activated.
     *
     * @param displayId The logical display id.
     * @param animate   {@code true} to animate the transition, {@code false}
@@ -268,7 +232,7 @@ public class MagnificationProcessor {
     * @return {@code true} if the magnification spec changed, {@code false} if
     * the spec did not change
     */
    public boolean reset(int displayId, boolean animate) {
    public boolean resetCurrentMagnification(int displayId, boolean animate) {
        int mode = getControllingMode(displayId);
        if (mode == MAGNIFICATION_MODE_FULLSCREEN) {
            return mController.getFullScreenMagnificationController().reset(displayId, animate);
@@ -278,6 +242,19 @@ public class MagnificationProcessor {
        return false;
    }

    /**
     * Resets the full-screen magnification on the given display.
     *
     * @param displayId The logical display id.
     * @param animate   {@code true} to animate the transition, {@code false}
     *                  to transition immediately
     * @return {@code true} if the magnification spec changed, {@code false} if
     * the spec did not change
     */
    public boolean resetFullscreenMagnification(int displayId, boolean animate) {
        return mController.getFullScreenMagnificationController().reset(displayId, animate);
    }

    /**
     * {@link FullScreenMagnificationController#resetIfNeeded(int, boolean)}
     */
+8 −5
Original line number Diff line number Diff line
@@ -585,8 +585,8 @@ public class AbstractAccessibilityServiceConnectionTest {
        doAnswer((invocation) -> {
            ((Region) invocation.getArguments()[1]).set(region);
            return null;
        }).when(mMockMagnificationProcessor).getMagnificationRegion(eq(displayId),
                any(), anyBoolean());
        }).when(mMockMagnificationProcessor).getFullscreenMagnificationRegion(eq(displayId), any(),
                anyBoolean());
        when(mMockSystemSupport.getCurrentUserIdLocked()).thenReturn(USER_ID2);

        final Region result = mServiceConnection.getMagnificationRegion(displayId);
@@ -620,7 +620,8 @@ public class AbstractAccessibilityServiceConnectionTest {
    @Test
    public void resetMagnification() {
        final int displayId = 1;
        when(mMockMagnificationProcessor.reset(displayId, true)).thenReturn(true);
        when(mMockMagnificationProcessor.resetFullscreenMagnification(displayId, true)).thenReturn(
                true);

        final boolean result = mServiceConnection.resetMagnification(displayId, true);
        assertThat(result, is(true));
@@ -629,7 +630,8 @@ public class AbstractAccessibilityServiceConnectionTest {
    @Test
    public void resetMagnification_cantControlMagnification_returnFalse() {
        final int displayId = 1;
        when(mMockMagnificationProcessor.reset(displayId, true)).thenReturn(true);
        when(mMockMagnificationProcessor.resetFullscreenMagnification(displayId, true)).thenReturn(
                true);
        when(mMockSecurityPolicy.canControlMagnification(mServiceConnection)).thenReturn(false);

        final boolean result = mServiceConnection.resetMagnification(displayId, true);
@@ -639,7 +641,8 @@ public class AbstractAccessibilityServiceConnectionTest {
    @Test
    public void resetMagnification_serviceNotBelongCurrentUser_returnFalse() {
        final int displayId = 1;
        when(mMockMagnificationProcessor.reset(displayId, true)).thenReturn(true);
        when(mMockMagnificationProcessor.resetFullscreenMagnification(displayId, true)).thenReturn(
                true);
        when(mMockSystemSupport.getCurrentUserIdLocked()).thenReturn(USER_ID2);

        final boolean result = mServiceConnection.resetMagnification(displayId, true);
+10 −23
Original line number Diff line number Diff line
@@ -98,7 +98,7 @@ public class MagnificationProcessorTest {
                .setScale(TEST_SCALE).build();
        setMagnificationActivated(TEST_DISPLAY, config);

        float scale = mMagnificationProcessor.getScale(TEST_DISPLAY);
        float scale = mMagnificationProcessor.getMagnificationConfig(TEST_DISPLAY).getScale();

        assertEquals(scale, TEST_SCALE, 0);
    }
@@ -117,14 +117,13 @@ public class MagnificationProcessorTest {
    }

    @Test
    public void getCenterX_canControlWindowMagnification_returnCenterX() {
    public void getCenterX_controlWindowMagnification_returnCenterX() {
        final MagnificationConfig config = new MagnificationConfig.Builder()
                .setMode(MAGNIFICATION_MODE_WINDOW)
                .setCenterX(TEST_CENTER_X).build();
        setMagnificationActivated(TEST_DISPLAY, config);

        float centerX = mMagnificationProcessor.getCenterX(
                TEST_DISPLAY,  /* canControlMagnification= */true);
        float centerX = mMagnificationProcessor.getMagnificationConfig(TEST_DISPLAY).getCenterX();

        assertEquals(centerX, TEST_CENTER_X, 0);
    }
@@ -143,14 +142,13 @@ public class MagnificationProcessorTest {
    }

    @Test
    public void getCenterY_canControlWindowMagnification_returnCenterY() {
    public void getCenterY_controlWindowMagnification_returnCenterY() {
        final MagnificationConfig config = new MagnificationConfig.Builder()
                .setMode(MAGNIFICATION_MODE_WINDOW)
                .setCenterY(TEST_CENTER_Y).build();
        setMagnificationActivated(TEST_DISPLAY, config);

        float centerY = mMagnificationProcessor.getCenterY(
                TEST_DISPLAY,  /* canControlMagnification= */false);
        float centerY = mMagnificationProcessor.getMagnificationConfig(TEST_DISPLAY).getCenterY();

        assertEquals(centerY, TEST_CENTER_Y, 0);
    }
@@ -159,24 +157,13 @@ public class MagnificationProcessorTest {
    public void getMagnificationRegion_canControlFullscreenMagnification_returnRegion() {
        final Region region = new Region(10, 20, 100, 200);
        setMagnificationActivated(TEST_DISPLAY, MAGNIFICATION_MODE_FULLSCREEN);
        mMagnificationProcessor.getMagnificationRegion(TEST_DISPLAY,
        mMagnificationProcessor.getFullscreenMagnificationRegion(TEST_DISPLAY,
                region,  /* canControlMagnification= */true);

        verify(mMockFullScreenMagnificationController).getMagnificationRegion(eq(TEST_DISPLAY),
                eq(region));
    }

    @Test
    public void getMagnificationRegion_canControlWindowMagnification_returnRegion() {
        final Region region = new Region(10, 20, 100, 200);
        setMagnificationActivated(TEST_DISPLAY, MAGNIFICATION_MODE_WINDOW);
        mMagnificationProcessor.getMagnificationRegion(TEST_DISPLAY,
                region,  /* canControlMagnification= */true);

        verify(mMockWindowMagnificationManager).getMagnificationSourceBounds(eq(TEST_DISPLAY),
                eq(region));
    }

    @Test
    public void getMagnificationRegion_fullscreenModeNotRegistered_shouldRegisterThenUnregister() {
        final Region region = new Region(10, 20, 100, 200);
@@ -188,7 +175,7 @@ public class MagnificationProcessorTest {
                any());

        final Region result = new Region();
        mMagnificationProcessor.getMagnificationRegion(TEST_DISPLAY,
        mMagnificationProcessor.getFullscreenMagnificationRegion(TEST_DISPLAY,
                result, /* canControlMagnification= */true);
        assertEquals(region, result);
        verify(mMockFullScreenMagnificationController).register(TEST_DISPLAY);
@@ -237,7 +224,7 @@ public class MagnificationProcessorTest {
    public void reset_fullscreenMagnificationActivated() {
        setMagnificationActivated(TEST_DISPLAY, MAGNIFICATION_MODE_FULLSCREEN);

        mMagnificationProcessor.reset(TEST_DISPLAY, /* animate= */false);
        mMagnificationProcessor.resetFullscreenMagnification(TEST_DISPLAY, /* animate= */false);

        verify(mMockFullScreenMagnificationController).reset(TEST_DISPLAY, false);
    }
@@ -246,7 +233,7 @@ public class MagnificationProcessorTest {
    public void reset_windowMagnificationActivated() {
        setMagnificationActivated(TEST_DISPLAY, MAGNIFICATION_MODE_WINDOW);

        mMagnificationProcessor.reset(TEST_DISPLAY, /* animate= */false);
        mMagnificationProcessor.resetCurrentMagnification(TEST_DISPLAY, /* animate= */false);

        verify(mMockWindowMagnificationManager).reset(TEST_DISPLAY);
    }