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

Commit 70439244 authored by Phil Weaver's avatar Phil Weaver
Browse files

Fix several accessibility magnification issues.

Clarifying region used for magnification as "magnificationRegion",
both in the public API and in the code. There's been significant
confusion about what "magnfifiedRegion" means. Removing
"availableRegion" from everywhere except where it's required, as
that region was identical to magnified/magnification region.

Trying to shut down magnification was a complex situation where
animations in progress and new magnification requests were tricky to
handle correctly. It was not possible to guarantee that the
magnification callbacks were unregistered consistently. There were
at least two situations that led to phone restarts:
1. If a triple tap was detected between unregistering the callbacks
and shutting down the input filter. In this case the magnification
request would go through.
2. If an animation had just started when magnification was turned
off, so the current magnification was 1.0 but the animator was
about to change it. In this case the callbacks would be unregistered,
and then the animator would start changing the magnification.

This change makes registering and unregistering magnification atomic.
It also makes MagnificationController stick around indefinitely once it
is created, registering and unregistering as needed to support
magnification gestures and services that control magnification. Services
that merely query the status of magnification no longer register for
callbacks.

One part of shutting down is turning off the animation and guaranteeing
that it won't try to make further changes. Adding a flag to
SpecAnimationBridge and a lock in that class so we can guarantee that
nothing happens when we aren't registered for magnification callbacks.

Also reconfiguring all accessibility options when a service stops to
make sure that only the features required by the current configuration
are enabled.

Bug: 27497138
Bug: 27821103
Change-Id: If697cbd34b117d82c8eee1ba7d0254089ee4241d
parent b1dea03f
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -2699,7 +2699,7 @@ package android.accessibilityservice {
    method public void addListener(android.accessibilityservice.AccessibilityService.MagnificationController.OnMagnificationChangedListener, android.os.Handler);
    method public float getCenterX();
    method public float getCenterY();
    method public android.graphics.Region getMagnifiedRegion();
    method public android.graphics.Region getMagnificationRegion();
    method public float getScale();
    method public boolean removeListener(android.accessibilityservice.AccessibilityService.MagnificationController.OnMagnificationChangedListener);
    method public boolean reset(boolean);
+1 −1
Original line number Diff line number Diff line
@@ -2803,7 +2803,7 @@ package android.accessibilityservice {
    method public void addListener(android.accessibilityservice.AccessibilityService.MagnificationController.OnMagnificationChangedListener, android.os.Handler);
    method public float getCenterX();
    method public float getCenterY();
    method public android.graphics.Region getMagnifiedRegion();
    method public android.graphics.Region getMagnificationRegion();
    method public float getScale();
    method public boolean removeListener(android.accessibilityservice.AccessibilityService.MagnificationController.OnMagnificationChangedListener);
    method public boolean reset(boolean);
+1 −1
Original line number Diff line number Diff line
@@ -2699,7 +2699,7 @@ package android.accessibilityservice {
    method public void addListener(android.accessibilityservice.AccessibilityService.MagnificationController.OnMagnificationChangedListener, android.os.Handler);
    method public float getCenterX();
    method public float getCenterY();
    method public android.graphics.Region getMagnifiedRegion();
    method public android.graphics.Region getMagnificationRegion();
    method public float getScale();
    method public boolean removeListener(android.accessibilityservice.AccessibilityService.MagnificationController.OnMagnificationChangedListener);
    method public boolean reset(boolean);
+16 −8
Original line number Diff line number Diff line
@@ -925,18 +925,25 @@ public abstract class AccessibilityService extends Service {
        }

        /**
         * Returns the region of the screen currently being magnified. If
         * magnification is not enabled, the returned region will be empty.
         * Returns the region of the screen currently active for magnification. Changes to
         * magnification scale and center only affect this portion of the screen. The rest of the
         * screen, for example input methods, cannot be magnified. This region is relative to the
         * unscaled screen and is independent of the scale and center point.
         * <p>
         * The returned region will be empty if magnification is not active. Magnification is active
         * if magnification gestures are enabled or if a service is running that can control
         * magnification.
         * <p>
         * <strong>Note:</strong> If the service is not yet connected (e.g.
         * {@link AccessibilityService#onServiceConnected()} has not yet been
         * called) or the service has been disconnected, this method will
         * return an empty region.
         *
         * @return the screen-relative bounds of the magnified region
         * @return the region of the screen currently active for magnification, or an empty region
         * if magnification is not active.
         */
        @NonNull
        public Region getMagnifiedRegion() {
        public Region getMagnificationRegion() {
            final IAccessibilityServiceConnection connection =
                    AccessibilityInteractionClient.getInstance().getConnection(
                            mService.mConnectionId);
@@ -1049,11 +1056,12 @@ public abstract class AccessibilityService extends Service {
             * Called when the magnified region, scale, or center changes.
             *
             * @param controller the magnification controller
             * @param region the new magnified region, may be empty if
             *               magnification is not enabled (e.g. scale is 1)
             * @param region the magnification region
             * @param scale the new scale
             * @param centerX the new X coordinate around which magnification is focused
             * @param centerY the new Y coordinate around which magnification is focused
             * @param centerX the new X coordinate, in unscaled coordinates, around which
             * magnification is focused
             * @param centerY the new Y coordinate, in unscaled coordinates, around which
             * magnification is focused
             */
            void onMagnificationChanged(@NonNull MagnificationController controller,
                    @NonNull Region region, float scale, float centerX, float centerY);
+7 −10
Original line number Diff line number Diff line
@@ -54,13 +54,12 @@ public abstract class WindowManagerInternal {
    public interface MagnificationCallbacks {

        /**
         * Called when the bounds of the screen content that is magnified changed.
         * Note that not the entire screen is magnified.
         * Called when the region where magnification operates changes. Note that this isn't the
         * entire screen. For example, IMEs are not magnified.
         *
         * @param magnifiedBounds the currently magnified region
         * @param availableBounds the region available for magnification
         * @param magnificationRegion the current magnification region
         */
        public void onMagnifiedBoundsChanged(Region magnifiedBounds, Region availableBounds);
        public void onMagnificationRegionChanged(Region magnificationRegion);

        /**
         * Called when an application requests a rectangle on the screen to allow
@@ -158,13 +157,11 @@ public abstract class WindowManagerInternal {
    public abstract void setMagnificationSpec(MagnificationSpec spec);

    /**
     * Obtains the magnified and available regions.
     * Obtains the magnification regions.
     *
     * @param outMagnified the currently magnified region
     * @param outAvailable the region available for magnification
     * @param magnificationRegion the current magnification region
     */
    public abstract void getMagnificationRegions(@NonNull Region outMagnified,
            @NonNull Region outAvailable);
    public abstract void getMagnificationRegion(@NonNull Region magnificationRegion);

    /**
     * Gets the magnification and translation applied to a window given its token.
Loading