diff options
author | Christopher Desjardins <christopher.desjardins@tomtom.com> | 2015-06-01 15:42:40 +0000 |
---|---|---|
committer | Christopher Desjardins <christopher.desjardins@tomtom.com> | 2015-06-04 09:12:49 +0200 |
commit | 30fefa4d5df1d690f69c2db0b631565acc98b91c (patch) | |
tree | 9ad6d318115658b79e5e9eeed7c5b8bb121080c5 /cmds/input | |
parent | bf17375e5e6195122ee24295cf05f012822711ec (diff) |
Input command can fail (with exceptions) if the touchscreen id is not 0
We had a device where the touchscreen was reconfigured during system
init, and as a result was assigned a device id that was not 0.
The following message from InputReader.cpp was logged when this occured:
I/InputReader( 762): Device reconfigured: id=4, name='himax-touchscreen', size 1024x600, orientation 1, mode 1, display id 0
Attempting to use the input command for the touchscreen in this state
will fail due to the hardcoded touchscreen device id.
Change-Id: I4e8fad864e7b83cce00c680b254bad06e1200f15
Diffstat (limited to 'cmds/input')
-rw-r--r-- | cmds/input/src/com/android/commands/input/Input.java | 17 |
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, |