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

Commit d77e0c95 authored by Wenyu Zhang's avatar Wenyu Zhang
Browse files

a11y: Remove TalkBack keyboard shortcut handling from PhoneWindowManager

With key gesture handler APIs, we can handle shortcuts in A11y
directly, this can allow components to react appropriately.
e.g. Use displayId passed in key gesture event to show UI on
correct display instead of routing that information from PWM to
A11y service.

Attaching the original cimmit that added TalkBack keyboard shortcut for
reference: I42d61f620b7b15e0e4d215d6b99b090b9862b15d.

Note that TalkbackShortcutController.java is used by wear via
`TRIPLE_PRESS` so we'll keep it. Further refactor can be done in
following CL in case needed.

Change-Id: I1981de4e30a9b4fda7f13056d91b3be7e80c10ef
Bug: b/413279228
Test: atest KeyGestureEventTests
Flag: EXEMPT refactor
parent a60b62c5
Loading
Loading
Loading
Loading
+1 −12
Original line number Diff line number Diff line
@@ -79,7 +79,6 @@ import static android.view.WindowManagerGlobal.ADD_PERMISSION_DENIED;
import static android.view.contentprotection.flags.Flags.createAccessibilityOverlayAppOpEnabled;

import static com.android.hardware.input.Flags.enableNew25q2Keycodes;
import static com.android.hardware.input.Flags.enableTalkbackAndMagnifierKeyGestures;
import static com.android.server.policy.WindowManagerPolicy.WindowManagerFuncs.CAMERA_LENS_COVERED;
import static com.android.server.policy.WindowManagerPolicy.WindowManagerFuncs.CAMERA_LENS_COVER_ABSENT;
import static com.android.server.policy.WindowManagerPolicy.WindowManagerFuncs.CAMERA_LENS_UNCOVERED;
@@ -1654,8 +1653,7 @@ public class PhoneWindowManager implements WindowManagerPolicy {
            case TRIPLE_PRESS_PRIMARY_NOTHING:
                break;
            case TRIPLE_PRESS_PRIMARY_TOGGLE_ACCESSIBILITY:
                mTalkbackShortcutController.toggleTalkback(mCurrentUserId,
                        TalkbackShortcutController.ShortcutSource.GESTURE);
                mTalkbackShortcutController.toggleTalkback(mCurrentUserId);
                if (mTalkbackShortcutController.isTalkBackShortcutGestureEnabled()) {
                    performHapticFeedback(HapticFeedbackConstants.CONFIRM,
                            "Stem primary - Triple Press - Toggle Accessibility");
@@ -3360,9 +3358,6 @@ public class PhoneWindowManager implements WindowManagerPolicy {
        if (!delegateBackGestureToShell()) {
            supportedGestures.add(KeyGestureEvent.KEY_GESTURE_TYPE_BACK);
        }
        if (enableTalkbackAndMagnifierKeyGestures()) {
            supportedGestures.add(KeyGestureEvent.KEY_GESTURE_TYPE_TOGGLE_TALKBACK);
        }
        if (!com.android.window.flags.Flags.grantManageKeyGesturesToRecents()) {
            // When grantManageKeyGesturesToRecents is enabled, the event is handled in the
            // recents app.
@@ -3549,12 +3544,6 @@ public class PhoneWindowManager implements WindowManagerPolicy {
                    closeSystemDialogsAsUser(UserHandle.CURRENT_OR_SELF);
                }
                break;
            case KeyGestureEvent.KEY_GESTURE_TYPE_TOGGLE_TALKBACK:
                if (complete) {
                    mTalkbackShortcutController.toggleTalkback(mCurrentUserId,
                            TalkbackShortcutController.ShortcutSource.KEYBOARD);
                }
                break;
            case KeyGestureEvent.KEY_GESTURE_TYPE_LAUNCH_APPLICATION:
                AppLaunchData data = event.getAppLaunchData();
                if (complete && canLaunchApp && data != null) {
+3 −8
Original line number Diff line number Diff line
@@ -38,11 +38,6 @@ class TalkbackShortcutController {
    private static final String TALKBACK_LABEL = "TalkBack";
    private final Context mContext;

    public enum ShortcutSource {
        GESTURE,
        KEYBOARD,
    }

    TalkbackShortcutController(Context context) {
        mContext = context;
    }
@@ -53,7 +48,7 @@ class TalkbackShortcutController {
     * @return talkback state after toggle. {@code true} if talkback is enabled, {@code false} if
     * talkback is disabled
     */
    boolean toggleTalkback(int userId, ShortcutSource source) {
    boolean toggleTalkback(int userId) {
        final Set<ComponentName> enabledServices =
                AccessibilityUtils.getEnabledServicesFromSettings(mContext, userId);
        ComponentName componentName =
@@ -66,13 +61,13 @@ class TalkbackShortcutController {

        boolean isTalkbackAlreadyEnabled = enabledServices.contains(componentName);

        if (source == ShortcutSource.KEYBOARD || isTalkBackShortcutGestureEnabled()) {
        if (isTalkBackShortcutGestureEnabled()) {
            isTalkbackAlreadyEnabled = !isTalkbackAlreadyEnabled;
            AccessibilityUtils.setAccessibilityServiceState(mContext, componentName,
                    isTalkbackAlreadyEnabled, userId);

            // log stem triple press telemetry if it's a talkback enabled event.
            if (source == ShortcutSource.GESTURE && isTalkbackAlreadyEnabled) {
            if (isTalkbackAlreadyEnabled) {
                logStemTriplePressAccessibilityTelemetry(componentName);
            }
        }
+0 −9
Original line number Diff line number Diff line
@@ -395,15 +395,6 @@ public class KeyGestureEventTests extends ShortcutKeyTestBase {
        mPhoneWindowManager.assertCloseAllDialogs();
    }

    @Test
    public void testKeyGestureToggleTalkback() {
        sendKeyGestureEventComplete(KeyGestureEvent.KEY_GESTURE_TYPE_TOGGLE_TALKBACK);
        mPhoneWindowManager.assertTalkBack(true);

        sendKeyGestureEventComplete(KeyGestureEvent.KEY_GESTURE_TYPE_TOGGLE_TALKBACK);
        mPhoneWindowManager.assertTalkBack(false);
    }

    @Test
    public void testKeyGestureToggleDoNotDisturb() {
        mPhoneWindowManager.overrideZenMode(Settings.Global.ZEN_MODE_OFF);
+1 −1
Original line number Diff line number Diff line
@@ -210,7 +210,7 @@ class TestPhoneWindowManager {
        }

        @Override
        boolean toggleTalkback(int currentUserId, ShortcutSource source) {
        boolean toggleTalkback(int currentUserId) {
            mIsTalkBackEnabled = !mIsTalkBackEnabled;
            return mIsTalkBackEnabled;
        }