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

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

Merge changes from topic "355734856-magnification-enlarge-cursor" into main

* changes:
  Fullscreen Magnification updates pointer icon on non-transient change
  Enlarge pointer icon for magnification
parents b34540fe 2b5c3c6c
Loading
Loading
Loading
Loading
+104 −18
Original line number Diff line number Diff line
@@ -64,6 +64,7 @@ import com.android.server.LocalServices;
import com.android.server.accessibility.AccessibilityManagerService;
import com.android.server.accessibility.AccessibilityTraceManager;
import com.android.server.accessibility.Flags;
import com.android.server.input.InputManagerInternal;
import com.android.server.wm.WindowManagerInternal;

import java.util.ArrayList;
@@ -396,7 +397,7 @@ public class FullScreenMagnificationController implements
                            mCurrentMagnificationSpec.offsetX, mCurrentMagnificationSpec.offsetY)) {
                        sendSpecToAnimation(mCurrentMagnificationSpec, null);
                    }
                    onMagnificationChangedLocked();
                    onMagnificationChangedLocked(/* isScaleTransient= */ false);
                }
                magnified.recycle();
            }
@@ -474,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();
@@ -498,6 +507,10 @@ public class FullScreenMagnificationController implements
            } else {
                hideThumbnail();
            }

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

        @GuardedBy("mLock")
@@ -611,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;
@@ -640,7 +654,7 @@ public class FullScreenMagnificationController implements
            setActivated(false);
            if (changed) {
                spec.clear();
                onMagnificationChangedLocked();
                onMagnificationChangedLocked(/* isScaleTransient= */ false);
            }
            mIdOfLastServiceToMagnify = INVALID_SERVICE_ID;
            sendSpecToAnimation(spec, animationCallback);
@@ -651,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;
@@ -674,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;
            }
@@ -696,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;
@@ -773,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();
@@ -801,7 +819,7 @@ public class FullScreenMagnificationController implements
            changed |= updateCurrentSpecWithOffsetsLocked(nonNormOffsetX, nonNormOffsetY);

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

            return changed;
@@ -816,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;
@@ -861,7 +879,7 @@ public class FullScreenMagnificationController implements
                            }
                            synchronized (mLock) {
                                mCurrentMagnificationSpec.setTo(lastSpecSent);
                                onMagnificationChangedLocked();
                                onMagnificationChangedLocked(/* isScaleTransient= */ false);
                            }
                        }
                    });
@@ -955,6 +973,7 @@ public class FullScreenMagnificationController implements
                        context,
                        traceManager,
                        LocalServices.getService(WindowManagerInternal.class),
                        LocalServices.getService(InputManagerInternal.class),
                        new Handler(context.getMainLooper()),
                        context.getResources().getInteger(R.integer.config_longAnimTime)),
                lock,
@@ -1464,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);
        }
    }

@@ -1496,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);
@@ -1503,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);
        }
    }

@@ -1526,7 +1551,7 @@ 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);
    }

@@ -1541,20 +1566,50 @@ 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 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);
    }

    /**
     * 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 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);
        }
    }

@@ -1569,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);
@@ -1640,6 +1697,8 @@ public class FullScreenMagnificationController implements
     */
    public void persistScale(int displayId) {
        final float scale = getScale(displayId);
        notifyScaleForInput(displayId, scale);

        if (scale < MagnificationConstants.PERSISTED_SCALE_MIN_VALUE) {
            return;
        }
@@ -1665,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);
@@ -1690,6 +1751,20 @@ public class FullScreenMagnificationController implements
        }
    }

    /**
     * Notifies input manager that magnification scale changed non-transiently
     * so that pointer cursor is scaled as well.
     *
     * @param displayId The logical display id.
     * @param scale     The new scale factor.
     */
    public void notifyScaleForInput(int displayId, float scale) {
        if (Flags.magnificationEnlargePointer()) {
            mControllerCtx.getInputManager()
                    .setAccessibilityPointerIconScaleFactor(displayId, scale);
        }
    }

    /**
     * Resets all displays' magnification if last magnifying service is disabled.
     *
@@ -2166,6 +2241,7 @@ public class FullScreenMagnificationController implements
        private final Context mContext;
        private final AccessibilityTraceManager mTrace;
        private final WindowManagerInternal mWindowManager;
        private final InputManagerInternal mInputManager;
        private final Handler mHandler;
        private final Long mAnimationDuration;

@@ -2175,11 +2251,13 @@ public class FullScreenMagnificationController implements
        public ControllerContext(@NonNull Context context,
                @NonNull AccessibilityTraceManager traceManager,
                @NonNull WindowManagerInternal windowManager,
                @NonNull InputManagerInternal inputManager,
                @NonNull Handler handler,
                long animationDuration) {
            mContext = context;
            mTrace = traceManager;
            mWindowManager = windowManager;
            mInputManager = inputManager;
            mHandler = handler;
            mAnimationDuration = animationDuration;
        }
@@ -2208,6 +2286,14 @@ public class FullScreenMagnificationController implements
            return mWindowManager;
        }

        /**
         * @return InputManagerInternal
         */
        @NonNull
        public InputManagerInternal getInputManager() {
            return mInputManager;
        }

        /**
         * @return Handler for main looper
         */
+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);
+8 −0
Original line number Diff line number Diff line
@@ -262,4 +262,12 @@ public abstract class InputManagerInternal {
     */
    public abstract void handleKeyGestureInKeyGestureController(int deviceId, int[] keycodes,
            int modifierState, @KeyGestureEvent.KeyGestureType int event);

    /**
     * Sets the magnification scale factor for pointer icons.
     *
     * @param displayId   the ID of the display where the new scale factor is applied.
     * @param scaleFactor the new scale factor to be applied for pointer icons.
     */
    public abstract void setAccessibilityPointerIconScaleFactor(int displayId, float scaleFactor);
}
+9 −0
Original line number Diff line number Diff line
@@ -3506,6 +3506,11 @@ public class InputManagerService extends IInputManager.Stub
                int modifierState, @KeyGestureEvent.KeyGestureType int gestureType) {
            mKeyGestureController.handleKeyGesture(deviceId, keycodes, modifierState, gestureType);
        }

        @Override
        public void setAccessibilityPointerIconScaleFactor(int displayId, float scaleFactor) {
            InputManagerService.this.setAccessibilityPointerIconScaleFactor(displayId, scaleFactor);
        }
    }

    @Override
@@ -3688,6 +3693,10 @@ public class InputManagerService extends IInputManager.Stub
        mPointerIconCache.setPointerScale(scale);
    }

    void setAccessibilityPointerIconScaleFactor(int displayId, float scaleFactor) {
        mPointerIconCache.setAccessibilityScaleFactor(displayId, scaleFactor);
    }

    interface KeyboardBacklightControllerInterface {
        default void incrementKeyboardBacklight(int deviceId) {}
        default void decrementKeyboardBacklight(int deviceId) {}
Loading