summaryrefslogtreecommitdiffstats
path: root/cmds
diff options
context:
space:
mode:
authorJeff Brown <jeffbrown@google.com>2012-04-05 19:34:52 -0700
committerAndroid (Google) Code Review <android-gerrit@google.com>2012-04-05 19:34:52 -0700
commitfd94c39a5528d2899762d7037fbf7557e87a17db (patch)
tree49600a54e3b3e6acd70d0e94cad6a2fe6b730f6c /cmds
parente331666e3ed0726c1f165224c803705c78b0e927 (diff)
parent001a30f89ae0cb70d26eacb88dc2a96b9473b3dd (diff)
downloadandroid_development-fd94c39a5528d2899762d7037fbf7557e87a17db.tar.gz
android_development-fd94c39a5528d2899762d7037fbf7557e87a17db.tar.bz2
android_development-fd94c39a5528d2899762d7037fbf7557e87a17db.zip
Merge "Use new input manager API."
Diffstat (limited to 'cmds')
-rw-r--r--cmds/monkey/src/com/android/commands/monkey/MonkeyKeyEvent.java41
-rw-r--r--cmds/monkey/src/com/android/commands/monkey/MonkeyMotionEvent.java9
-rw-r--r--cmds/monkey/src/com/android/commands/monkey/MonkeyTouchEvent.java9
-rw-r--r--cmds/monkey/src/com/android/commands/monkey/MonkeyTrackballEvent.java10
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);
- }
}