Merge "Use new input manager API."
This commit is contained in:
@@ -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)) {
|
||||
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;
|
||||
}
|
||||
} catch (RemoteException ex) {
|
||||
return MonkeyEvent.INJECT_ERROR_REMOTE_EXCEPTION;
|
||||
}
|
||||
|
||||
return MonkeyEvent.INJECT_SUCCESS;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user