From 2dd95b3f41f5be32fdb463c304bd65e120d92322 Mon Sep 17 00:00:00 2001 From: Philip Junker Date: Thu, 5 Aug 2021 18:01:06 +0200 Subject: [PATCH] Make sure adb shell input keyevent --longpress KEYCODE_DPAD_CENTER triggers View#performLongClick(...) KeyEvent#ACTION_UP removes the CheckForLongPress callback that triggers View#performLongClick(...) after the longpress timeout. By adding a delay in case of a long press, the View#CheckForLongPress callback runs as expected and the long press is triggered. Bug: 194799728 Test: manual; build ohm_gtv-userdebug and flash it; navigate to movie / app on main view of LauncherX; adb shell input keyevent --longpress KEYCODE_DPAD_CENTER; verify that longpress menu opens; adb shell input keyevent KEYCODE_DPAD_CENTER; verify that entity page opens Change-Id: Iae08a6c3b2c52888eae63c91a609f4aff06d2297 --- core/java/android/view/ViewConfiguration.java | 2 ++ .../java/com/android/server/input/InputShellCommand.java | 7 ++++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/core/java/android/view/ViewConfiguration.java b/core/java/android/view/ViewConfiguration.java index 0a3d0da6da1e0..495edab57abd3 100644 --- a/core/java/android/view/ViewConfiguration.java +++ b/core/java/android/view/ViewConfiguration.java @@ -600,6 +600,8 @@ public class ViewConfiguration { } /** + * Used for both key and motion events. + * * @return the duration in milliseconds before a press turns into * a long press */ diff --git a/services/core/java/com/android/server/input/InputShellCommand.java b/services/core/java/com/android/server/input/InputShellCommand.java index 720be826fd387..29aa2a873cc90 100644 --- a/services/core/java/com/android/server/input/InputShellCommand.java +++ b/services/core/java/com/android/server/input/InputShellCommand.java @@ -313,8 +313,13 @@ public class InputShellCommand extends ShellCommand { injectKeyEvent(event); if (longpress) { + try { + Thread.sleep(ViewConfiguration.getLongPressTimeout()); + } catch (InterruptedException e) { + throw new RuntimeException(e); + } // Some long press behavior would check the event time, we set a new event time here. - final long nextEventTime = now + ViewConfiguration.getGlobalActionKeyTimeout(); + final long nextEventTime = now + ViewConfiguration.getLongPressTimeout(); injectKeyEvent(KeyEvent.changeTimeRepeat(event, nextEventTime, 1 /* repeatCount */, KeyEvent.FLAG_LONG_PRESS)); }