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

Commit cecbcb9e authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge "a11y: Magnify the Magnification dialog" into main

parents c0c7dda9 7f9ce6b1
Loading
Loading
Loading
Loading
+22 −0
Original line number Diff line number Diff line
@@ -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();
        }
    }
}
+3 −0
Original line number Diff line number Diff line
@@ -207,4 +207,7 @@ interface IAccessibilityManager {

    @EnforcePermission("MANAGE_ACCESSIBILITY")
    void setTrustedAccessibilityServiceForTesting(in ComponentName trustedAccessibilityService);

    @EnforcePermission("MANAGE_ACCESSIBILITY")
    oneway void enableMagnificationAndZoomIn(int displayId);
}
+6 −0
Original line number Diff line number Diff line
@@ -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";
}
+4 −4
Original line number Diff line number Diff line
@@ -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(
@@ -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(
@@ -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(
@@ -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(
+102 −13
Original line number Diff line number Diff line
@@ -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
@@ -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

@@ -61,7 +63,7 @@ class KeyGestureDialogInteractorTest : SysuiTestCase() {
        underTest =
            KeyGestureDialogInteractor(
                kosmos.applicationContext,
                repository,
                mockRepository,
                broadcastDispatcher,
                testDispatcher,
                kosmos.fakeExecutorHandler,
@@ -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()
@@ -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),
@@ -122,6 +209,7 @@ class KeyGestureDialogInteractorTest : SysuiTestCase() {
        metaState: Int,
        keyCode: Int,
        targetName: String,
        displayId: Int,
    ) {
        val intent =
            Intent().apply {
@@ -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