diff options
author | Jeff Brown <jeffbrown@google.com> | 2012-04-05 18:48:05 -0700 |
---|---|---|
committer | Jeff Brown <jeffbrown@google.com> | 2012-04-05 18:50:00 -0700 |
commit | 001a30f89ae0cb70d26eacb88dc2a96b9473b3dd (patch) | |
tree | 445c8a4abf8b15d289907bc61f2866d3237fa1e2 | |
parent | f94c1a54d878a04fe2fe590b0feb2cc57e7e099e (diff) | |
download | android_development-001a30f89ae0cb70d26eacb88dc2a96b9473b3dd.tar.gz android_development-001a30f89ae0cb70d26eacb88dc2a96b9473b3dd.tar.bz2 android_development-001a30f89ae0cb70d26eacb88dc2a96b9473b3dd.zip |
Use new input manager API.
Bug: 6110399
Change-Id: Icc0b2bb1261ce39809af6a2b78279b28d3a758c5
4 files changed, 20 insertions, 49 deletions
diff --git a/cmds/monkey/src/com/android/commands/monkey/MonkeyKeyEvent.java b/cmds/monkey/src/com/android/commands/monkey/MonkeyKeyEvent.java index 455c00906..a78f918f0 100644 --- a/cmds/monkey/src/com/android/commands/monkey/MonkeyKeyEvent.java +++ b/cmds/monkey/src/com/android/commands/monkey/MonkeyKeyEvent.java @@ -17,8 +17,11 @@ package com.android.commands.monkey; import android.app.IActivityManager; +import android.hardware.input.InputManager; import android.os.RemoteException; +import android.os.SystemClock; import android.view.IWindowManager; +import android.view.InputDevice; import android.view.KeyEvent; /** * monkey key event @@ -85,22 +88,6 @@ public class MonkeyKeyEvent extends MonkeyEvent { mEventTime = eventTime; } - /** - * @return the key event - */ - private KeyEvent getEvent() { - if (keyEvent == null) { - if (mDeviceId < 0) { - keyEvent = new KeyEvent(mAction, mKeyCode); - } else { - // for scripts - keyEvent = new KeyEvent(mDownTime, mEventTime, mAction, - mKeyCode, mRepeatCount, mMetaState, mDeviceId, mScancode); - } - } - return keyEvent; - } - @Override public boolean isThrottlable() { return (getAction() == KeyEvent.ACTION_UP); @@ -126,15 +113,21 @@ public class MonkeyKeyEvent extends MonkeyEvent { } } - // inject key event - try { - if (!iwm.injectKeyEvent(getEvent(), false)) { - return MonkeyEvent.INJECT_FAIL; - } - } catch (RemoteException ex) { - return MonkeyEvent.INJECT_ERROR_REMOTE_EXCEPTION; + long eventTime = mEventTime; + if (eventTime == 0) { + eventTime = SystemClock.uptimeMillis(); + } + long downTime = mDownTime; + if (downTime == 0) { + downTime = eventTime; + } + KeyEvent newEvent = new KeyEvent(downTime, eventTime, mAction, mKeyCode, + mRepeatCount, mMetaState, mDeviceId, mScancode, + KeyEvent.FLAG_FROM_SYSTEM, InputDevice.SOURCE_KEYBOARD); + if (!InputManager.injectInputEvent(newEvent, + InputManager.INJECT_INPUT_EVENT_MODE_WAIT_FOR_RESULT)) { + return MonkeyEvent.INJECT_FAIL; } - return MonkeyEvent.INJECT_SUCCESS; } } diff --git a/cmds/monkey/src/com/android/commands/monkey/MonkeyMotionEvent.java b/cmds/monkey/src/com/android/commands/monkey/MonkeyMotionEvent.java index c59382fd1..437efdfd8 100644 --- a/cmds/monkey/src/com/android/commands/monkey/MonkeyMotionEvent.java +++ b/cmds/monkey/src/com/android/commands/monkey/MonkeyMotionEvent.java @@ -17,7 +17,7 @@ package com.android.commands.monkey; import android.app.IActivityManager; -import android.os.RemoteException; +import android.hardware.input.InputManager; import android.os.SystemClock; import android.util.SparseArray; import android.view.IWindowManager; @@ -185,11 +185,10 @@ public abstract class MonkeyMotionEvent extends MonkeyEvent { System.out.println(msg.toString()); } try { - if (!injectMotionEvent(iwm, me)) { + if (!InputManager.injectInputEvent(me, + InputManager.INJECT_INPUT_EVENT_MODE_WAIT_FOR_RESULT)) { return MonkeyEvent.INJECT_FAIL; } - } catch (RemoteException ex) { - return MonkeyEvent.INJECT_ERROR_REMOTE_EXCEPTION; } finally { me.recycle(); } @@ -197,6 +196,4 @@ public abstract class MonkeyMotionEvent extends MonkeyEvent { } protected abstract String getTypeLabel(); - protected abstract boolean injectMotionEvent(IWindowManager iwm, MotionEvent me) - throws RemoteException; } diff --git a/cmds/monkey/src/com/android/commands/monkey/MonkeyTouchEvent.java b/cmds/monkey/src/com/android/commands/monkey/MonkeyTouchEvent.java index 7a91c46b9..a9fb12838 100644 --- a/cmds/monkey/src/com/android/commands/monkey/MonkeyTouchEvent.java +++ b/cmds/monkey/src/com/android/commands/monkey/MonkeyTouchEvent.java @@ -16,10 +16,7 @@ package com.android.commands.monkey; -import android.os.RemoteException; -import android.view.IWindowManager; import android.view.InputDevice; -import android.view.MotionEvent; /** @@ -34,10 +31,4 @@ public class MonkeyTouchEvent extends MonkeyMotionEvent { protected String getTypeLabel() { return "Touch"; } - - @Override - protected boolean injectMotionEvent(IWindowManager iwm, MotionEvent me) - throws RemoteException { - return iwm.injectPointerEvent(me, false); - } } diff --git a/cmds/monkey/src/com/android/commands/monkey/MonkeyTrackballEvent.java b/cmds/monkey/src/com/android/commands/monkey/MonkeyTrackballEvent.java index 5033be005..960e40ead 100644 --- a/cmds/monkey/src/com/android/commands/monkey/MonkeyTrackballEvent.java +++ b/cmds/monkey/src/com/android/commands/monkey/MonkeyTrackballEvent.java @@ -16,11 +16,7 @@ package com.android.commands.monkey; -import android.os.RemoteException; -import android.view.IWindowManager; import android.view.InputDevice; -import android.view.MotionEvent; - /** * monkey trackball event @@ -34,10 +30,4 @@ public class MonkeyTrackballEvent extends MonkeyMotionEvent { protected String getTypeLabel() { return "Trackball"; } - - @Override - protected boolean injectMotionEvent(IWindowManager iwm, MotionEvent me) - throws RemoteException { - return iwm.injectTrackballEvent(me, false); - } } |