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

Commit 189978a7 authored by Minche Li's avatar Minche Li Committed by Android (Google) Code Review
Browse files

Merge "Refactors FullScreenMagnificationController#onMagnificationChangedLocked"

parents 3999df85 3c91f067
Loading
Loading
Loading
Loading
+12 −2
Original line number Diff line number Diff line
@@ -1363,8 +1363,18 @@ public class AccessibilityManagerService extends IAccessibilityManager.Stub
     * </p>
     *
     * @param displayId The logical display id
     * @param region the new magnified region, may be empty if
     *               magnification is not enabled (e.g. scale is 1)
     * @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.
     *               the returned region will be empty if the magnification is not active
     *               (e.g. scale is 1. And the magnification is active if magnification
     *               gestures are enabled or if a service is running that can control
     *               magnification.
     *               If the config mode is
     *               {@link MagnificationConfig#MAGNIFICATION_MODE_WINDOW},
     *               it is the region of screen projected on the magnification window.
     *               The region will be empty if magnification is not activated.
     * @param config The magnification config. That has magnification mode, the new scale and the
     *              new screen-relative center position
     */
+18 −18
Original line number Diff line number Diff line
@@ -50,7 +50,6 @@ import com.android.internal.annotations.GuardedBy;
import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.util.function.pooled.PooledLambda;
import com.android.server.LocalServices;
import com.android.server.accessibility.AccessibilityManagerService;
import com.android.server.accessibility.AccessibilityTraceManager;
import com.android.server.wm.WindowManagerInternal;

@@ -374,9 +373,8 @@ public class FullScreenMagnificationController implements
                    .setScale(getScale())
                    .setCenterX(getCenterX())
                    .setCenterY(getCenterY()).build();
            mControllerCtx.getAms().notifyMagnificationChanged(mDisplayId,
                    mMagnificationRegion,
                    config);
            mMagnificationInfoChangedCallback.onFullScreenMagnificationChanged(mDisplayId,
                    mMagnificationRegion, config);
            if (mUnregisterPending && !isMagnifying()) {
                unregister(mDeleteAfterUnregister);
            }
@@ -665,10 +663,10 @@ public class FullScreenMagnificationController implements
     * FullScreenMagnificationController Constructor
     */
    public FullScreenMagnificationController(@NonNull Context context,
            @NonNull AccessibilityManagerService ams, @NonNull Object lock,
            @NonNull AccessibilityTraceManager traceManager, @NonNull Object lock,
            @NonNull MagnificationInfoChangedCallback magnificationInfoChangedCallback,
            @NonNull MagnificationScaleProvider scaleProvider) {
        this(new ControllerContext(context, ams,
        this(new ControllerContext(context, traceManager,
                LocalServices.getService(WindowManagerInternal.class),
                new Handler(context.getMainLooper()),
                context.getResources().getInteger(R.integer.config_longAnimTime)), lock,
@@ -1521,7 +1519,6 @@ public class FullScreenMagnificationController implements
    @VisibleForTesting
    public static class ControllerContext {
        private final Context mContext;
        private final AccessibilityManagerService mAms;
        private final AccessibilityTraceManager mTrace;
        private final WindowManagerInternal mWindowManager;
        private final Handler mHandler;
@@ -1531,13 +1528,12 @@ public class FullScreenMagnificationController implements
         * Constructor for ControllerContext.
         */
        public ControllerContext(@NonNull Context context,
                @NonNull AccessibilityManagerService ams,
                @NonNull AccessibilityTraceManager traceManager,
                @NonNull WindowManagerInternal windowManager,
                @NonNull Handler handler,
                long animationDuration) {
            mContext = context;
            mAms = ams;
            mTrace = ams.getTraceManager();
            mTrace = traceManager;
            mWindowManager = windowManager;
            mHandler = handler;
            mAnimationDuration = animationDuration;
@@ -1551,14 +1547,6 @@ public class FullScreenMagnificationController implements
            return mContext;
        }

        /**
         * @return AccessibilityManagerService
         */
        @NonNull
        public AccessibilityManagerService getAms() {
            return mAms;
        }

        /**
         * @return AccessibilityTraceManager
         */
@@ -1632,5 +1620,17 @@ public class FullScreenMagnificationController implements
         *                           hidden.
         */
        void onImeWindowVisibilityChanged(boolean shown);

        /**
         * Called when the magnification spec changed.
         *
         * @param displayId The logical display id
         * @param region    The region of the screen currently active for magnification.
         *                  The returned region will be empty if the magnification is not active.
         * @param config    The magnification config. That has magnification mode, the new scale and
         *                  the new screen-relative center position
         */
        void onFullScreenMagnificationChanged(int displayId, @NonNull Region region,
                @NonNull MagnificationConfig config);
    }
}
+7 −1
Original line number Diff line number Diff line
@@ -405,6 +405,12 @@ public class MagnificationController implements WindowMagnificationManager.Callb
        mAms.notifyMagnificationChanged(displayId, new Region(bounds), config);
    }

    @Override
    public void onFullScreenMagnificationChanged(int displayId, @NonNull Region region,
            @NonNull MagnificationConfig config) {
        mAms.notifyMagnificationChanged(displayId, region, config);
    }

    private void disableFullScreenMagnificationIfNeeded(int displayId) {
        final FullScreenMagnificationController fullScreenMagnificationController =
                getFullScreenMagnificationController();
@@ -590,7 +596,7 @@ public class MagnificationController implements WindowMagnificationManager.Callb
        synchronized (mLock) {
            if (mFullScreenMagnificationController == null) {
                mFullScreenMagnificationController = new FullScreenMagnificationController(mContext,
                        mAms, mLock, this, mScaleProvider);
                        mAms.getTraceManager(), mLock, this, mScaleProvider);
            }
        }
        return mFullScreenMagnificationController;
+10 −14
Original line number Diff line number Diff line
@@ -52,7 +52,6 @@ import android.view.accessibility.MagnificationAnimationCallback;
import androidx.test.InstrumentationRegistry;
import androidx.test.runner.AndroidJUnit4;

import com.android.server.accessibility.AccessibilityManagerService;
import com.android.server.accessibility.AccessibilityTraceManager;
import com.android.server.accessibility.test.MessageCapturingHandler;
import com.android.server.wm.WindowManagerInternal;
@@ -94,7 +93,6 @@ public class FullScreenMagnificationControllerTest {
    final FullScreenMagnificationController.ControllerContext mMockControllerCtx =
            mock(FullScreenMagnificationController.ControllerContext.class);
    final Context mMockContext = mock(Context.class);
    final AccessibilityManagerService mMockAms = mock(AccessibilityManagerService.class);
    final AccessibilityTraceManager mMockTraceManager = mock(AccessibilityTraceManager.class);
    final WindowManagerInternal mMockWindowManager = mock(WindowManagerInternal.class);
    private final MagnificationAnimationCallback mAnimationCallback = mock(
@@ -121,12 +119,10 @@ public class FullScreenMagnificationControllerTest {
        // Pretending ID of the Thread associated with looper as main thread ID in controller
        when(mMockContext.getMainLooper()).thenReturn(looper);
        when(mMockControllerCtx.getContext()).thenReturn(mMockContext);
        when(mMockControllerCtx.getAms()).thenReturn(mMockAms);
        when(mMockControllerCtx.getTraceManager()).thenReturn(mMockTraceManager);
        when(mMockControllerCtx.getWindowManager()).thenReturn(mMockWindowManager);
        when(mMockControllerCtx.getHandler()).thenReturn(mMessageCapturingHandler);
        when(mMockControllerCtx.getAnimationDuration()).thenReturn(1000L);
        when(mMockAms.getTraceManager()).thenReturn(mMockTraceManager);
        initMockWindowManager();

        mFullScreenMagnificationController = new FullScreenMagnificationController(
@@ -357,8 +353,8 @@ public class FullScreenMagnificationControllerTest {
        assertEquals(newCenter.x, mFullScreenMagnificationController.getCenterX(displayId), 0.5);
        assertEquals(newCenter.y, mFullScreenMagnificationController.getCenterY(displayId), 0.5);
        assertThat(getCurrentMagnificationSpec(displayId), closeTo(endSpec));
        verify(mMockAms).notifyMagnificationChanged(eq(displayId), eq(INITIAL_MAGNIFICATION_REGION),
                mConfigCaptor.capture());
        verify(mRequestObserver).onFullScreenMagnificationChanged(eq(displayId),
                eq(INITIAL_MAGNIFICATION_REGION), mConfigCaptor.capture());
        assertConfigEquals(config, mConfigCaptor.getValue());
        verify(mMockValueAnimator).start();
        verify(mRequestObserver).onRequestMagnificationSpec(displayId, SERVICE_ID_1);
@@ -501,7 +497,7 @@ public class FullScreenMagnificationControllerTest {
        mMessageCapturingHandler.sendAllMessages();
        MagnificationConfig config = buildConfig(1.0f, OTHER_MAGNIFICATION_BOUNDS.centerX(),
                OTHER_MAGNIFICATION_BOUNDS.centerY());
        verify(mMockAms).notifyMagnificationChanged(eq(displayId), eq(OTHER_REGION),
        verify(mRequestObserver).onFullScreenMagnificationChanged(eq(displayId), eq(OTHER_REGION),
                mConfigCaptor.capture());
        assertConfigEquals(config, mConfigCaptor.getValue());
    }
@@ -655,9 +651,9 @@ public class FullScreenMagnificationControllerTest {
        register(displayId);
        zoomIn2xToMiddle(displayId);
        mMessageCapturingHandler.sendAllMessages();
        reset(mMockAms);
        reset(mRequestObserver);
        assertTrue(mFullScreenMagnificationController.resetIfNeeded(displayId, false));
        verify(mMockAms).notifyMagnificationChanged(eq(displayId),
        verify(mRequestObserver).onFullScreenMagnificationChanged(eq(displayId),
                eq(INITIAL_MAGNIFICATION_REGION), any(MagnificationConfig.class));
        assertFalse(mFullScreenMagnificationController.isMagnifying(displayId));
        assertFalse(mFullScreenMagnificationController.resetIfNeeded(displayId, false));
@@ -676,8 +672,8 @@ public class FullScreenMagnificationControllerTest {
        assertFalse(mFullScreenMagnificationController.reset(displayId, mAnimationCallback));
        mMessageCapturingHandler.sendAllMessages();

        verify(mMockAms, never()).notifyMagnificationChanged(eq(displayId), any(Region.class),
                any(MagnificationConfig.class));
        verify(mRequestObserver, never()).onFullScreenMagnificationChanged(eq(displayId),
                any(Region.class), any(MagnificationConfig.class));
        verify(mAnimationCallback).onResult(true);
    }

@@ -1072,8 +1068,8 @@ public class FullScreenMagnificationControllerTest {
        when(mMockValueAnimator.getAnimatedFraction()).thenReturn(0.0f);
        mTargetAnimationListener.onAnimationUpdate(mMockValueAnimator);
        verify(mMockWindowManager).setMagnificationSpec(eq(displayId), eq(startSpec));
        verify(mMockAms).notifyMagnificationChanged(eq(displayId), eq(INITIAL_MAGNIFICATION_REGION),
                mConfigCaptor.capture());
        verify(mRequestObserver).onFullScreenMagnificationChanged(eq(displayId),
                eq(INITIAL_MAGNIFICATION_REGION), mConfigCaptor.capture());
        assertConfigEquals(config, mConfigCaptor.getValue());
        Mockito.reset(mMockWindowManager);

@@ -1097,7 +1093,7 @@ public class FullScreenMagnificationControllerTest {

        // Animation should have been restarted
        verify(mMockValueAnimator, times(2)).start();
        verify(mMockAms, times(2)).notifyMagnificationChanged(eq(displayId),
        verify(mRequestObserver, times(2)).onFullScreenMagnificationChanged(eq(displayId),
                eq(INITIAL_MAGNIFICATION_REGION), mConfigCaptor.capture());
        assertConfigEquals(newConfig, mConfigCaptor.getValue());

+0 −2
Original line number Diff line number Diff line
@@ -151,8 +151,6 @@ public class FullScreenMagnificationGestureHandlerTest {
                mock(FullScreenMagnificationController.ControllerContext.class);
        final WindowManagerInternal mockWindowManager = mock(WindowManagerInternal.class);
        when(mockController.getContext()).thenReturn(mContext);
        when(mockController.getAms()).thenReturn(mMockAccessibilityManagerService);
        when(mMockAccessibilityManagerService.getTraceManager()).thenReturn(mMockTraceManager);
        when(mockController.getTraceManager()).thenReturn(mMockTraceManager);
        when(mockController.getWindowManager()).thenReturn(mockWindowManager);
        when(mockController.getHandler()).thenReturn(new Handler(mContext.getMainLooper()));
Loading