• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Tags
No Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

frameworks/base


Commit MetaInfo

Revision08ff78b9769f79e228864281cebac4826916d0aa (tree)
Time2020-04-14 23:46:49
AuthorChih-Wei Huang <cwhuang@linu...>
CommiterChih-Wei Huang

Log Message

input: simulate long press properly

The original implementation of long press sends two ACTION_DOWN events
which would be interpreted as a double tap. For example, sending
a long press POWER key will launch the camera:

11-21 16:27:37.320 2223 2223 I Input : injectKeyEvent: KeyEvent { action=ACTION_DOWN, keyCode=KEYCODE_POWER, scanCode=0, metaState=0, flags=0x0, repeatCount=0, eventTime=39641, downTime=39641, deviceId=-1, source=0x101 }
11-21 16:27:37.321 2223 2223 I Input : injectKeyEvent: KeyEvent { action=ACTION_DOWN, keyCode=KEYCODE_POWER, scanCode=0, metaState=0, flags=0x80, repeatCount=1, eventTime=39641, downTime=39641, deviceId=-1, source=0x101 }
11-21 16:27:37.322 1411 1565 I GestureLauncherService: Power button double tap gesture detected, launching camera. Interval=0ms
11-21 16:27:37.322 2223 2223 I Input : injectKeyEvent: KeyEvent { action=ACTION_UP, keyCode=KEYCODE_POWER, scanCode=0, metaState=0, flags=0x0, repeatCount=0, eventTime=39641, downTime=39641, deviceId=-1, source=0x101 }

This is unexpected and incorrect.

Just simulate the long press by delaying ACTION_UP one second.

Change Summary

Incremental Difference

--- a/cmds/input/src/com/android/commands/input/Input.java
+++ b/cmds/input/src/com/android/commands/input/Input.java
@@ -192,7 +192,7 @@ public class Input extends BaseCommand {
192192 }
193193
194194 private void sendKeyEvent(int inputSource, int keyCode, boolean longpress, int displayId) {
195- final long now = SystemClock.uptimeMillis();
195+ long now = SystemClock.uptimeMillis();
196196 int repeatCount = 0;
197197
198198 KeyEvent event = new KeyEvent(now, now, KeyEvent.ACTION_DOWN, keyCode, repeatCount,
@@ -202,9 +202,13 @@ public class Input extends BaseCommand {
202202
203203 injectKeyEvent(event);
204204 if (longpress) {
205- repeatCount++;
206- injectKeyEvent(KeyEvent.changeTimeRepeat(event, now, repeatCount,
207- KeyEvent.FLAG_LONG_PRESS));
205+ try {
206+ Thread.sleep(1000);
207+ } catch (InterruptedException e) {
208+ throw new RuntimeException(e);
209+ }
210+ now = SystemClock.uptimeMillis();
211+ event = KeyEvent.changeTimeRepeat(event, now, repeatCount);
208212 }
209213 injectKeyEvent(KeyEvent.changeAction(event, KeyEvent.ACTION_UP));
210214 }