Loading services/accessibility/java/com/android/server/accessibility/magnification/FullScreenMagnificationController.java +24 −3 Original line number Diff line number Diff line Loading @@ -79,6 +79,8 @@ public class FullScreenMagnificationController { private final ScreenStateObserver mScreenStateObserver; private final MagnificationRequestObserver mMagnificationRequestObserver; private int mUserId; private final long mMainThreadId; Loading Loading @@ -479,6 +481,8 @@ public class FullScreenMagnificationController { sendSpecToAnimation(mCurrentMagnificationSpec, animationCallback); if (isMagnifying() && (id != INVALID_ID)) { mIdOfLastServiceToMagnify = id; mMagnificationRequestObserver.onRequestMagnificationSpec(mDisplayId, mIdOfLastServiceToMagnify); } return changed; } Loading Loading @@ -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; } /** Loading Loading @@ -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); } } services/accessibility/java/com/android/server/accessibility/magnification/MagnificationController.java +14 −1 Original line number Diff line number Diff line Loading @@ -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}. Loading Loading @@ -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()); } } Loading services/tests/servicestests/src/com/android/server/accessibility/magnification/FullScreenMagnificationControllerTest.java +8 −3 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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; Loading @@ -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); Loading @@ -116,7 +120,7 @@ public class FullScreenMagnificationControllerTest { initMockWindowManager(); mFullScreenMagnificationController = new FullScreenMagnificationController( mMockControllerCtx, new Object()); mMockControllerCtx, new Object(), mRequestObserver); } @After Loading Loading @@ -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); Loading services/tests/servicestests/src/com/android/server/accessibility/magnification/FullScreenMagnificationGestureHandlerTest.java +4 −1 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -126,6 +127,8 @@ public class FullScreenMagnificationGestureHandlerTest { FullScreenMagnificationController mFullScreenMagnificationController; @Mock ScaleChangedListener mMockScaleChangedListener; @Mock MagnificationRequestObserver mMagnificationRequestObserver; private OffsettableClock mClock; private FullScreenMagnificationGestureHandler mMgh; Loading @@ -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; Loading services/tests/servicestests/src/com/android/server/accessibility/magnification/MagnificationControllerTest.java +11 −0 Original line number Diff line number Diff line Loading @@ -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); Loading Loading
services/accessibility/java/com/android/server/accessibility/magnification/FullScreenMagnificationController.java +24 −3 Original line number Diff line number Diff line Loading @@ -79,6 +79,8 @@ public class FullScreenMagnificationController { private final ScreenStateObserver mScreenStateObserver; private final MagnificationRequestObserver mMagnificationRequestObserver; private int mUserId; private final long mMainThreadId; Loading Loading @@ -479,6 +481,8 @@ public class FullScreenMagnificationController { sendSpecToAnimation(mCurrentMagnificationSpec, animationCallback); if (isMagnifying() && (id != INVALID_ID)) { mIdOfLastServiceToMagnify = id; mMagnificationRequestObserver.onRequestMagnificationSpec(mDisplayId, mIdOfLastServiceToMagnify); } return changed; } Loading Loading @@ -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; } /** Loading Loading @@ -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); } }
services/accessibility/java/com/android/server/accessibility/magnification/MagnificationController.java +14 −1 Original line number Diff line number Diff line Loading @@ -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}. Loading Loading @@ -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()); } } Loading
services/tests/servicestests/src/com/android/server/accessibility/magnification/FullScreenMagnificationControllerTest.java +8 −3 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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; Loading @@ -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); Loading @@ -116,7 +120,7 @@ public class FullScreenMagnificationControllerTest { initMockWindowManager(); mFullScreenMagnificationController = new FullScreenMagnificationController( mMockControllerCtx, new Object()); mMockControllerCtx, new Object(), mRequestObserver); } @After Loading Loading @@ -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); Loading
services/tests/servicestests/src/com/android/server/accessibility/magnification/FullScreenMagnificationGestureHandlerTest.java +4 −1 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -126,6 +127,8 @@ public class FullScreenMagnificationGestureHandlerTest { FullScreenMagnificationController mFullScreenMagnificationController; @Mock ScaleChangedListener mMockScaleChangedListener; @Mock MagnificationRequestObserver mMagnificationRequestObserver; private OffsettableClock mClock; private FullScreenMagnificationGestureHandler mMgh; Loading @@ -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; Loading
services/tests/servicestests/src/com/android/server/accessibility/magnification/MagnificationControllerTest.java +11 −0 Original line number Diff line number Diff line Loading @@ -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); Loading