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

Commit f7ff2c89 authored by mincheli's avatar mincheli
Browse files

Handles magnification scale change when requesting Accessibility action

The magnification sale should be consistent between a11y framework
and systemUi. So when a user requests to perfom scale a11y action by
systemUi, We need to handle it in Framework to ensure consistency
of the magnification scale.

Bug: 170791657
Test: atest WindowMagnificationTest WindowMagnificationManagerTest
WindowMagnificationControllerTest MagnificationControllerTest
Change-Id: Iaa34e66f29b320be971d416ce38d770b2265915f

Change-Id: I0598accefd62a8cefd93bda6163ac704fdd96cba
parent b27f59f6
Loading
Loading
Loading
Loading
+10 −0
Original line number Diff line number Diff line
@@ -50,4 +50,14 @@ import android.graphics.Rect;
     * @param sourceBounds The magnified bounds in screen coordinates.
     */
    void onSourceBoundsChanged(int displayId, in Rect sourceBounds);

    /**
     * Called when the accessibility action of scale requests to be performed.
     * It is invoked from System UI. And the action is provided by the mirror window.
     *
     * @param displayId The logical display id.
     * @param scale the target scale, or {@link Float#NaN} to leave unchanged
     */
    void onPerformScaleAction(int displayId, float scale);

}
+17 −0
Original line number Diff line number Diff line
@@ -144,6 +144,13 @@ public class WindowMagnification extends SystemUI implements WindowMagnifierCall
        }
    }

    @Override
    public void onPerformScaleAction(int displayId, float scale) {
        if (mWindowMagnificationConnectionImpl != null) {
            mWindowMagnificationConnectionImpl.onPerformScaleAction(displayId, scale);
        }
    }

    @Override
    public void requestWindowMagnificationConnection(boolean connect) {
        if (connect) {
@@ -246,5 +253,15 @@ public class WindowMagnification extends SystemUI implements WindowMagnifierCall
                }
            }
        }

        void onPerformScaleAction(int displayId, float scale) {
            if (mConnectionCallback != null) {
                try {
                    mConnectionCallback.onPerformScaleAction(displayId, scale);
                } catch (RemoteException e) {
                    Log.e(TAG, "Failed to inform performing scale action", e);
                }
            }
        }
    }
}
+4 −2
Original line number Diff line number Diff line
@@ -705,12 +705,14 @@ class WindowMagnificationController implements View.OnTouchListener, SurfaceHold
        private boolean performA11yAction(int action) {
            if (action == R.id.accessibility_action_zoom_in) {
                final float scale = mScale + A11Y_CHANGE_SCALE_DIFFERENCE;
                setScale(A11Y_ACTION_SCALE_RANGE.clamp(scale));
                mWindowMagnifierCallback.onPerformScaleAction(mDisplayId,
                        A11Y_ACTION_SCALE_RANGE.clamp(scale));
                return true;
            }
            if (action == R.id.accessibility_action_zoom_out) {
                final float scale = mScale - A11Y_CHANGE_SCALE_DIFFERENCE;
                setScale(A11Y_ACTION_SCALE_RANGE.clamp(scale));
                mWindowMagnifierCallback.onPerformScaleAction(mDisplayId,
                        A11Y_ACTION_SCALE_RANGE.clamp(scale));
                return true;
            }
            if (action == R.id.accessibility_action_move_up) {
+9 −0
Original line number Diff line number Diff line
@@ -37,4 +37,13 @@ interface WindowMagnifierCallback {
     * @param sourceBounds The magnified bounds in screen coordinates.
     */
    void onSourceBoundsChanged(int displayId, Rect sourceBounds);

    /**
     * Called when the accessibility action of scale requests to be performed.
     * It is invoked from System UI. And the action is provided by the mirror window.
     *
     * @param displayId The logical display id.
     * @param scale the target scale, or {@link Float#NaN} to leave unchanged
     */
    void onPerformScaleAction(int displayId, float scale);
}
+3 −2
Original line number Diff line number Diff line
@@ -276,6 +276,7 @@ public class WindowMagnificationControllerTest extends SysuiTestCase {

    @Test
    public void performA11yActions_visible_expectedResults() {
        final int displayId = mContext.getDisplayId();
        mInstrumentation.runOnMainSync(() -> {
            mWindowMagnificationController.enableWindowMagnification(2.5f, Float.NaN,
                    Float.NaN);
@@ -285,10 +286,10 @@ public class WindowMagnificationControllerTest extends SysuiTestCase {
        assertTrue(
                mMirrorView.performAccessibilityAction(R.id.accessibility_action_zoom_out, null));
        // Minimum scale is 2.0.
        assertEquals(2.0f, mWindowMagnificationController.getScale(), 0f);
        verify(mWindowMagnifierCallback).onPerformScaleAction(eq(displayId), eq(2.0f));

        assertTrue(mMirrorView.performAccessibilityAction(R.id.accessibility_action_zoom_in, null));
        assertEquals(3.0f, mWindowMagnificationController.getScale(), 0f);
        verify(mWindowMagnifierCallback).onPerformScaleAction(eq(displayId), eq(3.5f));

        // TODO: Verify the final state when the mirror surface is visible.
        assertTrue(mMirrorView.performAccessibilityAction(R.id.accessibility_action_move_up, null));
Loading