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

Commit 6150a003 authored by ryanlwlin's avatar ryanlwlin
Browse files

Disable Window magnification for magnification API

To avoid window magnification and full-screen magniification are both
visible while developers use full-screen magnification API, we disable
window magnification if non-default MagnificationSpec is requested by
the AccessibilityService.

Test: atest com.android.server.accessibility.magnification
manually Test: enable window magnification and use Voice Access to
enable full-screen magnification.
Bug: 146475460

Change-Id: I76e0191f8296ddf48bbf41b8cf78113ed797226b
parent abd78597
Loading
Loading
Loading
Loading
+24 −3
Original line number Diff line number Diff line
@@ -79,6 +79,8 @@ public class FullScreenMagnificationController {

    private final ScreenStateObserver mScreenStateObserver;

    private final MagnificationRequestObserver mMagnificationRequestObserver;

    private int mUserId;

    private final long mMainThreadId;
@@ -479,6 +481,8 @@ public class FullScreenMagnificationController {
            sendSpecToAnimation(mCurrentMagnificationSpec, animationCallback);
            if (isMagnifying() && (id != INVALID_ID)) {
                mIdOfLastServiceToMagnify = id;
                mMagnificationRequestObserver.onRequestMagnificationSpec(mDisplayId,
                        mIdOfLastServiceToMagnify);
            }
            return changed;
        }
@@ -609,22 +613,27 @@ public class FullScreenMagnificationController {
     * FullScreenMagnificationController Constructor
     */
    public FullScreenMagnificationController(@NonNull Context context,
            @NonNull AccessibilityManagerService ams, @NonNull Object lock) {
            @NonNull AccessibilityManagerService ams, @NonNull Object lock,
            @NonNull MagnificationRequestObserver magnificationRequestObserver) {
        this(new ControllerContext(context, ams,
                LocalServices.getService(WindowManagerInternal.class),
                new Handler(context.getMainLooper()),
                context.getResources().getInteger(R.integer.config_longAnimTime)), lock);
                context.getResources().getInteger(R.integer.config_longAnimTime)), lock,
                magnificationRequestObserver);
    }

    /**
     * Constructor for tests
     */
    @VisibleForTesting
    public FullScreenMagnificationController(@NonNull ControllerContext ctx, @NonNull Object lock) {
    public FullScreenMagnificationController(@NonNull ControllerContext ctx,
            @NonNull Object lock,
            @NonNull MagnificationRequestObserver magnificationRequestObserver) {
        mControllerCtx = ctx;
        mLock = lock;
        mMainThreadId = mControllerCtx.getContext().getMainLooper().getThread().getId();
        mScreenStateObserver = new ScreenStateObserver(mControllerCtx.getContext(), this);
        mMagnificationRequestObserver = magnificationRequestObserver;
    }

    /**
@@ -1487,4 +1496,16 @@ public class FullScreenMagnificationController {
    private static MagnificationAnimationCallback transformToStubCallback(boolean animate) {
        return animate ? STUB_ANIMATION_CALLBACK : null;
    }

    interface  MagnificationRequestObserver {

        /**
         * Called when the {@link MagnificationSpec} is changed with non-default
         * scale by the service.
         *
         * @param displayId the logical display id
         * @param serviceId the ID of the service requesting the change
         */
        void onRequestMagnificationSpec(int displayId, int serviceId);
    }
}
+14 −1
Original line number Diff line number Diff line
@@ -128,6 +128,19 @@ public class MagnificationController {
        setDisableMagnificationCallbackLocked(displayId, animationEndCallback);
    }

    void onRequestMagnificationSpec(int displayId, int serviceId) {
        synchronized (mLock) {
            if (serviceId == AccessibilityManagerService.MAGNIFICATION_GESTURE_HANDLER_ID) {
                return;
            }
            if (mWindowMagnificationMgr == null
                    || !mWindowMagnificationMgr.isWindowMagnifierEnabled(displayId)) {
                return;
            }
            mWindowMagnificationMgr.disableWindowMagnification(displayId, false);
        }
    }

    /**
     * Updates the active user ID of {@link FullScreenMagnificationController} and {@link
     * WindowMagnificationManager}.
@@ -184,7 +197,7 @@ public class MagnificationController {
        synchronized (mLock) {
            if (mFullScreenMagnificationController == null) {
                mFullScreenMagnificationController = new FullScreenMagnificationController(mContext,
                        mAms, mLock);
                        mAms, mLock, this::onRequestMagnificationSpec);
                mFullScreenMagnificationController.setUserId(mAms.getCurrentUserIdLocked());
            }
        }
+8 −3
Original line number Diff line number Diff line
@@ -16,6 +16,8 @@

package com.android.server.accessibility.magnification;

import static com.android.server.accessibility.magnification.FullScreenMagnificationController.MagnificationRequestObserver;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertThat;
@@ -93,6 +95,10 @@ public class FullScreenMagnificationControllerTest {
    final Context mMockContext = mock(Context.class);
    final AccessibilityManagerService mMockAms = mock(AccessibilityManagerService.class);
    final WindowManagerInternal mMockWindowManager = mock(WindowManagerInternal.class);
    private final MagnificationAnimationCallback mAnimationCallback = mock(
            MagnificationAnimationCallback.class);
    private final MagnificationRequestObserver mRequestObserver = mock(
            MagnificationRequestObserver.class);
    final MessageCapturingHandler mMessageCapturingHandler = new MessageCapturingHandler(null);

    ValueAnimator mMockValueAnimator;
@@ -100,12 +106,10 @@ public class FullScreenMagnificationControllerTest {
    ValueAnimator.AnimatorListener mStateListener;

    FullScreenMagnificationController mFullScreenMagnificationController;
    MagnificationAnimationCallback mAnimationCallback;

    @Before
    public void setUp() {
        Looper looper = InstrumentationRegistry.getContext().getMainLooper();
        mAnimationCallback = Mockito.mock(MagnificationAnimationCallback.class);
        // Pretending ID of the Thread associated with looper as main thread ID in controller
        when(mMockContext.getMainLooper()).thenReturn(looper);
        when(mMockControllerCtx.getContext()).thenReturn(mMockContext);
@@ -116,7 +120,7 @@ public class FullScreenMagnificationControllerTest {
        initMockWindowManager();

        mFullScreenMagnificationController = new FullScreenMagnificationController(
                mMockControllerCtx, new Object());
                mMockControllerCtx, new Object(), mRequestObserver);
    }

    @After
@@ -345,6 +349,7 @@ public class FullScreenMagnificationControllerTest {
        verify(mMockAms).notifyMagnificationChanged(displayId,
                INITIAL_MAGNIFICATION_REGION, scale, newCenter.x, newCenter.y);
        verify(mMockValueAnimator).start();
        verify(mRequestObserver).onRequestMagnificationSpec(displayId, SERVICE_ID_1);

        // Initial value
        when(mMockValueAnimator.getAnimatedFraction()).thenReturn(0.0f);
+4 −1
Original line number Diff line number Diff line
@@ -53,6 +53,7 @@ import androidx.test.runner.AndroidJUnit4;

import com.android.server.accessibility.AccessibilityManagerService;
import com.android.server.accessibility.EventStreamTransformation;
import com.android.server.accessibility.magnification.FullScreenMagnificationController.MagnificationRequestObserver;
import com.android.server.accessibility.magnification.MagnificationGestureHandler.ScaleChangedListener;
import com.android.server.testutils.OffsettableClock;
import com.android.server.testutils.TestHandler;
@@ -126,6 +127,8 @@ public class FullScreenMagnificationGestureHandlerTest {
    FullScreenMagnificationController mFullScreenMagnificationController;
    @Mock
    ScaleChangedListener mMockScaleChangedListener;
    @Mock
    MagnificationRequestObserver mMagnificationRequestObserver;

    private OffsettableClock mClock;
    private FullScreenMagnificationGestureHandler mMgh;
@@ -148,7 +151,7 @@ public class FullScreenMagnificationGestureHandlerTest {
        when(mockController.getAnimationDuration()).thenReturn(1000L);
        when(mockWindowManager.setMagnificationCallbacks(eq(DISPLAY_0), any())).thenReturn(true);
        mFullScreenMagnificationController = new FullScreenMagnificationController(mockController,
                new Object()) {
                new Object(), mMagnificationRequestObserver) {
            @Override
            public boolean magnificationRegionContains(int displayId, float x, float y) {
                return true;
+11 −0
Original line number Diff line number Diff line
@@ -250,6 +250,17 @@ public class MagnificationControllerTest {
        verify(mScreenMagnificationController).setUserId(CURRENT_USER_ID);
        verify(mWindowMagnificationManager).setUserId(CURRENT_USER_ID);
    }

    @Test
    public void onMagnificationRequest_windowMagnifying_disableWindow() throws RemoteException {
        setMagnificationEnabled(MODE_WINDOW);

        mMagnificationController.onRequestMagnificationSpec(TEST_DISPLAY, 1);
        mMockConnection.invokeCallbacks();

        assertFalse(mWindowMagnificationManager.isWindowMagnifierEnabled(TEST_DISPLAY));
    }

    private void setMagnificationEnabled(int mode) throws RemoteException {

        setMagnificationEnabled(mode, MAGNIFIED_CENTER_X, MAGNIFIED_CENTER_Y);