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

Commit be41ea67 authored by mincheli's avatar mincheli
Browse files

Notifies window magnifcation changes for AccessibilityService (1/n)

See Design doc:  go/b200769372
To make the behavior consistent on the new platform,
The legcay callback,
  onMagnificationChanged(MagnificationController controller,
  Region region, float scale, float centerX, float centerY)
keep notifying only full-screen magnification change as
before.

To support listening to the magnification changes of all
magnification modes, the service should overide
The new callback proposed in T,
  onMagnificationChanged(MagnificationController controller,
  Region region, MagnificationConfig config).

TODO: Notify magnifcation change when window magnifier turns off

Bug: 203013925
Test: atest AccessibilityMagnificationTest,
    atest MagnificationControllerTest,
    atest WindowMagnificationManagerTest,
    atest WindowMagnificationControllerTest,
    atest FullScreenMagnificationControllerTest,

Change-Id: Ia73195a71f55bb26ef3f2eafce0dc73d8a65583b
parent a75f5a9a
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -3137,6 +3137,7 @@ package android.accessibilityservice {
  public static interface AccessibilityService.MagnificationController.OnMagnificationChangedListener {
    method public void onMagnificationChanged(@NonNull android.accessibilityservice.AccessibilityService.MagnificationController, @NonNull android.graphics.Region, float, float, float);
    method public default void onMagnificationChanged(@NonNull android.accessibilityservice.AccessibilityService.MagnificationController, @NonNull android.graphics.Region, @NonNull android.accessibilityservice.MagnificationConfig);
  }
  public static final class AccessibilityService.ScreenshotResult {
+52 −25
Original line number Diff line number Diff line
@@ -587,7 +587,7 @@ public abstract class AccessibilityService extends Service {
        boolean onKeyEvent(KeyEvent event);
        /** Magnification changed callbacks for different displays */
        void onMagnificationChanged(int displayId, @NonNull Region region,
                float scale, float centerX, float centerY);
                MagnificationConfig config);
        /** Callbacks for receiving motion events. */
        void onMotionEvent(MotionEvent event);
        /** Callback for tuch state changes. */
@@ -1183,14 +1183,14 @@ public abstract class AccessibilityService extends Service {
        }
    }

    private void onMagnificationChanged(int displayId, @NonNull Region region, float scale,
            float centerX, float centerY) {
    private void onMagnificationChanged(int displayId, @NonNull Region region,
            MagnificationConfig config) {
        MagnificationController controller;
        synchronized (mLock) {
            controller = mMagnificationControllers.get(displayId);
        }
        if (controller != null) {
            controller.dispatchMagnificationChanged(region, scale, centerX, centerY);
            controller.dispatchMagnificationChanged(region, config);
        }
    }

@@ -1328,8 +1328,8 @@ public abstract class AccessibilityService extends Service {
         * Dispatches magnification changes to any registered listeners. This
         * should be called on the service's main thread.
         */
        void dispatchMagnificationChanged(final @NonNull Region region, final float scale,
                final float centerX, final float centerY) {
        void dispatchMagnificationChanged(final @NonNull Region region,
                final MagnificationConfig config) {
            final ArrayMap<OnMagnificationChangedListener, Handler> entries;
            synchronized (mLock) {
                if (mListeners == null || mListeners.isEmpty()) {
@@ -1348,16 +1348,13 @@ public abstract class AccessibilityService extends Service {
                final OnMagnificationChangedListener listener = entries.keyAt(i);
                final Handler handler = entries.valueAt(i);
                if (handler != null) {
                    handler.post(new Runnable() {
                        @Override
                        public void run() {
                    handler.post(() -> {
                        listener.onMagnificationChanged(MagnificationController.this,
                                    region, scale, centerX, centerY);
                        }
                                region, config);
                    });
                } else {
                    // We're already on the main thread, just run the listener.
                    listener.onMagnificationChanged(this, region, scale, centerX, centerY);
                    listener.onMagnificationChanged(this, region, config);
                }
            }
        }
@@ -1665,6 +1662,10 @@ public abstract class AccessibilityService extends Service {
        public interface OnMagnificationChangedListener {
            /**
             * Called when the magnified region, scale, or center changes.
             * <p>
             * <strong>Note:</strong> This legacy callback notifies only full-screen
             * magnification change.
             * </p>
             *
             * @param controller the magnification controller
             * @param region the magnification region
@@ -1676,6 +1677,38 @@ public abstract class AccessibilityService extends Service {
             */
            void onMagnificationChanged(@NonNull MagnificationController controller,
                    @NonNull Region region, float scale, float centerX, float centerY);

            /**
             * Called when the magnified region, mode, scale, or center changes of
             * all magnification modes.
             * <p>
             * <strong>Note:</strong> This method can be overridden to listen to the
             * magnification changes of all magnification modes then the legacy callback
             * would not receive the notifications.
             * Skipping calling super when overriding this method results in
             * {@link #onMagnificationChanged(MagnificationController, Region, float, float, float)}
             * not getting called.
             * </p>
             *
             * @param controller the magnification controller
             * @param region the magnification region
             *               If the config mode is
             *               {@link MagnificationConfig#MAGNIFICATION_MODE_FULLSCREEN},
             *               it is the region of the screen currently active for magnification.
             *               that is the same region as {@link #getMagnificationRegion()}.
             *               If the config mode is
             *               {@link MagnificationConfig#MAGNIFICATION_MODE_WINDOW},
             *               it is the region of screen projected on the magnification window.
             * @param config The magnification config. That has the controlling magnification
             *               mode, the new scale and the new screen-relative center position
             */
            default void onMagnificationChanged(@NonNull MagnificationController controller,
                    @NonNull Region region, @NonNull MagnificationConfig config) {
                if (config.getMode() == MAGNIFICATION_MODE_FULLSCREEN) {
                    onMagnificationChanged(controller, region,
                            config.getScale(), config.getCenterX(), config.getCenterY());
                }
            }
        }
    }

@@ -2370,9 +2403,8 @@ public abstract class AccessibilityService extends Service {

            @Override
            public void onMagnificationChanged(int displayId, @NonNull Region region,
                    float scale, float centerX, float centerY) {
                AccessibilityService.this.onMagnificationChanged(displayId, region, scale,
                        centerX, centerY);
                    MagnificationConfig config) {
                AccessibilityService.this.onMagnificationChanged(displayId, region, config);
            }

            @Override
@@ -2496,12 +2528,10 @@ public abstract class AccessibilityService extends Service {

        /** Magnification changed callbacks for different displays */
        public void onMagnificationChanged(int displayId, @NonNull Region region,
                float scale, float centerX, float centerY) {
                MagnificationConfig config) {
            final SomeArgs args = SomeArgs.obtain();
            args.arg1 = region;
            args.arg2 = scale;
            args.arg3 = centerX;
            args.arg4 = centerY;
            args.arg2 = config;
            args.argi1 = displayId;

            final Message message = mCaller.obtainMessageO(DO_ON_MAGNIFICATION_CHANGED, args);
@@ -2660,13 +2690,10 @@ public abstract class AccessibilityService extends Service {
                    if (mConnectionId != AccessibilityInteractionClient.NO_ID) {
                        final SomeArgs args = (SomeArgs) message.obj;
                        final Region region = (Region) args.arg1;
                        final float scale = (float) args.arg2;
                        final float centerX = (float) args.arg3;
                        final float centerY = (float) args.arg4;
                        final MagnificationConfig config = (MagnificationConfig) args.arg2;
                        final int displayId = args.argi1;
                        args.recycle();
                        mCallback.onMagnificationChanged(displayId, region, scale,
                                centerX, centerY);
                        mCallback.onMagnificationChanged(displayId, region, config);
                    }
                    return;
                }
+2 −1
Original line number Diff line number Diff line
@@ -21,6 +21,7 @@ import android.graphics.Region;
import android.view.accessibility.AccessibilityEvent;
import android.view.accessibility.AccessibilityWindowInfo;
import android.accessibilityservice.AccessibilityGestureEvent;
import android.accessibilityservice.MagnificationConfig;
import android.view.KeyEvent;
import android.view.MotionEvent;

@@ -43,7 +44,7 @@ import android.view.MotionEvent;

    void onKeyEvent(in KeyEvent event, int sequence);

    void onMagnificationChanged(int displayId, in Region region, float scale, float centerX, float centerY);
    void onMagnificationChanged(int displayId, in Region region, in MagnificationConfig config);

    void onMotionEvent(in MotionEvent event);

+2 −1
Original line number Diff line number Diff line
@@ -22,6 +22,7 @@ import android.accessibilityservice.AccessibilityService.IAccessibilityServiceCl
import android.accessibilityservice.AccessibilityServiceInfo;
import android.accessibilityservice.IAccessibilityServiceClient;
import android.accessibilityservice.IAccessibilityServiceConnection;
import android.accessibilityservice.MagnificationConfig;
import android.annotation.IntDef;
import android.annotation.NonNull;
import android.annotation.Nullable;
@@ -1581,7 +1582,7 @@ public final class UiAutomation {

                @Override
                public void onMagnificationChanged(int displayId, @NonNull Region region,
                        float scale, float centerX, float centerY) {
                        MagnificationConfig config) {
                    /* do nothing */
                }

+7 −3
Original line number Diff line number Diff line
@@ -252,7 +252,12 @@ class WindowMagnificationController implements View.OnTouchListener, SurfaceHold
                                mMagnificationFrame.height());
                        mTransaction.setGeometry(mMirrorSurface, mSourceBounds, mTmpRect,
                                Surface.ROTATION_0).apply();
                        mWindowMagnifierCallback.onSourceBoundsChanged(mDisplayId, mSourceBounds);

                        // Notify source bounds change when the magnifier is not animating.
                        if (!mAnimationController.isAnimating()) {
                            mWindowMagnifierCallback.onSourceBoundsChanged(mDisplayId,
                                    mSourceBounds);
                        }
                    }
                };
        mUpdateStateDescriptionRunnable = () -> {
@@ -596,7 +601,6 @@ class WindowMagnificationController implements View.OnTouchListener, SurfaceHold
    private void modifyWindowMagnification(SurfaceControl.Transaction t) {
        mSfVsyncFrameProvider.postFrameCallback(mMirrorViewGeometryVsyncCallback);
        updateMirrorViewLayout();

    }

    /**
@@ -800,7 +804,7 @@ class WindowMagnificationController implements View.OnTouchListener, SurfaceHold
     *                          are as same as current values, or the transition is interrupted
     *                          due to the new transition request.
     */
    void enableWindowMagnification(float scale, float centerX, float centerY,
    public void enableWindowMagnification(float scale, float centerX, float centerY,
            float magnificationFrameOffsetRatioX, float magnificationFrameOffsetRatioY,
            @Nullable IRemoteMagnificationAnimationCallback animationCallback) {
        mAnimationController.enableWindowMagnification(scale, centerX, centerY,
Loading