diff options
author | chaviw <chaviw@google.com> | 2019-01-04 13:36:36 -0800 |
---|---|---|
committer | chaviw <chaviw@google.com> | 2019-01-08 10:39:45 -0800 |
commit | 3a567f17d3082ac59d4ca3816e97dc2a4b076e4d (patch) | |
tree | ede6429a4ca82400d9b91c9653fe317a3c3b2cf7 /cmds/input/src | |
parent | fa432cf4c5358a1b1d039fceecb6b6bb70bf66f0 (diff) |
Added shell command for some general input events
Added shell command for events DOWN, UP, and MOVE. This can be invoked
by calling 'adb shell input event <DOWN|UP|MOVE> <x> <y>'
This was needed to test transferTouchFocus, but can be useful for other
testing as well.
Test: 'adb shell input event <DOWN|UP|MOVE> <x> <y>'
Change-Id: If3e77b04c7172505e7fe8998b5b3c496044870bb
Diffstat (limited to 'cmds/input/src')
-rw-r--r-- | cmds/input/src/com/android/commands/input/Input.java | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/cmds/input/src/com/android/commands/input/Input.java b/cmds/input/src/com/android/commands/input/Input.java index b905e94cd96f..0c861cfd3e63 100644 --- a/cmds/input/src/com/android/commands/input/Input.java +++ b/cmds/input/src/com/android/commands/input/Input.java @@ -44,6 +44,9 @@ public class Input extends BaseCommand { private static final String INVALID_DISPLAY_ARGUMENTS = "Error: Invalid arguments for display ID."; + private static final float DEFAULT_PRESSURE = 1.0f; + private static final float NO_PRESSURE = 0.0f; + private static final Map<String, Integer> SOURCES = new HashMap<String, Integer>() {{ put("keyboard", InputDevice.SOURCE_KEYBOARD); put("dpad", InputDevice.SOURCE_DPAD); @@ -76,6 +79,7 @@ public class Input extends BaseCommand { COMMANDS.put("draganddrop", new InputDragAndDrop()); COMMANDS.put("press", new InputPress()); COMMANDS.put("roll", new InputRoll()); + COMMANDS.put("motionevent", new InputMotionEvent()); } @Override @@ -304,6 +308,41 @@ public class Input extends BaseCommand { } } + class InputMotionEvent implements InputCmd { + @Override + public void run(int inputSource, int displayId) { + inputSource = getSource(inputSource, InputDevice.SOURCE_TOUCHSCREEN); + sendMotionEvent(inputSource, nextArgRequired(), Float.parseFloat(nextArgRequired()), + Float.parseFloat(nextArgRequired()), displayId); + } + + private void sendMotionEvent(int inputSource, String motionEventType, float x, float y, + int displayId) { + final int action; + final float pressure; + + switch (motionEventType.toUpperCase()) { + case "DOWN": + action = MotionEvent.ACTION_DOWN; + pressure = DEFAULT_PRESSURE; + break; + case "UP": + action = MotionEvent.ACTION_UP; + pressure = NO_PRESSURE; + break; + case "MOVE": + action = MotionEvent.ACTION_MOVE; + pressure = DEFAULT_PRESSURE; + break; + default: + throw new IllegalArgumentException("Unknown motionevent " + motionEventType); + } + + final long now = SystemClock.uptimeMillis(); + injectMotionEvent(inputSource, action, now, now, x, y, pressure, displayId); + } + } + /** * Abstract class for command * use nextArgRequired or nextArg to check next argument if necessary. @@ -391,5 +430,6 @@ public class Input extends BaseCommand { + " (Default: touchscreen)"); out.println(" press (Default: trackball)"); out.println(" roll <dx> <dy> (Default: trackball)"); + out.println(" event <DOWN|UP|MOVE> <x> <y> (Default: touchscreen)"); } } |