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

Commit 7ec4a10b authored by Vaibhav Devmurari's avatar Vaibhav Devmurari
Browse files

Refactor shortcut handling into before/after key capture stages

With key capture APIs, we need to split shortcut and system keys
handling into stages:
- Before key capture: System keys like functional row and
  non-capturable shortcuts (Home + Desktop windowing)
- After key capture: All remaining system shortcuts that only get
  executed if the focusing window doesn't have key capture enabled
- Unhandled shortcuts: Shortcuts that need to be executed if key
  capturing window doesn;t consume certain keys

Test: atest InputTests
DD: go/key_capture
Bug: 416681006
Flag: EXEMPT refactor
Change-Id: Ia3f8e63a6ac69b60ac100aed8b844e2e2629b572
parent 24af31ea
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -27,6 +27,7 @@ parcelable AidlInputGestureData {
    String appLaunchRole;
    String appLaunchPackageName;
    String appLaunchClassName;
    boolean allowCaptureByFocusedWindow;

    @JavaDerive(equals=true)
    parcelable KeyTrigger {
+17 −0
Original line number Diff line number Diff line
@@ -56,6 +56,11 @@ public final class InputGestureData {
        return new Action(mInputGestureData.gestureType, getAppLaunchData());
    }

    /** Returns if the gesture can be captured by the focused window */
    public boolean allowCaptureByFocusedWindow() {
        return mInputGestureData.allowCaptureByFocusedWindow;
    }

    private void validate() {
        Trigger trigger = getTrigger();
        Action action = getAction();
@@ -93,6 +98,7 @@ public final class InputGestureData {
        private int mKeyGestureType = KeyGestureEvent.KEY_GESTURE_TYPE_UNSPECIFIED;
        @Nullable
        private AppLaunchData mAppLaunchData = null;
        private boolean mAllowCaptureByFocusedWindow = true;

        /** Set input gesture trigger data for key based gestures */
        public Builder setTrigger(Trigger trigger) {
@@ -113,6 +119,15 @@ public final class InputGestureData {
            return this;
        }

        /**
         * Set whether the gesture can be blocked by the focused window when keyboard capture is
         * enabled.
         */
        public Builder setAllowCaptureByFocusedWindow(boolean allowCapture) {
            mAllowCaptureByFocusedWindow = allowCapture;
            return this;
        }

        /** Creates {@link android.hardware.input.InputGestureData} based on data provided */
        public InputGestureData build() throws IllegalArgumentException {
            if (mTrigger == null) {
@@ -141,6 +156,7 @@ public final class InputGestureData {
                    throw new IllegalArgumentException("AppLaunchData type is invalid!");
                }
            }
            data.allowCaptureByFocusedWindow = mAllowCaptureByFocusedWindow;
            return new InputGestureData(data);
        }
    }
@@ -150,6 +166,7 @@ public final class InputGestureData {
        return "InputGestureData { "
                + "trigger = " + getTrigger()
                + ", action = " + getAction()
                + ", allowCaptureByFocusedWindow = " + mInputGestureData.allowCaptureByFocusedWindow
                + " }";
    }

+137 −86
Original line number Diff line number Diff line
@@ -104,167 +104,217 @@ final class InputGestureManager {
                createKeyGesture(
                        KeyEvent.KEYCODE_A,
                        KeyEvent.META_META_ON,
                        KeyGestureEvent.KEY_GESTURE_TYPE_LAUNCH_ASSISTANT
                        KeyGestureEvent.KEY_GESTURE_TYPE_LAUNCH_ASSISTANT,
                        /* allowCaptureByFocusedWindow = */true
                ),
                createKeyGesture(
                        KeyEvent.KEYCODE_H,
                        KeyEvent.META_META_ON,
                        KeyGestureEvent.KEY_GESTURE_TYPE_HOME
                        KeyGestureEvent.KEY_GESTURE_TYPE_HOME,
                        /* allowCaptureByFocusedWindow = */false
                ),
                createKeyGesture(
                        KeyEvent.KEYCODE_ENTER,
                        KeyEvent.META_META_ON,
                        KeyGestureEvent.KEY_GESTURE_TYPE_HOME
                        KeyGestureEvent.KEY_GESTURE_TYPE_HOME,
                        /* allowCaptureByFocusedWindow = */false
                ),
                createKeyGesture(
                        KeyEvent.KEYCODE_I,
                        KeyEvent.META_META_ON,
                        KeyGestureEvent.KEY_GESTURE_TYPE_LAUNCH_SYSTEM_SETTINGS
                        KeyGestureEvent.KEY_GESTURE_TYPE_LAUNCH_SYSTEM_SETTINGS,
                        /* allowCaptureByFocusedWindow = */true
                ),
                createKeyGesture(
                        KeyEvent.KEYCODE_L,
                        KeyEvent.META_META_ON,
                        KeyGestureEvent.KEY_GESTURE_TYPE_LOCK_SCREEN
                        KeyGestureEvent.KEY_GESTURE_TYPE_LOCK_SCREEN,
                        /* allowCaptureByFocusedWindow = */true
                ),
                createKeyGesture(
                        KeyEvent.KEYCODE_N,
                        KeyEvent.META_META_ON,
                        KeyGestureEvent.KEY_GESTURE_TYPE_TOGGLE_NOTIFICATION_PANEL
                        KeyGestureEvent.KEY_GESTURE_TYPE_TOGGLE_NOTIFICATION_PANEL,
                        /* allowCaptureByFocusedWindow = */true
                ),
                createKeyGesture(
                        KeyEvent.KEYCODE_S,
                        KeyEvent.META_META_ON,
                        KeyGestureEvent.KEY_GESTURE_TYPE_TAKE_SCREENSHOT
                        KeyGestureEvent.KEY_GESTURE_TYPE_TAKE_SCREENSHOT,
                        /* allowCaptureByFocusedWindow = */true
                ),
                createKeyGesture(
                        KeyEvent.KEYCODE_ESCAPE,
                        KeyEvent.META_META_ON,
                        KeyGestureEvent.KEY_GESTURE_TYPE_BACK
                        KeyGestureEvent.KEY_GESTURE_TYPE_BACK,
                        /* allowCaptureByFocusedWindow = */true
                ),
                createKeyGesture(
                        KeyEvent.KEYCODE_DPAD_UP,
                        KeyEvent.META_META_ON | KeyEvent.META_CTRL_ON,
                        KeyGestureEvent.KEY_GESTURE_TYPE_MULTI_WINDOW_NAVIGATION
                        KeyGestureEvent.KEY_GESTURE_TYPE_MULTI_WINDOW_NAVIGATION,
                        /* allowCaptureByFocusedWindow = */false
                ),
                createKeyGesture(
                        KeyEvent.KEYCODE_DPAD_DOWN,
                        KeyEvent.META_META_ON | KeyEvent.META_CTRL_ON,
                        KeyGestureEvent.KEY_GESTURE_TYPE_DESKTOP_MODE
                        KeyGestureEvent.KEY_GESTURE_TYPE_DESKTOP_MODE,
                        /* allowCaptureByFocusedWindow = */false
                ),
                createKeyGesture(
                        KeyEvent.KEYCODE_DPAD_LEFT,
                        KeyEvent.META_META_ON,
                        KeyGestureEvent.KEY_GESTURE_TYPE_BACK
                        KeyGestureEvent.KEY_GESTURE_TYPE_BACK,
                        /* allowCaptureByFocusedWindow = */true
                ),
                createKeyGesture(
                        KeyEvent.KEYCODE_DPAD_LEFT,
                        KeyEvent.META_META_ON | KeyEvent.META_CTRL_ON,
                        KeyGestureEvent.KEY_GESTURE_TYPE_SPLIT_SCREEN_NAVIGATION_LEFT
                        KeyGestureEvent.KEY_GESTURE_TYPE_SPLIT_SCREEN_NAVIGATION_LEFT,
                        /* allowCaptureByFocusedWindow = */false
                ),
                createKeyGesture(
                        KeyEvent.KEYCODE_DPAD_RIGHT,
                        KeyEvent.META_META_ON | KeyEvent.META_CTRL_ON,
                        KeyGestureEvent.KEY_GESTURE_TYPE_SPLIT_SCREEN_NAVIGATION_RIGHT
                        KeyGestureEvent.KEY_GESTURE_TYPE_SPLIT_SCREEN_NAVIGATION_RIGHT,
                        /* allowCaptureByFocusedWindow = */false
                ),
                createKeyGesture(
                        KeyEvent.KEYCODE_SLASH,
                        KeyEvent.META_META_ON,
                        KeyGestureEvent.KEY_GESTURE_TYPE_OPEN_SHORTCUT_HELPER
                        KeyGestureEvent.KEY_GESTURE_TYPE_OPEN_SHORTCUT_HELPER,
                        /* allowCaptureByFocusedWindow = */true
                ),
                createKeyGesture(
                        KeyEvent.KEYCODE_TAB,
                        KeyEvent.META_META_ON,
                        KeyGestureEvent.KEY_GESTURE_TYPE_RECENT_APPS
                        KeyGestureEvent.KEY_GESTURE_TYPE_RECENT_APPS,
                        /* allowCaptureByFocusedWindow = */true
                )
        ));
        if ("1".equals(SystemProperties.get("ro.debuggable"))) {
            systemShortcuts.add(createKeyGesture(
            systemShortcuts.add(
                    createKeyGesture(
                            KeyEvent.KEYCODE_DEL,
                            KeyEvent.META_META_ON | KeyEvent.META_CTRL_ON,
                    KeyGestureEvent.KEY_GESTURE_TYPE_TRIGGER_BUG_REPORT
                            KeyGestureEvent.KEY_GESTURE_TYPE_TRIGGER_BUG_REPORT,
                            /* allowCaptureByFocusedWindow = */true
                    ));
        }
        if (DesktopExperienceFlags.ENABLE_MOVE_TO_NEXT_DISPLAY_SHORTCUT.isTrue()) {
            systemShortcuts.add(createKeyGesture(
            systemShortcuts.add(
                    createKeyGesture(
                            KeyEvent.KEYCODE_D,
                            KeyEvent.META_META_ON | KeyEvent.META_CTRL_ON,
                    KeyGestureEvent.KEY_GESTURE_TYPE_MOVE_TO_NEXT_DISPLAY
                            KeyGestureEvent.KEY_GESTURE_TYPE_MOVE_TO_NEXT_DISPLAY,
                            /* allowCaptureByFocusedWindow = */false
                    ));
        }
        if (enableTalkbackAndMagnifierKeyGestures()) {
            systemShortcuts.add(createKeyGesture(KeyEvent.KEYCODE_T,
            systemShortcuts.add(
                    createKeyGesture(KeyEvent.KEYCODE_T,
                            KeyEvent.META_META_ON | KeyEvent.META_ALT_ON,
                    KeyGestureEvent.KEY_GESTURE_TYPE_TOGGLE_SCREEN_READER));
            systemShortcuts.add(createKeyGesture(KeyEvent.KEYCODE_M,
                            KeyGestureEvent.KEY_GESTURE_TYPE_TOGGLE_SCREEN_READER,
                            /* allowCaptureByFocusedWindow = */true
                    ));
            systemShortcuts.add(
                    createKeyGesture(KeyEvent.KEYCODE_M,
                            KeyEvent.META_META_ON | KeyEvent.META_ALT_ON,
                    KeyGestureEvent.KEY_GESTURE_TYPE_TOGGLE_MAGNIFICATION));
            systemShortcuts.add(createKeyGesture(KeyEvent.KEYCODE_S,
                            KeyGestureEvent.KEY_GESTURE_TYPE_TOGGLE_MAGNIFICATION,
                            /* allowCaptureByFocusedWindow = */true
                    ));
            systemShortcuts.add(
                    createKeyGesture(KeyEvent.KEYCODE_S,
                            KeyEvent.META_META_ON | KeyEvent.META_ALT_ON,
                    KeyGestureEvent.KEY_GESTURE_TYPE_ACTIVATE_SELECT_TO_SPEAK));
                            KeyGestureEvent.KEY_GESTURE_TYPE_ACTIVATE_SELECT_TO_SPEAK,
                            /* allowCaptureByFocusedWindow = */true
                    ));
        }
        if (enableVoiceAccessKeyGestures()) {
            systemShortcuts.add(
                    createKeyGesture(
                            KeyEvent.KEYCODE_V,
                            KeyEvent.META_META_ON | KeyEvent.META_ALT_ON,
                            KeyGestureEvent.KEY_GESTURE_TYPE_TOGGLE_VOICE_ACCESS));
                            KeyGestureEvent.KEY_GESTURE_TYPE_TOGGLE_VOICE_ACCESS,
                            /* allowCaptureByFocusedWindow = */true
                    ));
        }
        if (DesktopModeFlags.ENABLE_TASK_RESIZING_KEYBOARD_SHORTCUTS.isTrue()) {
            systemShortcuts.add(createKeyGesture(
            systemShortcuts.add(
                    createKeyGesture(
                            KeyEvent.KEYCODE_LEFT_BRACKET,
                            KeyEvent.META_META_ON,
                    KeyGestureEvent.KEY_GESTURE_TYPE_SNAP_LEFT_FREEFORM_WINDOW
                            KeyGestureEvent.KEY_GESTURE_TYPE_SNAP_LEFT_FREEFORM_WINDOW,
                            /* allowCaptureByFocusedWindow = */false
                    ));
            systemShortcuts.add(createKeyGesture(
            systemShortcuts.add(
                    createKeyGesture(
                            KeyEvent.KEYCODE_RIGHT_BRACKET,
                            KeyEvent.META_META_ON,
                    KeyGestureEvent.KEY_GESTURE_TYPE_SNAP_RIGHT_FREEFORM_WINDOW
                            KeyGestureEvent.KEY_GESTURE_TYPE_SNAP_RIGHT_FREEFORM_WINDOW,
                            /* allowCaptureByFocusedWindow = */false
                    ));
            systemShortcuts.add(createKeyGesture(
            systemShortcuts.add(
                    createKeyGesture(
                            KeyEvent.KEYCODE_EQUALS,
                            KeyEvent.META_META_ON,
                    KeyGestureEvent.KEY_GESTURE_TYPE_TOGGLE_MAXIMIZE_FREEFORM_WINDOW
                            KeyGestureEvent.KEY_GESTURE_TYPE_TOGGLE_MAXIMIZE_FREEFORM_WINDOW,
                            /* allowCaptureByFocusedWindow = */false
                    ));
            systemShortcuts.add(createKeyGesture(
            systemShortcuts.add(
                    createKeyGesture(
                            KeyEvent.KEYCODE_MINUS,
                            KeyEvent.META_META_ON,
                    KeyGestureEvent.KEY_GESTURE_TYPE_MINIMIZE_FREEFORM_WINDOW
                            KeyGestureEvent.KEY_GESTURE_TYPE_MINIMIZE_FREEFORM_WINDOW,
                            /* allowCaptureByFocusedWindow = */false
                    ));
        }
        if (keyboardA11yShortcutControl()) {
            systemShortcuts.add(createKeyGesture(
            systemShortcuts.add(
                    createKeyGesture(
                            KeyEvent.KEYCODE_3,
                            KeyEvent.META_META_ON | KeyEvent.META_ALT_ON,
                    KeyGestureEvent.KEY_GESTURE_TYPE_TOGGLE_BOUNCE_KEYS
                            KeyGestureEvent.KEY_GESTURE_TYPE_TOGGLE_BOUNCE_KEYS,
                            /* allowCaptureByFocusedWindow = */true
                    ));
            if (InputSettings.isAccessibilityMouseKeysFeatureFlagEnabled()) {
                systemShortcuts.add(createKeyGesture(
                systemShortcuts.add(
                        createKeyGesture(
                                KeyEvent.KEYCODE_4,
                                KeyEvent.META_META_ON | KeyEvent.META_ALT_ON,
                        KeyGestureEvent.KEY_GESTURE_TYPE_TOGGLE_MOUSE_KEYS
                                KeyGestureEvent.KEY_GESTURE_TYPE_TOGGLE_MOUSE_KEYS,
                                /* allowCaptureByFocusedWindow = */true
                        ));
            }
            systemShortcuts.add(createKeyGesture(
            systemShortcuts.add(
                    createKeyGesture(
                            KeyEvent.KEYCODE_5,
                            KeyEvent.META_META_ON | KeyEvent.META_ALT_ON,
                    KeyGestureEvent.KEY_GESTURE_TYPE_TOGGLE_STICKY_KEYS
                            KeyGestureEvent.KEY_GESTURE_TYPE_TOGGLE_STICKY_KEYS,
                            /* allowCaptureByFocusedWindow = */true
                    ));
            systemShortcuts.add(createKeyGesture(
            systemShortcuts.add(
                    createKeyGesture(
                            KeyEvent.KEYCODE_6,
                            KeyEvent.META_META_ON | KeyEvent.META_ALT_ON,
                    KeyGestureEvent.KEY_GESTURE_TYPE_TOGGLE_SLOW_KEYS
                            KeyGestureEvent.KEY_GESTURE_TYPE_TOGGLE_SLOW_KEYS,
                            /* allowCaptureByFocusedWindow = */true
                    ));
        }
        if (DesktopExperienceFlags.ENABLE_KEYBOARD_SHORTCUTS_TO_SWITCH_DESKS.isTrue()) {
            systemShortcuts.add(createKeyGesture(
            systemShortcuts.add(
                    createKeyGesture(
                            KeyEvent.KEYCODE_LEFT_BRACKET,
                            KeyEvent.META_META_ON | KeyEvent.META_CTRL_ON,
                    KeyGestureEvent.KEY_GESTURE_TYPE_SWITCH_TO_PREVIOUS_DESK
                            KeyGestureEvent.KEY_GESTURE_TYPE_SWITCH_TO_PREVIOUS_DESK,
                            /* allowCaptureByFocusedWindow = */false
                    ));
            systemShortcuts.add(createKeyGesture(
            systemShortcuts.add(
                    createKeyGesture(
                            KeyEvent.KEYCODE_RIGHT_BRACKET,
                            KeyEvent.META_META_ON | KeyEvent.META_CTRL_ON,
                    KeyGestureEvent.KEY_GESTURE_TYPE_SWITCH_TO_NEXT_DESK
                            KeyGestureEvent.KEY_GESTURE_TYPE_SWITCH_TO_NEXT_DESK,
                            /* allowCaptureByFocusedWindow = */false
                    ));
        }
        synchronized (mGestureLock) {
@@ -439,10 +489,11 @@ final class InputGestureManager {
    }

    private static InputGestureData createKeyGesture(int keycode, int modifierState,
            int keyGestureType) {
            int keyGestureType, boolean allowCaptureByFocusedWindow) {
        return new InputGestureData.Builder()
                .setTrigger(createKeyTrigger(keycode, modifierState))
                .setKeyGestureType(keyGestureType)
                .setAllowCaptureByFocusedWindow(allowCaptureByFocusedWindow)
                .build();
    }

+318 −182

File changed.

Preview size limit exceeded, changes collapsed.

+191 −863

File changed.

Preview size limit exceeded, changes collapsed.

Loading