Loading core/java/android/view/accessibility/AccessibilityManager.java +22 −0 Original line number Diff line number Diff line Loading @@ -2721,4 +2721,26 @@ public final class AccessibilityManager { throw re.rethrowFromSystemServer(); } } /** * Turns on Magnification and zooms in. * * @param displayId which display enabling Magnification * @hide */ @RequiresPermission(Manifest.permission.MANAGE_ACCESSIBILITY) public void enableMagnificationAndZoomIn(int displayId) { final IAccessibilityManager service; synchronized (mLock) { service = getServiceLocked(); if (service == null) { return; } } try { service.enableMagnificationAndZoomIn(displayId); } catch (RemoteException re) { throw re.rethrowFromSystemServer(); } } } core/java/android/view/accessibility/IAccessibilityManager.aidl +3 −0 Original line number Diff line number Diff line Loading @@ -207,4 +207,7 @@ interface IAccessibilityManager { @EnforcePermission("MANAGE_ACCESSIBILITY") void setTrustedAccessibilityServiceForTesting(in ComponentName trustedAccessibilityService); @EnforcePermission("MANAGE_ACCESSIBILITY") oneway void enableMagnificationAndZoomIn(int displayId); } core/java/com/android/internal/accessibility/common/KeyGestureEventConstants.java +6 −0 Original line number Diff line number Diff line Loading @@ -47,4 +47,10 @@ public final class KeyGestureEventConstants { * @see Settings.Secure#ACCESSIBILITY_GESTURE_TARGETS */ public static final String TARGET_NAME = "TARGET_NAME"; /** * Used as the name of the extra data when we put the value of the display id on the key gesture * event into an intent. */ public static final String DISPLAY_ID = "DISPLAY_ID"; } packages/SystemUI/multivalentTests/src/com/android/systemui/accessibility/data/repository/AccessibilityShortcutsRepositoryImplTest.kt +4 −4 Original line number Diff line number Diff line Loading @@ -221,7 +221,7 @@ class AccessibilityShortcutsRepositoryImplTest : SysuiTestCase() { fun enableShortcutsForTargets_targetNameForMagnification_enabled() { val targetName = getTargetNameByType(KeyGestureEvent.KEY_GESTURE_TYPE_TOGGLE_MAGNIFICATION) underTest.enableShortcutsForTargets(targetName) underTest.enableShortcutsForTargets(enable = true, targetName) verify(accessibilityManager) .enableShortcutsForTargets( Loading @@ -237,7 +237,7 @@ class AccessibilityShortcutsRepositoryImplTest : SysuiTestCase() { val targetName = getTargetNameByType(KeyGestureEvent.KEY_GESTURE_TYPE_ACTIVATE_SELECT_TO_SPEAK) underTest.enableShortcutsForTargets(targetName) underTest.enableShortcutsForTargets(enable = true, targetName) verify(accessibilityManager) .enableShortcutsForTargets( Loading @@ -252,7 +252,7 @@ class AccessibilityShortcutsRepositoryImplTest : SysuiTestCase() { fun enableShortcutsForTargets_targetNameForVoiceAccess_enabled() { val targetName = getTargetNameByType(KeyGestureEvent.KEY_GESTURE_TYPE_TOGGLE_VOICE_ACCESS) underTest.enableShortcutsForTargets(targetName) underTest.enableShortcutsForTargets(enable = true, targetName) verify(accessibilityManager) .enableShortcutsForTargets( Loading @@ -267,7 +267,7 @@ class AccessibilityShortcutsRepositoryImplTest : SysuiTestCase() { fun enableShortcutsForTargets_targetNameForTalkBack_enabled() { val targetName = getTargetNameByType(KeyGestureEvent.KEY_GESTURE_TYPE_TOGGLE_SCREEN_READER) underTest.enableShortcutsForTargets(targetName) underTest.enableShortcutsForTargets(enable = true, targetName) verify(accessibilityManager) .enableShortcutsForTargets( Loading packages/SystemUI/multivalentTests/src/com/android/systemui/accessibility/keygesture/domain/KeyGestureDialogInteractorTest.kt +102 −13 Original line number Diff line number Diff line Loading @@ -20,6 +20,8 @@ import android.content.Intent import android.content.applicationContext import android.hardware.input.KeyGestureEvent import android.os.fakeExecutorHandler import android.view.Display.DEFAULT_DISPLAY import android.view.Display.INVALID_DISPLAY import android.view.KeyEvent import androidx.test.ext.junit.runners.AndroidJUnit4 import androidx.test.filters.SmallTest Loading Loading @@ -52,7 +54,7 @@ class KeyGestureDialogInteractorTest : SysuiTestCase() { private val testScope = kosmos.testScope // mocks private val repository = mock(AccessibilityShortcutsRepository::class.java) private val mockRepository = mock(AccessibilityShortcutsRepository::class.java) private lateinit var underTest: KeyGestureDialogInteractor Loading @@ -61,7 +63,7 @@ class KeyGestureDialogInteractorTest : SysuiTestCase() { underTest = KeyGestureDialogInteractor( kosmos.applicationContext, repository, mockRepository, broadcastDispatcher, testDispatcher, kosmos.fakeExecutorHandler, Loading @@ -69,25 +71,110 @@ class KeyGestureDialogInteractorTest : SysuiTestCase() { } @Test fun onPositiveButtonClick_enabledShortcutsForFakeTarget() { fun enableShortcutsForTargets_enabledShortcutsForFakeTarget() { val enabledTargetName = "fakeTargetName" underTest.onPositiveButtonClick(enabledTargetName) underTest.enableShortcutsForTargets(/* enable= */ true, enabledTargetName) verify(repository).enableShortcutsForTargets(eq(enabledTargetName)) verify(mockRepository).enableShortcutsForTargets(eq(true), eq(enabledTargetName)) } @Test fun keyGestureConfirmDialogRequest_invalidRequestReceived() { fun enableMagnificationAndZoomIn_validDisplayId_delegatesToRepository() { underTest.enableMagnificationAndZoomIn(DEFAULT_DISPLAY) verify(mockRepository).enableMagnificationAndZoomIn(eq(DEFAULT_DISPLAY)) } @Test fun keyGestureConfirmDialogRequest_invalidKeyGestureTypeReceived_flowIsNull() { testScope.runTest { val keyGestureConfirmInfo by collectLastValue(underTest.keyGestureConfirmDialogRequest) runCurrent() sendIntentBroadcast( keyGestureType = 0, metaState = KeyEvent.META_META_ON or KeyEvent.META_ALT_ON, keyCode = KeyEvent.KEYCODE_M, targetName = "targetNameForMagnification", displayId = DEFAULT_DISPLAY, ) runCurrent() assertThat(keyGestureConfirmInfo).isNull() } } @Test fun keyGestureConfirmDialogRequest_invalidMetaStateReceived_flowIsNull() { testScope.runTest { val keyGestureConfirmInfo by collectLastValue(underTest.keyGestureConfirmDialogRequest) runCurrent() sendIntentBroadcast( keyGestureType = KeyGestureEvent.KEY_GESTURE_TYPE_TOGGLE_MAGNIFICATION, metaState = 0, keyCode = KeyEvent.KEYCODE_M, targetName = "targetNameForMagnification", displayId = DEFAULT_DISPLAY, ) runCurrent() assertThat(keyGestureConfirmInfo).isNull() } } @Test fun keyGestureConfirmDialogRequest_invalidKeyCodeReceived_flowIsNull() { testScope.runTest { val keyGestureConfirmInfo by collectLastValue(underTest.keyGestureConfirmDialogRequest) runCurrent() sendIntentBroadcast( keyGestureType = KeyGestureEvent.KEY_GESTURE_TYPE_TOGGLE_MAGNIFICATION, metaState = KeyEvent.META_META_ON or KeyEvent.META_ALT_ON, keyCode = 0, targetName = "targetNameForMagnification", displayId = DEFAULT_DISPLAY, ) runCurrent() assertThat(keyGestureConfirmInfo).isNull() } } @Test fun keyGestureConfirmDialogRequest_invalidTargetNameReceived_flowIsNull() { testScope.runTest { val keyGestureType = KeyGestureEvent.KEY_GESTURE_TYPE_TOGGLE_MAGNIFICATION val metaState = 0 val keyCode = 0 val testTargetName = "fakeTargetName" val keyGestureConfirmInfo by collectLastValue(underTest.keyGestureConfirmDialogRequest) runCurrent() sendIntentBroadcast(keyGestureType, metaState, keyCode, testTargetName) sendIntentBroadcast( keyGestureType = KeyGestureEvent.KEY_GESTURE_TYPE_TOGGLE_MAGNIFICATION, metaState = KeyEvent.META_META_ON or KeyEvent.META_ALT_ON, keyCode = KeyEvent.KEYCODE_M, targetName = "", displayId = DEFAULT_DISPLAY, ) runCurrent() assertThat(keyGestureConfirmInfo).isNull() } } @Test fun keyGestureConfirmDialogRequest_invalidDisplayIdReceived_flowIsNull() { testScope.runTest { val keyGestureConfirmInfo by collectLastValue(underTest.keyGestureConfirmDialogRequest) runCurrent() sendIntentBroadcast( keyGestureType = KeyGestureEvent.KEY_GESTURE_TYPE_TOGGLE_MAGNIFICATION, metaState = KeyEvent.META_META_ON or KeyEvent.META_ALT_ON, keyCode = KeyEvent.KEYCODE_M, targetName = "targetNameForMagnification", displayId = INVALID_DISPLAY, ) runCurrent() assertThat(keyGestureConfirmInfo).isNull() Loading @@ -104,10 +191,10 @@ class KeyGestureDialogInteractorTest : SysuiTestCase() { collectLastValue(underTest.keyGestureConfirmDialogRequest) runCurrent() sendIntentBroadcast(keyGestureType, metaState, keyCode, testTargetName) sendIntentBroadcast(keyGestureType, metaState, keyCode, testTargetName, DEFAULT_DISPLAY) runCurrent() verify(repository) verify(mockRepository) .getTitleToContentForKeyGestureDialog( eq(keyGestureType), eq(metaState), Loading @@ -122,6 +209,7 @@ class KeyGestureDialogInteractorTest : SysuiTestCase() { metaState: Int, keyCode: Int, targetName: String, displayId: Int, ) { val intent = Intent().apply { Loading @@ -130,6 +218,7 @@ class KeyGestureDialogInteractorTest : SysuiTestCase() { putExtra(KeyGestureEventConstants.META_STATE, metaState) putExtra(KeyGestureEventConstants.KEY_CODE, keyCode) putExtra(KeyGestureEventConstants.TARGET_NAME, targetName) putExtra(KeyGestureEventConstants.DISPLAY_ID, displayId) } broadcastDispatcher.sendIntentToMatchingReceiversOnly(context, intent) Loading Loading
core/java/android/view/accessibility/AccessibilityManager.java +22 −0 Original line number Diff line number Diff line Loading @@ -2721,4 +2721,26 @@ public final class AccessibilityManager { throw re.rethrowFromSystemServer(); } } /** * Turns on Magnification and zooms in. * * @param displayId which display enabling Magnification * @hide */ @RequiresPermission(Manifest.permission.MANAGE_ACCESSIBILITY) public void enableMagnificationAndZoomIn(int displayId) { final IAccessibilityManager service; synchronized (mLock) { service = getServiceLocked(); if (service == null) { return; } } try { service.enableMagnificationAndZoomIn(displayId); } catch (RemoteException re) { throw re.rethrowFromSystemServer(); } } }
core/java/android/view/accessibility/IAccessibilityManager.aidl +3 −0 Original line number Diff line number Diff line Loading @@ -207,4 +207,7 @@ interface IAccessibilityManager { @EnforcePermission("MANAGE_ACCESSIBILITY") void setTrustedAccessibilityServiceForTesting(in ComponentName trustedAccessibilityService); @EnforcePermission("MANAGE_ACCESSIBILITY") oneway void enableMagnificationAndZoomIn(int displayId); }
core/java/com/android/internal/accessibility/common/KeyGestureEventConstants.java +6 −0 Original line number Diff line number Diff line Loading @@ -47,4 +47,10 @@ public final class KeyGestureEventConstants { * @see Settings.Secure#ACCESSIBILITY_GESTURE_TARGETS */ public static final String TARGET_NAME = "TARGET_NAME"; /** * Used as the name of the extra data when we put the value of the display id on the key gesture * event into an intent. */ public static final String DISPLAY_ID = "DISPLAY_ID"; }
packages/SystemUI/multivalentTests/src/com/android/systemui/accessibility/data/repository/AccessibilityShortcutsRepositoryImplTest.kt +4 −4 Original line number Diff line number Diff line Loading @@ -221,7 +221,7 @@ class AccessibilityShortcutsRepositoryImplTest : SysuiTestCase() { fun enableShortcutsForTargets_targetNameForMagnification_enabled() { val targetName = getTargetNameByType(KeyGestureEvent.KEY_GESTURE_TYPE_TOGGLE_MAGNIFICATION) underTest.enableShortcutsForTargets(targetName) underTest.enableShortcutsForTargets(enable = true, targetName) verify(accessibilityManager) .enableShortcutsForTargets( Loading @@ -237,7 +237,7 @@ class AccessibilityShortcutsRepositoryImplTest : SysuiTestCase() { val targetName = getTargetNameByType(KeyGestureEvent.KEY_GESTURE_TYPE_ACTIVATE_SELECT_TO_SPEAK) underTest.enableShortcutsForTargets(targetName) underTest.enableShortcutsForTargets(enable = true, targetName) verify(accessibilityManager) .enableShortcutsForTargets( Loading @@ -252,7 +252,7 @@ class AccessibilityShortcutsRepositoryImplTest : SysuiTestCase() { fun enableShortcutsForTargets_targetNameForVoiceAccess_enabled() { val targetName = getTargetNameByType(KeyGestureEvent.KEY_GESTURE_TYPE_TOGGLE_VOICE_ACCESS) underTest.enableShortcutsForTargets(targetName) underTest.enableShortcutsForTargets(enable = true, targetName) verify(accessibilityManager) .enableShortcutsForTargets( Loading @@ -267,7 +267,7 @@ class AccessibilityShortcutsRepositoryImplTest : SysuiTestCase() { fun enableShortcutsForTargets_targetNameForTalkBack_enabled() { val targetName = getTargetNameByType(KeyGestureEvent.KEY_GESTURE_TYPE_TOGGLE_SCREEN_READER) underTest.enableShortcutsForTargets(targetName) underTest.enableShortcutsForTargets(enable = true, targetName) verify(accessibilityManager) .enableShortcutsForTargets( Loading
packages/SystemUI/multivalentTests/src/com/android/systemui/accessibility/keygesture/domain/KeyGestureDialogInteractorTest.kt +102 −13 Original line number Diff line number Diff line Loading @@ -20,6 +20,8 @@ import android.content.Intent import android.content.applicationContext import android.hardware.input.KeyGestureEvent import android.os.fakeExecutorHandler import android.view.Display.DEFAULT_DISPLAY import android.view.Display.INVALID_DISPLAY import android.view.KeyEvent import androidx.test.ext.junit.runners.AndroidJUnit4 import androidx.test.filters.SmallTest Loading Loading @@ -52,7 +54,7 @@ class KeyGestureDialogInteractorTest : SysuiTestCase() { private val testScope = kosmos.testScope // mocks private val repository = mock(AccessibilityShortcutsRepository::class.java) private val mockRepository = mock(AccessibilityShortcutsRepository::class.java) private lateinit var underTest: KeyGestureDialogInteractor Loading @@ -61,7 +63,7 @@ class KeyGestureDialogInteractorTest : SysuiTestCase() { underTest = KeyGestureDialogInteractor( kosmos.applicationContext, repository, mockRepository, broadcastDispatcher, testDispatcher, kosmos.fakeExecutorHandler, Loading @@ -69,25 +71,110 @@ class KeyGestureDialogInteractorTest : SysuiTestCase() { } @Test fun onPositiveButtonClick_enabledShortcutsForFakeTarget() { fun enableShortcutsForTargets_enabledShortcutsForFakeTarget() { val enabledTargetName = "fakeTargetName" underTest.onPositiveButtonClick(enabledTargetName) underTest.enableShortcutsForTargets(/* enable= */ true, enabledTargetName) verify(repository).enableShortcutsForTargets(eq(enabledTargetName)) verify(mockRepository).enableShortcutsForTargets(eq(true), eq(enabledTargetName)) } @Test fun keyGestureConfirmDialogRequest_invalidRequestReceived() { fun enableMagnificationAndZoomIn_validDisplayId_delegatesToRepository() { underTest.enableMagnificationAndZoomIn(DEFAULT_DISPLAY) verify(mockRepository).enableMagnificationAndZoomIn(eq(DEFAULT_DISPLAY)) } @Test fun keyGestureConfirmDialogRequest_invalidKeyGestureTypeReceived_flowIsNull() { testScope.runTest { val keyGestureConfirmInfo by collectLastValue(underTest.keyGestureConfirmDialogRequest) runCurrent() sendIntentBroadcast( keyGestureType = 0, metaState = KeyEvent.META_META_ON or KeyEvent.META_ALT_ON, keyCode = KeyEvent.KEYCODE_M, targetName = "targetNameForMagnification", displayId = DEFAULT_DISPLAY, ) runCurrent() assertThat(keyGestureConfirmInfo).isNull() } } @Test fun keyGestureConfirmDialogRequest_invalidMetaStateReceived_flowIsNull() { testScope.runTest { val keyGestureConfirmInfo by collectLastValue(underTest.keyGestureConfirmDialogRequest) runCurrent() sendIntentBroadcast( keyGestureType = KeyGestureEvent.KEY_GESTURE_TYPE_TOGGLE_MAGNIFICATION, metaState = 0, keyCode = KeyEvent.KEYCODE_M, targetName = "targetNameForMagnification", displayId = DEFAULT_DISPLAY, ) runCurrent() assertThat(keyGestureConfirmInfo).isNull() } } @Test fun keyGestureConfirmDialogRequest_invalidKeyCodeReceived_flowIsNull() { testScope.runTest { val keyGestureConfirmInfo by collectLastValue(underTest.keyGestureConfirmDialogRequest) runCurrent() sendIntentBroadcast( keyGestureType = KeyGestureEvent.KEY_GESTURE_TYPE_TOGGLE_MAGNIFICATION, metaState = KeyEvent.META_META_ON or KeyEvent.META_ALT_ON, keyCode = 0, targetName = "targetNameForMagnification", displayId = DEFAULT_DISPLAY, ) runCurrent() assertThat(keyGestureConfirmInfo).isNull() } } @Test fun keyGestureConfirmDialogRequest_invalidTargetNameReceived_flowIsNull() { testScope.runTest { val keyGestureType = KeyGestureEvent.KEY_GESTURE_TYPE_TOGGLE_MAGNIFICATION val metaState = 0 val keyCode = 0 val testTargetName = "fakeTargetName" val keyGestureConfirmInfo by collectLastValue(underTest.keyGestureConfirmDialogRequest) runCurrent() sendIntentBroadcast(keyGestureType, metaState, keyCode, testTargetName) sendIntentBroadcast( keyGestureType = KeyGestureEvent.KEY_GESTURE_TYPE_TOGGLE_MAGNIFICATION, metaState = KeyEvent.META_META_ON or KeyEvent.META_ALT_ON, keyCode = KeyEvent.KEYCODE_M, targetName = "", displayId = DEFAULT_DISPLAY, ) runCurrent() assertThat(keyGestureConfirmInfo).isNull() } } @Test fun keyGestureConfirmDialogRequest_invalidDisplayIdReceived_flowIsNull() { testScope.runTest { val keyGestureConfirmInfo by collectLastValue(underTest.keyGestureConfirmDialogRequest) runCurrent() sendIntentBroadcast( keyGestureType = KeyGestureEvent.KEY_GESTURE_TYPE_TOGGLE_MAGNIFICATION, metaState = KeyEvent.META_META_ON or KeyEvent.META_ALT_ON, keyCode = KeyEvent.KEYCODE_M, targetName = "targetNameForMagnification", displayId = INVALID_DISPLAY, ) runCurrent() assertThat(keyGestureConfirmInfo).isNull() Loading @@ -104,10 +191,10 @@ class KeyGestureDialogInteractorTest : SysuiTestCase() { collectLastValue(underTest.keyGestureConfirmDialogRequest) runCurrent() sendIntentBroadcast(keyGestureType, metaState, keyCode, testTargetName) sendIntentBroadcast(keyGestureType, metaState, keyCode, testTargetName, DEFAULT_DISPLAY) runCurrent() verify(repository) verify(mockRepository) .getTitleToContentForKeyGestureDialog( eq(keyGestureType), eq(metaState), Loading @@ -122,6 +209,7 @@ class KeyGestureDialogInteractorTest : SysuiTestCase() { metaState: Int, keyCode: Int, targetName: String, displayId: Int, ) { val intent = Intent().apply { Loading @@ -130,6 +218,7 @@ class KeyGestureDialogInteractorTest : SysuiTestCase() { putExtra(KeyGestureEventConstants.META_STATE, metaState) putExtra(KeyGestureEventConstants.KEY_CODE, keyCode) putExtra(KeyGestureEventConstants.TARGET_NAME, targetName) putExtra(KeyGestureEventConstants.DISPLAY_ID, displayId) } broadcastDispatcher.sendIntentToMatchingReceiversOnly(context, intent) Loading