summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Vaibhav Devmurari <vdevmurari@google.com> 2023-07-20 19:06:11 +0000
committer Vaibhav Devmurari <vdevmurari@google.com> 2023-08-25 12:28:28 +0000
commitc16ad205a32d453a61c1e06b6ad336271a662535 (patch)
tree4cfcbbf6127932204b01547e4d3983dcdbca83ce
parentcd0178db3a30ec8e64ec222e78922968854c0231 (diff)
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
-rw-r--r--services/core/java/com/android/server/policy/PhoneWindowManager.java37
-rw-r--r--services/tests/wmtests/src/com/android/server/policy/ShortcutLoggingTests.java6
2 files changed, 40 insertions, 3 deletions
diff --git a/services/core/java/com/android/server/policy/PhoneWindowManager.java b/services/core/java/com/android/server/policy/PhoneWindowManager.java
index b3aa09b8f17b..d5199ff97376 100644
--- a/services/core/java/com/android/server/policy/PhoneWindowManager.java
+++ b/services/core/java/com/android/server/policy/PhoneWindowManager.java
@@ -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()) {
- enterStageSplitFromRunningApp(true /* leftOrTop */);
- logKeyboardSystemsEvent(event, KeyboardLogEvent.SPLIT_SCREEN_NAVIGATION);
+ 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
diff --git a/services/tests/wmtests/src/com/android/server/policy/ShortcutLoggingTests.java b/services/tests/wmtests/src/com/android/server/policy/ShortcutLoggingTests.java
index 8fadecd0dc38..e13dc3eea729 100644
--- a/services/tests/wmtests/src/com/android/server/policy/ShortcutLoggingTests.java
+++ b/services/tests/wmtests/src/com/android/server/policy/ShortcutLoggingTests.java
@@ -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},