Merge "Use new input manager API."
This commit is contained in:
@@ -17,8 +17,11 @@
|
|||||||
package com.android.commands.monkey;
|
package com.android.commands.monkey;
|
||||||
|
|
||||||
import android.app.IActivityManager;
|
import android.app.IActivityManager;
|
||||||
|
import android.hardware.input.InputManager;
|
||||||
import android.os.RemoteException;
|
import android.os.RemoteException;
|
||||||
|
import android.os.SystemClock;
|
||||||
import android.view.IWindowManager;
|
import android.view.IWindowManager;
|
||||||
|
import android.view.InputDevice;
|
||||||
import android.view.KeyEvent;
|
import android.view.KeyEvent;
|
||||||
/**
|
/**
|
||||||
* monkey key event
|
* monkey key event
|
||||||
@@ -85,22 +88,6 @@ public class MonkeyKeyEvent extends MonkeyEvent {
|
|||||||
mEventTime = eventTime;
|
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
|
@Override
|
||||||
public boolean isThrottlable() {
|
public boolean isThrottlable() {
|
||||||
return (getAction() == KeyEvent.ACTION_UP);
|
return (getAction() == KeyEvent.ACTION_UP);
|
||||||
@@ -126,15 +113,21 @@ public class MonkeyKeyEvent extends MonkeyEvent {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// inject key event
|
long eventTime = mEventTime;
|
||||||
try {
|
if (eventTime == 0) {
|
||||||
if (!iwm.injectKeyEvent(getEvent(), false)) {
|
eventTime = SystemClock.uptimeMillis();
|
||||||
return MonkeyEvent.INJECT_FAIL;
|
}
|
||||||
}
|
long downTime = mDownTime;
|
||||||
} catch (RemoteException ex) {
|
if (downTime == 0) {
|
||||||
return MonkeyEvent.INJECT_ERROR_REMOTE_EXCEPTION;
|
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;
|
return MonkeyEvent.INJECT_SUCCESS;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,7 +17,7 @@
|
|||||||
package com.android.commands.monkey;
|
package com.android.commands.monkey;
|
||||||
|
|
||||||
import android.app.IActivityManager;
|
import android.app.IActivityManager;
|
||||||
import android.os.RemoteException;
|
import android.hardware.input.InputManager;
|
||||||
import android.os.SystemClock;
|
import android.os.SystemClock;
|
||||||
import android.util.SparseArray;
|
import android.util.SparseArray;
|
||||||
import android.view.IWindowManager;
|
import android.view.IWindowManager;
|
||||||
@@ -185,11 +185,10 @@ public abstract class MonkeyMotionEvent extends MonkeyEvent {
|
|||||||
System.out.println(msg.toString());
|
System.out.println(msg.toString());
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
if (!injectMotionEvent(iwm, me)) {
|
if (!InputManager.injectInputEvent(me,
|
||||||
|
InputManager.INJECT_INPUT_EVENT_MODE_WAIT_FOR_RESULT)) {
|
||||||
return MonkeyEvent.INJECT_FAIL;
|
return MonkeyEvent.INJECT_FAIL;
|
||||||
}
|
}
|
||||||
} catch (RemoteException ex) {
|
|
||||||
return MonkeyEvent.INJECT_ERROR_REMOTE_EXCEPTION;
|
|
||||||
} finally {
|
} finally {
|
||||||
me.recycle();
|
me.recycle();
|
||||||
}
|
}
|
||||||
@@ -197,6 +196,4 @@ public abstract class MonkeyMotionEvent extends MonkeyEvent {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected abstract String getTypeLabel();
|
protected abstract String getTypeLabel();
|
||||||
protected abstract boolean injectMotionEvent(IWindowManager iwm, MotionEvent me)
|
|
||||||
throws RemoteException;
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,10 +16,7 @@
|
|||||||
|
|
||||||
package com.android.commands.monkey;
|
package com.android.commands.monkey;
|
||||||
|
|
||||||
import android.os.RemoteException;
|
|
||||||
import android.view.IWindowManager;
|
|
||||||
import android.view.InputDevice;
|
import android.view.InputDevice;
|
||||||
import android.view.MotionEvent;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -34,10 +31,4 @@ public class MonkeyTouchEvent extends MonkeyMotionEvent {
|
|||||||
protected String getTypeLabel() {
|
protected String getTypeLabel() {
|
||||||
return "Touch";
|
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;
|
package com.android.commands.monkey;
|
||||||
|
|
||||||
import android.os.RemoteException;
|
|
||||||
import android.view.IWindowManager;
|
|
||||||
import android.view.InputDevice;
|
import android.view.InputDevice;
|
||||||
import android.view.MotionEvent;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* monkey trackball event
|
* monkey trackball event
|
||||||
@@ -34,10 +30,4 @@ public class MonkeyTrackballEvent extends MonkeyMotionEvent {
|
|||||||
protected String getTypeLabel() {
|
protected String getTypeLabel() {
|
||||||
return "Trackball";
|
return "Trackball";
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
protected boolean injectMotionEvent(IWindowManager iwm, MotionEvent me)
|
|
||||||
throws RemoteException {
|
|
||||||
return iwm.injectTrackballEvent(me, false);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user