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

Commit c16ad205 authored by Vaibhav Devmurari's avatar Vaibhav Devmurari
Browse files

Handle BACK shortcuts in PWM by injection

Current BACK shortcuts are handled in InputDispatcher and
Meta+`, Meta+Backspace, Meta+Left are converted to KEY_BACK
in InputDispatcher instead of being handled in PWM since BACK is
processed on app side instead of System fully handling it.

This blocks us from handling shortcuts like Meta+Ctrl+Left since
by the time keys reach PWM it is converted to Key_Back+Left and
doesn't get processed. Instead we wil handle everything in PWM now
and try to get similar behavior by injecting KEY_BACK whenever
Back shortcuts are pressed.

Bug: 290473497
Test: atest ShortcutLoggingTests
Test: atest BackShortcutTests
Change-Id: Idc60b303abb9ebfd0142e7686aabc4a39e529c19
parent cd0178db
Loading
Loading
Loading
Loading
+34 −3
Original line number Diff line number Diff line
@@ -3342,6 +3342,13 @@ public class PhoneWindowManager implements WindowManagerPolicy {
                    return true;
                }
                break;
            case KeyEvent.KEYCODE_DEL:
            case KeyEvent.KEYCODE_GRAVE:
                if (firstDown && event.isMetaPressed()) {
                    logKeyboardSystemsEvent(event, KeyboardLogEvent.BACK);
                    injectBackGesture(event.getDownTime());
                    return true;
                }
            case KeyEvent.KEYCODE_DPAD_UP:
                if (firstDown && event.isMetaPressed() && event.isCtrlPressed()) {
                    StatusBarManagerInternal statusbar = getStatusBarManagerInternal();
@@ -3353,9 +3360,14 @@ public class PhoneWindowManager implements WindowManagerPolicy {
                }
                break;
            case KeyEvent.KEYCODE_DPAD_LEFT:
                if (firstDown && event.isMetaPressed() && event.isCtrlPressed()) {
                if (firstDown && event.isMetaPressed()) {
                    if (event.isCtrlPressed()) {
                        enterStageSplitFromRunningApp(true /* leftOrTop */);
                        logKeyboardSystemsEvent(event, KeyboardLogEvent.SPLIT_SCREEN_NAVIGATION);
                    } else {
                        logKeyboardSystemsEvent(event, KeyboardLogEvent.BACK);
                        injectBackGesture(event.getDownTime());
                    }
                    return true;
                }
                break;
@@ -3618,6 +3630,25 @@ public class PhoneWindowManager implements WindowManagerPolicy {
        return (metaState & KeyEvent.META_META_ON) != 0;
    }

    @SuppressLint("MissingPermission")
    private void injectBackGesture(long downtime) {
        // Create and inject down event
        KeyEvent downEvent = new KeyEvent(downtime, downtime, KeyEvent.ACTION_DOWN,
                KeyEvent.KEYCODE_BACK, 0 /* repeat */, 0 /* metaState */,
                KeyCharacterMap.VIRTUAL_KEYBOARD, 0 /* scancode */,
                KeyEvent.FLAG_FROM_SYSTEM | KeyEvent.FLAG_VIRTUAL_HARD_KEY,
                InputDevice.SOURCE_KEYBOARD);
        mInputManager.injectInputEvent(downEvent, InputManager.INJECT_INPUT_EVENT_MODE_ASYNC);


        // Create and inject up event
        KeyEvent upEvent = KeyEvent.changeAction(downEvent, KeyEvent.ACTION_UP);
        mInputManager.injectInputEvent(upEvent, InputManager.INJECT_INPUT_EVENT_MODE_ASYNC);

        downEvent.recycle();
        upEvent.recycle();
    }

    private boolean handleHomeShortcuts(int displayId, IBinder focusedToken, KeyEvent event) {
        // First we always handle the home key here, so applications
        // can never break it, although if keyguard is on, we do let
+6 −0
Original line number Diff line number Diff line
@@ -65,6 +65,12 @@ public class ShortcutLoggingTests extends ShortcutKeyTestBase {
                        KeyboardLogEvent.RECENT_APPS, KeyEvent.KEYCODE_TAB, ALT_ON},
                {"BACK key -> Go back", new int[]{KeyEvent.KEYCODE_BACK}, KeyboardLogEvent.BACK,
                        KeyEvent.KEYCODE_BACK, 0},
                {"Meta + `(grave) -> Go back", new int[]{META_KEY, KeyEvent.KEYCODE_GRAVE},
                        KeyboardLogEvent.BACK, KeyEvent.KEYCODE_GRAVE, META_ON},
                {"Meta + Left arrow -> Go back", new int[]{META_KEY, KeyEvent.KEYCODE_DPAD_LEFT},
                        KeyboardLogEvent.BACK, KeyEvent.KEYCODE_DPAD_LEFT, META_ON},
                {"Meta + Del -> Go back", new int[]{META_KEY, KeyEvent.KEYCODE_DEL},
                        KeyboardLogEvent.BACK, KeyEvent.KEYCODE_DEL, META_ON},
                {"APP_SWITCH key -> Open App switcher", new int[]{KeyEvent.KEYCODE_APP_SWITCH},
                        KeyboardLogEvent.APP_SWITCH, KeyEvent.KEYCODE_APP_SWITCH, 0},
                {"ASSIST key -> Launch assistant", new int[]{KeyEvent.KEYCODE_ASSIST},