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

Commit 2b5c3c6c authored by Hiroki Sato's avatar Hiroki Sato
Browse files

Fullscreen Magnification updates pointer icon on non-transient change

Changing pointer icon scale involves resource loading, which is
expensive. Thus, we want to change the size of pointer icon only when
the change is not transient, i.e., not during animation, user's gesture,
moving a slider bar in settings panel, etc.

In order to update it, this change adds `isScaleTransient` parameter to
all the entrance point of changing fullscreen magnification scale so
that when the change is actually applied, we can tell whether we should
update a pointer icon size.

The change itself is big, but most of them are mechanical change of
method signatures and the behavior is controlled behind the aconfig
flag.

Bug: 355734856
Test: Enable flag, and changing scale with slider or gesture will change pointer icons.
Test: atest com.android.server.accessibility.magnification
Flag: com.android.server.accessibility.magnification_enlarge_pointer

Change-Id: Ibd8c0aa05c047c3977f8d2e7fc5d50f2193705fa
parent 5a2c7673
Loading
Loading
Loading
Loading
+75 −18
Original line number Diff line number Diff line
@@ -397,7 +397,7 @@ public class FullScreenMagnificationController implements
                            mCurrentMagnificationSpec.offsetX, mCurrentMagnificationSpec.offsetY)) {
                        sendSpecToAnimation(mCurrentMagnificationSpec, null);
                    }
                    onMagnificationChangedLocked();
                    onMagnificationChangedLocked(/* isScaleTransient= */ false);
                }
                magnified.recycle();
            }
@@ -475,8 +475,16 @@ public class FullScreenMagnificationController implements
            return mIdOfLastServiceToMagnify;
        }

        /**
         * This is invoked whenever magnification change happens.
         *
         * @param isScaleTransient represents that if the scale is being changed and the changed
         *                         value may be short lived and be updated again soon.
         *                         Calling the method usually notifies input manager to update the
         *                         cursor scale, but setting this value {@code true} prevents it.
         */
        @GuardedBy("mLock")
        void onMagnificationChangedLocked() {
        void onMagnificationChangedLocked(boolean isScaleTransient) {
            final float scale = getScale();
            final float centerX = getCenterX();
            final float centerY = getCenterY();
@@ -499,6 +507,10 @@ public class FullScreenMagnificationController implements
            } else {
                hideThumbnail();
            }

            if (!isScaleTransient) {
                notifyScaleForInput(mDisplayId, scale);
            }
        }

        @GuardedBy("mLock")
@@ -612,8 +624,9 @@ public class FullScreenMagnificationController implements
         * Directly Zooms out the scale to 1f with animating the transition. This method is
         * triggered only by service automatically, such as when user context changed.
         */
        @GuardedBy("mLock")
        void zoomOutFromService() {
            setScaleAndCenter(1.0f, Float.NaN, Float.NaN,
            setScaleAndCenter(1.0f, Float.NaN, Float.NaN, /* isScaleTransient= */ false,
                    transformToStubCallback(true),
                    AccessibilityManagerService.MAGNIFICATION_GESTURE_HANDLER_ID);
            mZoomedOutFromService = true;
@@ -641,7 +654,7 @@ public class FullScreenMagnificationController implements
            setActivated(false);
            if (changed) {
                spec.clear();
                onMagnificationChangedLocked();
                onMagnificationChangedLocked(/* isScaleTransient= */ false);
            }
            mIdOfLastServiceToMagnify = INVALID_SERVICE_ID;
            sendSpecToAnimation(spec, animationCallback);
@@ -652,7 +665,7 @@ public class FullScreenMagnificationController implements
        }

        @GuardedBy("mLock")
        boolean setScale(float scale, float pivotX, float pivotY,
        boolean setScale(float scale, float pivotX, float pivotY, boolean isScaleTransient,
                boolean animate, int id) {
            if (!mRegistered) {
                return false;
@@ -675,12 +688,14 @@ public class FullScreenMagnificationController implements
            final float centerX = normPivotX + offsetX;
            final float centerY = normPivotY + offsetY;
            mIdOfLastServiceToMagnify = id;
            return setScaleAndCenter(scale, centerX, centerY, transformToStubCallback(animate), id);
            return setScaleAndCenter(scale, centerX, centerY, isScaleTransient,
                    transformToStubCallback(animate), id);
        }

        @GuardedBy("mLock")
        boolean setScaleAndCenter(float scale, float centerX, float centerY,
                MagnificationAnimationCallback animationCallback, int id) {
                boolean isScaleTransient, MagnificationAnimationCallback animationCallback,
                int id) {
            if (!mRegistered) {
                return false;
            }
@@ -697,7 +712,7 @@ public class FullScreenMagnificationController implements
                                + animationCallback + ", id = " + id + ")");
            }
            boolean changed = setActivated(true);
            changed |= updateMagnificationSpecLocked(scale, centerX, centerY);
            changed |= updateMagnificationSpecLocked(scale, centerX, centerY, isScaleTransient);
            sendSpecToAnimation(mCurrentMagnificationSpec, animationCallback);
            if (isActivated() && (id != INVALID_SERVICE_ID)) {
                mIdOfLastServiceToMagnify = id;
@@ -774,7 +789,9 @@ public class FullScreenMagnificationController implements
         * @return {@code true} if the magnification spec changed or {@code false}
         *         otherwise
         */
        boolean updateMagnificationSpecLocked(float scale, float centerX, float centerY) {
        @GuardedBy("mLock")
        boolean updateMagnificationSpecLocked(float scale, float centerX, float centerY,
                boolean isScaleTransient) {
            // Handle defaults.
            if (Float.isNaN(centerX)) {
                centerX = getCenterX();
@@ -802,7 +819,7 @@ public class FullScreenMagnificationController implements
            changed |= updateCurrentSpecWithOffsetsLocked(nonNormOffsetX, nonNormOffsetY);

            if (changed) {
                onMagnificationChangedLocked();
                onMagnificationChangedLocked(isScaleTransient);
            }

            return changed;
@@ -817,7 +834,7 @@ public class FullScreenMagnificationController implements
            final float nonNormOffsetX = mCurrentMagnificationSpec.offsetX - offsetX;
            final float nonNormOffsetY = mCurrentMagnificationSpec.offsetY - offsetY;
            if (updateCurrentSpecWithOffsetsLocked(nonNormOffsetX, nonNormOffsetY)) {
                onMagnificationChangedLocked();
                onMagnificationChangedLocked(/* isScaleTransient= */ false);
            }
            if (id != INVALID_SERVICE_ID) {
                mIdOfLastServiceToMagnify = id;
@@ -862,7 +879,7 @@ public class FullScreenMagnificationController implements
                            }
                            synchronized (mLock) {
                                mCurrentMagnificationSpec.setTo(lastSpecSent);
                                onMagnificationChangedLocked();
                                onMagnificationChangedLocked(/* isScaleTransient= */ false);
                            }
                        }
                    });
@@ -1466,20 +1483,24 @@ public class FullScreenMagnificationController implements
     * @param scale the target scale, must be >= 1
     * @param pivotX the screen-relative X coordinate around which to scale
     * @param pivotY the screen-relative Y coordinate around which to scale
     * @param isScaleTransient {@code true} if the scale is for a short time and potentially changed
     *                         soon. {@code false} otherwise.
     * @param animate {@code true} to animate the transition, {@code false}
     *                to transition immediately
     * @param id the ID of the service requesting the change
     * @return {@code true} if the magnification spec changed, {@code false} if
     *         the spec did not change
     */
    @SuppressWarnings("GuardedBy")
    // errorprone cannot recognize an inner class guarded by an outer class member.
    public boolean setScale(int displayId, float scale, float pivotX, float pivotY,
            boolean animate, int id) {
            boolean isScaleTransient, boolean animate, int id) {
        synchronized (mLock) {
            final DisplayMagnification display = mDisplays.get(displayId);
            if (display == null) {
                return false;
            }
            return display.setScale(scale, pivotX, pivotY, animate, id);
            return display.setScale(scale, pivotX, pivotY, isScaleTransient, animate, id);
        }
    }

@@ -1498,6 +1519,8 @@ public class FullScreenMagnificationController implements
     * @return {@code true} if the magnification spec changed, {@code false} if
     * the spec did not change
     */
    @SuppressWarnings("GuardedBy")
    // errorprone cannot recognize an inner class guarded by an outer class member.
    public boolean setCenter(int displayId, float centerX, float centerY, boolean animate, int id) {
        synchronized (mLock) {
            final DisplayMagnification display = mDisplays.get(displayId);
@@ -1505,7 +1528,7 @@ public class FullScreenMagnificationController implements
                return false;
            }
            return display.setScaleAndCenter(Float.NaN, centerX, centerY,
                    animate ? STUB_ANIMATION_CALLBACK : null, id);
                    /* isScaleTransient= */ false, animate ? STUB_ANIMATION_CALLBACK : null, id);
        }
    }

@@ -1528,7 +1551,32 @@ public class FullScreenMagnificationController implements
     */
    public boolean setScaleAndCenter(int displayId, float scale, float centerX, float centerY,
            boolean animate, int id) {
        return setScaleAndCenter(displayId, scale, centerX, centerY,
        return setScaleAndCenter(displayId, scale, centerX, centerY, /* isScaleTransient= */ false,
                transformToStubCallback(animate), id);
    }

    /**
     * Sets the scale and center of the magnified region, optionally
     * animating the transition. If animation is disabled, the transition
     * is immediate.
     *
     * @param displayId        The logical display id.
     * @param scale            the target scale, or {@link Float#NaN} to leave unchanged
     * @param centerX          the screen-relative X coordinate around which to
     *                         center and scale, or {@link Float#NaN} to leave unchanged
     * @param centerY          the screen-relative Y coordinate around which to
     *                         center and scale, or {@link Float#NaN} to leave unchanged
     * @param isScaleTransient {@code true} if the scale is for a short time and potentially changed
     *                         soon. {@code false} otherwise.
     * @param animate          {@code true} to animate the transition, {@code false}
     *                         to transition immediately
     * @param id               the ID of the service requesting the change
     * @return {@code true} if the magnification spec changed, {@code false} if
     * the spec did not change
     */
    public boolean setScaleAndCenter(int displayId, float scale, float centerX, float centerY,
            boolean isScaleTransient, boolean animate, int id) {
        return setScaleAndCenter(displayId, scale, centerX, centerY, isScaleTransient,
                transformToStubCallback(animate), id);
    }

@@ -1543,20 +1591,25 @@ public class FullScreenMagnificationController implements
     *                center and scale, or {@link Float#NaN} to leave unchanged
     * @param centerY the screen-relative Y coordinate around which to
     *                center and scale, or {@link Float#NaN} to leave unchanged
     * @param isScaleTransient {@code true} if the scale is for a short time and potentially changed
     *                         soon. {@code false} otherwise.
     * @param animationCallback Called when the animation result is valid.
     *                           {@code null} to transition immediately
     * @param id the ID of the service requesting the change
     * @return {@code true} if the magnification spec changed, {@code false} if
     *         the spec did not change
     */
    @SuppressWarnings("GuardedBy")
    // errorprone cannot recognize an inner class guarded by an outer class member.
    public boolean setScaleAndCenter(int displayId, float scale, float centerX, float centerY,
            MagnificationAnimationCallback animationCallback, int id) {
            boolean isScaleTransient, MagnificationAnimationCallback animationCallback, int id) {
        synchronized (mLock) {
            final DisplayMagnification display = mDisplays.get(displayId);
            if (display == null) {
                return false;
            }
            return display.setScaleAndCenter(scale, centerX, centerY, animationCallback, id);
            return display.setScaleAndCenter(scale, centerX, centerY, isScaleTransient,
                    animationCallback, id);
        }
    }

@@ -1571,6 +1624,8 @@ public class FullScreenMagnificationController implements
     *                screen pixels.
     * @param id      the ID of the service requesting the change
     */
    @SuppressWarnings("GuardedBy")
    // errorprone cannot recognize an inner class guarded by an outer class member.
    public void offsetMagnifiedRegion(int displayId, float offsetX, float offsetY, int id) {
        synchronized (mLock) {
            final DisplayMagnification display = mDisplays.get(displayId);
@@ -1669,6 +1724,8 @@ public class FullScreenMagnificationController implements
     *
     * @param displayId The logical display id.
     */
    @SuppressWarnings("GuardedBy")
    // errorprone cannot recognize an inner class guarded by an outer class member.
    private void zoomOutFromService(int displayId) {
        synchronized (mLock) {
            final DisplayMagnification display = mDisplays.get(displayId);
+3 −1
Original line number Diff line number Diff line
@@ -617,7 +617,8 @@ public class FullScreenMagnificationGestureHandler extends MagnificationGestureH
            }

            if (DEBUG_PANNING_SCALING) Slog.i(mLogTag, "Scaled content to: " + scale + "x");
            mFullScreenMagnificationController.setScale(mDisplayId, scale, pivotX, pivotY, false,
            mFullScreenMagnificationController.setScale(mDisplayId, scale, pivotX, pivotY,
                    /* isScaleTransient= */ true, /* animate= */ false,
                    AccessibilityManagerService.MAGNIFICATION_GESTURE_HANDLER_ID);

            checkShouldDetectPassPersistedScale();
@@ -1974,6 +1975,7 @@ public class FullScreenMagnificationGestureHandler extends MagnificationGestureH
                    /* scale= */ scale,
                    /* centerX= */ mPivotEdge.x,
                    /* centerY= */ mPivotEdge.y,
                    /* isScaleTransient= */ true,
                    /* animate= */ true,
                    /* id= */ AccessibilityManagerService.MAGNIFICATION_GESTURE_HANDLER_ID);
            if (scale == 1.0f) {
+3 −2
Original line number Diff line number Diff line
@@ -176,7 +176,8 @@ public class MagnificationController implements MagnificationConnectionManager.C
    public void onPerformScaleAction(int displayId, float scale, boolean updatePersistence) {
        if (getFullScreenMagnificationController().isActivated(displayId)) {
            getFullScreenMagnificationController().setScaleAndCenter(displayId, scale,
                    Float.NaN, Float.NaN, false, MAGNIFICATION_GESTURE_HANDLER_ID);
                    Float.NaN, Float.NaN, /* isScaleTransient= */ !updatePersistence, false,
                    MAGNIFICATION_GESTURE_HANDLER_ID);
            if (updatePersistence) {
                getFullScreenMagnificationController().persistScale(displayId);
            }
@@ -371,7 +372,7 @@ public class MagnificationController implements MagnificationConnectionManager.C
                        }
                        screenMagnificationController.setScaleAndCenter(displayId, targetScale,
                                magnificationCenter.x, magnificationCenter.y,
                                magnificationAnimationCallback, id);
                                /* isScaleTransient= */ false, magnificationAnimationCallback, id);
                    } else {
                        if (screenMagnificationController.isRegistered(displayId)) {
                            screenMagnificationController.reset(displayId, false);
+4 −1
Original line number Diff line number Diff line
@@ -480,7 +480,7 @@ public class MagnificationProcessorTest {
        if (config.getMode() == MAGNIFICATION_MODE_FULLSCREEN) {
            mFullScreenMagnificationControllerStub.resetAndStubMethods();
            mMockFullScreenMagnificationController.setScaleAndCenter(displayId, config.getScale(),
                    config.getCenterX(), config.getCenterY(), false, SERVICE_ID);
                    config.getCenterX(), config.getCenterY(), true, false, SERVICE_ID);
            mMagnificationManagerStub.deactivateIfNeed();
        } else if (config.getMode() == MAGNIFICATION_MODE_WINDOW) {
            mMagnificationManagerStub.resetAndStubMethods();
@@ -529,6 +529,9 @@ public class MagnificationProcessorTest {
                mCenterY = invocation.getArgument(3);
                return true;
            };
            doAnswer(enableMagnificationStubAnswer).when(
                    mScreenMagnificationController).setScaleAndCenter(eq(TEST_DISPLAY), anyFloat(),
                    anyFloat(), anyFloat(), anyBoolean(), anyBoolean(), eq(SERVICE_ID));
            doAnswer(enableMagnificationStubAnswer).when(
                    mScreenMagnificationController).setScaleAndCenter(eq(TEST_DISPLAY), anyFloat(),
                    anyFloat(), anyFloat(), anyBoolean(), eq(SERVICE_ID));
+113 −34

File changed.

Preview size limit exceeded, changes collapsed.

Loading