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

Commit cdea7179 authored by Roy Chou's avatar Roy Chou
Browse files

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
parent e5d3844e
Loading
Loading
Loading
Loading
+34 −8
Original line number Diff line number Diff line
@@ -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.
     *
+21 −0
Original line number Diff line number Diff line
@@ -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;