summaryrefslogtreecommitdiff
path: root/cmds/input
diff options
context:
space:
mode:
authorMichael Wright <michaelwr@google.com>2015-06-05 12:41:42 +0000
committerAndroid Git Automerger <android-git-automerger@android.com>2015-06-05 12:41:42 +0000
commitcb59c0dea1f97c1f979ae83db81cd2eca6872fa2 (patch)
tree1857d5b21d3bba121e8c1714cfb2e8ad7ef35393 /cmds/input
parent0a5bfb463a1c6f7f49c99a923d152e96fe093eef (diff)
parent863b3cd1fa11da493962ef062f3650e4fb2c8f9f (diff)
am 863b3cd1: am 7d72fedd: Merge "Input command can fail (with exceptions) if the touchscreen id is not 0"
* commit '863b3cd1fa11da493962ef062f3650e4fb2c8f9f': Input command can fail (with exceptions) if the touchscreen id is not 0
Diffstat (limited to 'cmds/input')
-rw-r--r--cmds/input/src/com/android/commands/input/Input.java17
1 files changed, 14 insertions, 3 deletions
diff --git a/cmds/input/src/com/android/commands/input/Input.java b/cmds/input/src/com/android/commands/input/Input.java
index 2a7c79bdfb5b..754d3f510bbd 100644
--- a/cmds/input/src/com/android/commands/input/Input.java
+++ b/cmds/input/src/com/android/commands/input/Input.java
@@ -234,6 +234,18 @@ public class Input {
InputManager.INJECT_INPUT_EVENT_MODE_WAIT_FOR_FINISH);
}
+ private int getInputDeviceId(int inputSource) {
+ final int DEFAULT_DEVICE_ID = 0;
+ int[] devIds = InputDevice.getDeviceIds();
+ for (int devId : devIds) {
+ InputDevice inputDev = InputDevice.getDevice(devId);
+ if (inputDev.supportsSource(inputSource)) {
+ return devId;
+ }
+ }
+ return DEFAULT_DEVICE_ID;
+ }
+
/**
* Builds a MotionEvent and injects it into the event stream.
*
@@ -249,11 +261,10 @@ public class Input {
final int DEFAULT_META_STATE = 0;
final float DEFAULT_PRECISION_X = 1.0f;
final float DEFAULT_PRECISION_Y = 1.0f;
- final int DEFAULT_DEVICE_ID = 0;
final int DEFAULT_EDGE_FLAGS = 0;
MotionEvent event = MotionEvent.obtain(when, when, action, x, y, pressure, DEFAULT_SIZE,
- DEFAULT_META_STATE, DEFAULT_PRECISION_X, DEFAULT_PRECISION_Y, DEFAULT_DEVICE_ID,
- DEFAULT_EDGE_FLAGS);
+ DEFAULT_META_STATE, DEFAULT_PRECISION_X, DEFAULT_PRECISION_Y,
+ getInputDeviceId(inputSource), DEFAULT_EDGE_FLAGS);
event.setSource(inputSource);
Log.i(TAG, "injectMotionEvent: " + event);
InputManager.getInstance().injectInputEvent(event,