Loading services/accessibility/java/com/android/server/accessibility/AccessibilityInputFilter.java +1 −1 Original line number Diff line number Diff line Loading @@ -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); } } Loading services/accessibility/java/com/android/server/accessibility/AccessibilityManagerService.java +4 −0 Original line number Diff line number Diff line Loading @@ -2028,6 +2028,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--) { Loading services/accessibility/java/com/android/server/accessibility/AccessibilityWindowManager.java +4 −0 Original line number Diff line number Diff line Loading @@ -1258,6 +1258,10 @@ public class AccessibilityWindowManager { return mLastNonProxyTopFocusedDisplayId; } int getTopFocusedDisplayId() { return mTopFocusedDisplayId; } /** * Checks if we are tracking windows on specified display. * Loading services/accessibility/java/com/android/server/accessibility/magnification/MagnificationKeyHandler.java +8 −1 Original line number Diff line number Diff line Loading @@ -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; /* Loading Loading @@ -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 Loading Loading @@ -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; } } services/tests/servicestests/src/com/android/server/accessibility/magnification/MagnificationKeyHandlerTest.java +57 −13 Original line number Diff line number Diff line Loading @@ -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; Loading @@ -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(); Loading @@ -60,6 +62,9 @@ public class MagnificationKeyHandlerTest { @Mock MagnificationKeyHandler.Callback mCallback; @Mock AccessibilityManagerService mAms; @Mock EventStreamTransformation mNextHandler; Loading @@ -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); } Loading Loading @@ -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 Loading Loading @@ -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); Loading @@ -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. Loading @@ -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()); Loading @@ -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); Loading Loading
services/accessibility/java/com/android/server/accessibility/AccessibilityInputFilter.java +1 −1 Original line number Diff line number Diff line Loading @@ -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); } } Loading
services/accessibility/java/com/android/server/accessibility/AccessibilityManagerService.java +4 −0 Original line number Diff line number Diff line Loading @@ -2028,6 +2028,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--) { Loading
services/accessibility/java/com/android/server/accessibility/AccessibilityWindowManager.java +4 −0 Original line number Diff line number Diff line Loading @@ -1258,6 +1258,10 @@ public class AccessibilityWindowManager { return mLastNonProxyTopFocusedDisplayId; } int getTopFocusedDisplayId() { return mTopFocusedDisplayId; } /** * Checks if we are tracking windows on specified display. * Loading
services/accessibility/java/com/android/server/accessibility/magnification/MagnificationKeyHandler.java +8 −1 Original line number Diff line number Diff line Loading @@ -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; /* Loading Loading @@ -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 Loading Loading @@ -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; } }
services/tests/servicestests/src/com/android/server/accessibility/magnification/MagnificationKeyHandlerTest.java +57 −13 Original line number Diff line number Diff line Loading @@ -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; Loading @@ -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(); Loading @@ -60,6 +62,9 @@ public class MagnificationKeyHandlerTest { @Mock MagnificationKeyHandler.Callback mCallback; @Mock AccessibilityManagerService mAms; @Mock EventStreamTransformation mNextHandler; Loading @@ -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); } Loading Loading @@ -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 Loading Loading @@ -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); Loading @@ -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. Loading @@ -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()); Loading @@ -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); Loading