From cdea71792595c4f74b8ad46ebeed534289a2363e Mon Sep 17 00:00:00 2001 From: Roy Chou Date: Thu, 2 Feb 2023 16:21:54 +0000 Subject: [PATCH] feat(#AlwaysOnMagnifier)!: Support always on feature in FullScreenMagnificationController Add variable mAlwaysOnMagnificationEnabled in FullScreenMagnificationController. If enabled is true, when onUserContextChanged method is triggered, the magnifier will zoom to 100% and keep in activated state. If enabled is false, the magnifier will be disabled. It's the original behavior. Bug: 146504200 Test: manual atest FullScreenMagnificationControllerTest Change-Id: Id7be1fe2cb66ce079f413103ea4e134b4542571c --- .../FullScreenMagnificationController.java | 42 +++++++++++++++---- ...FullScreenMagnificationControllerTest.java | 21 ++++++++++ 2 files changed, 55 insertions(+), 8 deletions(-) diff --git a/services/accessibility/java/com/android/server/accessibility/magnification/FullScreenMagnificationController.java b/services/accessibility/java/com/android/server/accessibility/magnification/FullScreenMagnificationController.java index 595cdec23b600..d7c5b5d92d7f3 100644 --- a/services/accessibility/java/com/android/server/accessibility/magnification/FullScreenMagnificationController.java +++ b/services/accessibility/java/com/android/server/accessibility/magnification/FullScreenMagnificationController.java @@ -57,6 +57,7 @@ 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; @@ -99,7 +100,8 @@ public class FullScreenMagnificationController implements private final Rect mTempRect = new Rect(); // Whether the following typing focus feature for magnification is enabled. private boolean mMagnificationFollowTypingEnabled = true; - + // Whether the always on magnification feature is enabled. + private boolean mAlwaysOnMagnificationEnabled = false; private final DisplayManagerInternal mDisplayManagerInternal; /** @@ -291,18 +293,15 @@ public class FullScreenMagnificationController implements @Override public void onDisplaySizeChanged() { - // Treat as context change and reset - final Message m = PooledLambda.obtainMessage( - FullScreenMagnificationController::resetIfNeeded, - FullScreenMagnificationController.this, mDisplayId, true); - mControllerCtx.getHandler().sendMessage(m); + // Treat as context change + onUserContextChanged(); } @Override public void onUserContextChanged() { final Message m = PooledLambda.obtainMessage( - FullScreenMagnificationController::resetIfNeeded, - FullScreenMagnificationController.this, mDisplayId, true); + FullScreenMagnificationController::onUserContextChanged, + FullScreenMagnificationController.this, mDisplayId); mControllerCtx.getHandler().sendMessage(m); } @@ -795,6 +794,33 @@ public class FullScreenMagnificationController implements return mMagnificationFollowTypingEnabled; } + void setAlwaysOnMagnificationEnabled(boolean enabled) { + mAlwaysOnMagnificationEnabled = enabled; + } + + boolean isAlwaysOnMagnificationEnabled() { + return mAlwaysOnMagnificationEnabled; + } + + /** + * if the magnifier with given displayId is activated: + * 1. if {@link #isAlwaysOnMagnificationEnabled()}, zoom the magnifier to 100%, + * 2. otherwise, reset the magnification. + * + * @param displayId The logical display id. + */ + void onUserContextChanged(int displayId) { + synchronized (mLock) { + if (isAlwaysOnMagnificationEnabled()) { + setScaleAndCenter(displayId, 1.0f, Float.NaN, Float.NaN, + true, + AccessibilityManagerService.MAGNIFICATION_GESTURE_HANDLER_ID); + } else { + reset(displayId, true); + } + } + } + /** * Remove the display magnification with given id. * diff --git a/services/tests/servicestests/src/com/android/server/accessibility/magnification/FullScreenMagnificationControllerTest.java b/services/tests/servicestests/src/com/android/server/accessibility/magnification/FullScreenMagnificationControllerTest.java index bf23d9dcbe96e..2d036fec11640 100644 --- a/services/tests/servicestests/src/com/android/server/accessibility/magnification/FullScreenMagnificationControllerTest.java +++ b/services/tests/servicestests/src/com/android/server/accessibility/magnification/FullScreenMagnificationControllerTest.java @@ -1196,6 +1196,27 @@ public class FullScreenMagnificationControllerTest { persistedScale); } + @Test + public void testOnContextChanged_alwaysOnFeatureDisabled_resetMagnification() { + setScaleToMagnifying(); + + mFullScreenMagnificationController.setAlwaysOnMagnificationEnabled(false); + mFullScreenMagnificationController.onUserContextChanged(DISPLAY_0); + + verify(mRequestObserver).onFullScreenMagnificationActivationState(eq(DISPLAY_0), eq(false)); + } + + @Test + public void testOnContextChanged_alwaysOnFeatureEnabled_setScaleTo1xAndStayActivated() { + setScaleToMagnifying(); + + mFullScreenMagnificationController.setAlwaysOnMagnificationEnabled(true); + mFullScreenMagnificationController.onUserContextChanged(DISPLAY_0); + + assertEquals(1.0f, mFullScreenMagnificationController.getScale(DISPLAY_0), 0); + assertTrue(mFullScreenMagnificationController.isActivated(DISPLAY_0)); + } + private void setScaleToMagnifying() { register(DISPLAY_0); float scale = 2.0f;