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

Commit 0c584b10 authored by Ebru Kurnaz's avatar Ebru Kurnaz
Browse files

Allow magnification shortcuts to work on top focused display.

Test: atest MagnificationKeyHandlerTest
Bug: 407788786
Flag: EXEMPT bug fix
Change-Id: I84be30be967eb25b4225735b9ba71f0a3381ac9f
parent 616fd282
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -822,7 +822,7 @@ public class AccessibilityInputFilter extends InputFilter implements EventStream

        if (isAnyMagnificationEnabled(mEnabledFeatures)) {
            mMagnificationKeyHandler = new MagnificationKeyHandler(
                    mAms.getMagnificationController());
                    mAms.getMagnificationController(), mAms);
            addFirstEventHandler(Display.DEFAULT_DISPLAY, mMagnificationKeyHandler);
        }
    }
+4 −0
Original line number Diff line number Diff line
@@ -2029,6 +2029,10 @@ public class AccessibilityManagerService extends IAccessibilityManager.Stub
        return mA11yWindowManager.getLastNonProxyTopFocusedDisplayId();
    }

    public int getTopFocusedDisplayId() {
        return mA11yWindowManager.getTopFocusedDisplayId();
    }

    @VisibleForTesting
    void notifySystemActionsChangedLocked(AccessibilityUserState userState) {
        for (int i = userState.mBoundServices.size() - 1; i >= 0; i--) {
+4 −0
Original line number Diff line number Diff line
@@ -1258,6 +1258,10 @@ public class AccessibilityWindowManager {
        return mLastNonProxyTopFocusedDisplayId;
    }

    int getTopFocusedDisplayId() {
        return mTopFocusedDisplayId;
    }

    /**
     * Checks if we are tracking windows on specified display.
     *
+8 −1
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@ package com.android.server.accessibility.magnification;
import android.view.Display;
import android.view.KeyEvent;

import com.android.server.accessibility.AccessibilityManagerService;
import com.android.server.accessibility.BaseEventStreamTransformation;

/*
@@ -85,10 +86,12 @@ public class MagnificationKeyHandler extends BaseEventStreamTransformation {
    }

    protected final MagnificationKeyHandler.Callback mCallback;
    private final AccessibilityManagerService mAms;
    private boolean mIsKeyboardInteracting = false;

    public MagnificationKeyHandler(Callback callback) {
    public MagnificationKeyHandler(Callback callback, AccessibilityManagerService ams) {
        mCallback = callback;
        mAms = ams;
    }

    @Override
@@ -161,6 +164,10 @@ public class MagnificationKeyHandler extends BaseEventStreamTransformation {
        if (event.getDisplayId() != Display.INVALID_DISPLAY) {
            return event.getDisplayId();
        }
        int topFocusedDisplayId = mAms.getTopFocusedDisplayId();
        if (topFocusedDisplayId != Display.INVALID_DISPLAY) {
            return topFocusedDisplayId;
        }
        return Display.DEFAULT_DISPLAY;
    }
}
+57 −13
Original line number Diff line number Diff line
@@ -36,6 +36,7 @@ import android.view.KeyEvent;

import androidx.test.runner.AndroidJUnit4;

import com.android.server.accessibility.AccessibilityManagerService;
import com.android.server.accessibility.EventStreamTransformation;

import org.junit.Before;
@@ -51,6 +52,7 @@ import org.mockito.MockitoAnnotations;
 */
@RunWith(AndroidJUnit4.class)
public class MagnificationKeyHandlerTest {
    private static final int EXTERNAL_DISPLAY_ID = 2;

    @Rule
    public final CheckFlagsRule mCheckFlagsRule = DeviceFlagsValueProvider.createCheckFlagsRule();
@@ -60,6 +62,9 @@ public class MagnificationKeyHandlerTest {
    @Mock
    MagnificationKeyHandler.Callback mCallback;

    @Mock
    AccessibilityManagerService mAms;

    @Mock
    EventStreamTransformation mNextHandler;

@@ -67,7 +72,8 @@ public class MagnificationKeyHandlerTest {
    public void setUp() {
        MockitoAnnotations.initMocks(this);
        when(mCallback.isMagnificationActivated(any(Integer.class))).thenReturn(true);
        mMkh = new MagnificationKeyHandler(mCallback);
        when(mAms.getTopFocusedDisplayId()).thenReturn(Display.DEFAULT_DISPLAY);
        mMkh = new MagnificationKeyHandler(mCallback, mAms);
        mMkh.setNext(mNextHandler);
    }

@@ -135,32 +141,70 @@ public class MagnificationKeyHandlerTest {

    @Test
    public void onKeyEvent_panStartAndEnd_left() {
        testPanMagnification(KeyEvent.KEYCODE_DPAD_LEFT, PAN_DIRECTION_LEFT);
        testPanMagnification(KeyEvent.KEYCODE_DPAD_LEFT, PAN_DIRECTION_LEFT, Display.DEFAULT_DISPLAY);
    }


    @Test
    public void onKeyEvent_panStartAndEnd_left_onExternalDisplay() {
        when(mAms.getTopFocusedDisplayId()).thenReturn(EXTERNAL_DISPLAY_ID);
        testPanMagnification(KeyEvent.KEYCODE_DPAD_LEFT, PAN_DIRECTION_LEFT, EXTERNAL_DISPLAY_ID);
    }


    @Test
    public void onKeyEvent_panStartAndEnd_right() {
        testPanMagnification(KeyEvent.KEYCODE_DPAD_RIGHT, PAN_DIRECTION_RIGHT);
        testPanMagnification(KeyEvent.KEYCODE_DPAD_RIGHT, PAN_DIRECTION_RIGHT, Display.DEFAULT_DISPLAY);
    }

    @Test
    public void onKeyEvent_panStartAndEnd_right_onExternalDisplay() {
        when(mAms.getTopFocusedDisplayId()).thenReturn(EXTERNAL_DISPLAY_ID);
        testPanMagnification(KeyEvent.KEYCODE_DPAD_RIGHT, PAN_DIRECTION_RIGHT, EXTERNAL_DISPLAY_ID);
    }

    @Test
    public void onKeyEvent_panStartAndEnd_up() {
        testPanMagnification(KeyEvent.KEYCODE_DPAD_UP, PAN_DIRECTION_UP);
        testPanMagnification(KeyEvent.KEYCODE_DPAD_UP, PAN_DIRECTION_UP, Display.DEFAULT_DISPLAY);
    }

    @Test
    public void onKeyEvent_panStartAndEnd_up_onExternalDisplay() {
        when(mAms.getTopFocusedDisplayId()).thenReturn(EXTERNAL_DISPLAY_ID);
        testPanMagnification(KeyEvent.KEYCODE_DPAD_UP, PAN_DIRECTION_UP, EXTERNAL_DISPLAY_ID);
    }

    @Test
    public void onKeyEvent_panStartAndEnd_down() {
        testPanMagnification(KeyEvent.KEYCODE_DPAD_DOWN, PAN_DIRECTION_DOWN);
        testPanMagnification(KeyEvent.KEYCODE_DPAD_DOWN, PAN_DIRECTION_DOWN, Display.DEFAULT_DISPLAY);
    }

    @Test
    public void onKeyEvent_panStartAndEnd_down_onExternalDisplay() {
        when(mAms.getTopFocusedDisplayId()).thenReturn(EXTERNAL_DISPLAY_ID);
        testPanMagnification(KeyEvent.KEYCODE_DPAD_DOWN, PAN_DIRECTION_DOWN, EXTERNAL_DISPLAY_ID);
    }

    @Test
    public void onKeyEvent_scaleStartAndEnd_zoomIn() {
        testScaleMagnification(KeyEvent.KEYCODE_EQUALS, ZOOM_DIRECTION_IN);
        testScaleMagnification(KeyEvent.KEYCODE_EQUALS, ZOOM_DIRECTION_IN, Display.DEFAULT_DISPLAY);
    }

    @Test
    public void onKeyEvent_scaleStartAndEnd_zoomIn_onExternalDisplay() {
        when(mAms.getTopFocusedDisplayId()).thenReturn(EXTERNAL_DISPLAY_ID);
        testScaleMagnification(KeyEvent.KEYCODE_EQUALS, ZOOM_DIRECTION_IN, EXTERNAL_DISPLAY_ID);
    }

    @Test
    public void onKeyEvent_scaleStartAndEnd_zoomOut() {
        testScaleMagnification(KeyEvent.KEYCODE_MINUS, ZOOM_DIRECTION_OUT);
        testScaleMagnification(KeyEvent.KEYCODE_MINUS, ZOOM_DIRECTION_OUT, Display.DEFAULT_DISPLAY);
    }

    @Test
    public void onKeyEvent_scaleStartAndEnd_zoomOut_onExternalDisplay() {
        when(mAms.getTopFocusedDisplayId()).thenReturn(EXTERNAL_DISPLAY_ID);
        testScaleMagnification(KeyEvent.KEYCODE_MINUS, ZOOM_DIRECTION_OUT, EXTERNAL_DISPLAY_ID);
    }

    @Test
@@ -243,13 +287,13 @@ public class MagnificationKeyHandlerTest {

    }

    private void testPanMagnification(int keyCode, int panDirection) {
    private void testPanMagnification(int keyCode, int panDirection, int displayId) {
        final KeyEvent downEvent = new KeyEvent(0, 0, KeyEvent.ACTION_DOWN, keyCode, 0,
                KeyEvent.META_META_ON | KeyEvent.META_ALT_ON);
        mMkh.onKeyEvent(downEvent, 0);

        // Pan started.
        verify(mCallback, times(1)).onPanMagnificationStart(Display.DEFAULT_DISPLAY, panDirection);
        verify(mCallback, times(1)).onPanMagnificationStart(displayId, panDirection);
        verify(mCallback, times(0)).onPanMagnificationStop(anyInt());

        Mockito.clearInvocations(mCallback);
@@ -259,7 +303,7 @@ public class MagnificationKeyHandlerTest {
        mMkh.onKeyEvent(upEvent, 0);

        // Pan ended.
        verify(mCallback, times(0)).onPanMagnificationStart(Display.DEFAULT_DISPLAY, panDirection);
        verify(mCallback, times(0)).onPanMagnificationStart(displayId, panDirection);
        verify(mCallback, times(1)).onPanMagnificationStop(panDirection);

        // Scale callbacks were not called.
@@ -270,13 +314,13 @@ public class MagnificationKeyHandlerTest {
        verify(mNextHandler, times(0)).onKeyEvent(any(), anyInt());
    }

    private void testScaleMagnification(int keyCode, int zoomDirection) {
    private void testScaleMagnification(int keyCode, int zoomDirection, int displayId) {
        final KeyEvent downEvent = new KeyEvent(0, 0, KeyEvent.ACTION_DOWN, keyCode, 0,
                KeyEvent.META_META_ON | KeyEvent.META_ALT_ON);
        mMkh.onKeyEvent(downEvent, 0);

        // Scale started.
        verify(mCallback, times(1)).onScaleMagnificationStart(Display.DEFAULT_DISPLAY,
        verify(mCallback, times(1)).onScaleMagnificationStart(displayId,
                zoomDirection);
        verify(mCallback, times(0)).onScaleMagnificationStop(anyInt());

@@ -287,7 +331,7 @@ public class MagnificationKeyHandlerTest {
        mMkh.onKeyEvent(upEvent, 0);

        // Scale ended.
        verify(mCallback, times(0)).onScaleMagnificationStart(Display.DEFAULT_DISPLAY,
        verify(mCallback, times(0)).onScaleMagnificationStart(displayId,
                zoomDirection);
        verify(mCallback, times(1)).onScaleMagnificationStop(zoomDirection);