Add support for multitouch pinch-zoom gesture to monkey.

Change-Id: Ib28f2ede95dbe01eae4d9c72906b6fdfeda44ce4
This commit is contained in:
Jeff Brown
2010-10-04 20:58:18 -07:00
parent 892dcfe10b
commit 585ab96950
9 changed files with 351 additions and 181 deletions

View File

@@ -732,6 +732,9 @@ public class Monkey {
} else if (opt.equals("--pct-anyevent")) {
int i = MonkeySourceRandom.FACTOR_ANYTHING;
mFactors[i] = -nextOptionLong("any events percentage");
} else if (opt.equals("--pct-pinchzoom")) {
int i = MonkeySourceRandom.FACTOR_PINCHZOOM;
mFactors[i] = -nextOptionLong("pinch zoom events percentage");
} else if (opt.equals("--pkg-blacklist-file")) {
mPkgBlacklistFile = nextOptionData();
} else if (opt.equals("--pkg-whitelist-file")) {
@@ -1246,7 +1249,7 @@ public class Monkey {
usage.append(" [--pct-trackball PERCENT] [--pct-syskeys PERCENT]\n");
usage.append(" [--pct-nav PERCENT] [--pct-majornav PERCENT]\n");
usage.append(" [--pct-appswitch PERCENT] [--pct-flip PERCENT]\n");
usage.append(" [--pct-anyevent PERCENT]\n");
usage.append(" [--pct-anyevent PERCENT] [--pct-pinchzoom PERCENT]\n");
usage.append(" [--pkg-blacklist-file PACKAGE_BLACKLIST_FILE]\n");
usage.append(" [--pkg-whitelist-file PACKAGE_WHITELIST_FILE]\n");
usage.append(" [--wait-dbg] [--dbg-no-events]\n");

View File

@@ -25,7 +25,7 @@ import android.view.IWindowManager;
public abstract class MonkeyEvent {
protected int eventType;
public static final int EVENT_TYPE_KEY = 0;
public static final int EVENT_TYPE_POINTER = 1;
public static final int EVENT_TYPE_TOUCH = 1;
public static final int EVENT_TYPE_TRACKBALL = 2;
public static final int EVENT_TYPE_ACTIVITY = 3;
public static final int EVENT_TYPE_FLIP = 4; // Keyboard flip

View File

@@ -117,11 +117,11 @@ public class MonkeyKeyEvent extends MonkeyEvent {
}
try {
System.out.println(":SendKey (" + note + "): "
System.out.println(":Sending Key (" + note + "): "
+ mKeyCode + " // "
+ MonkeySourceRandom.getKeyName(mKeyCode));
} catch (ArrayIndexOutOfBoundsException e) {
System.out.println(":SendKey (ACTION_UP): "
System.out.println(":Sending Key (" + note + "): "
+ mKeyCode + " // Unknown key event");
}
}

View File

@@ -19,144 +19,184 @@ package com.android.commands.monkey;
import android.app.IActivityManager;
import android.os.RemoteException;
import android.os.SystemClock;
import android.util.SparseArray;
import android.view.IWindowManager;
import android.view.KeyEvent;
import android.view.MotionEvent;
/**
* monkey motion event
*/
public class MonkeyMotionEvent extends MonkeyEvent {
private long mDownTime = -1;
private long mEventTime = -1;
private int mAction = -1;
private float mX = -1;
private float mY = -1;
private float mPressure = -1;
private float mSize = -1;
private int mMetaState = -1;
private float mXPrecision = -1;
private float mYPrecision = -1;
private int mDeviceId = -1;
private int mEdgeFlags = -1;
public abstract class MonkeyMotionEvent extends MonkeyEvent {
private long mDownTime;
private long mEventTime;
private int mAction;
private SparseArray<MotionEvent.PointerCoords> mPointers;
private int mMetaState;
private float mXPrecision;
private float mYPrecision;
private int mDeviceId;
private int mSource;
private int mFlags;
private int mEdgeFlags;
//If true, this is an intermediate step (more verbose logging, only)
private boolean mIntermediateNote;
public MonkeyMotionEvent(int type, long downAt, int action,
float x, float y, int metaState) {
private boolean mIntermediateNote;
protected MonkeyMotionEvent(int type, int source, int action) {
super(type);
mDownTime = downAt;
mSource = source;
mDownTime = -1;
mEventTime = -1;
mAction = action;
mX = x;
mY = y;
mMetaState = metaState;
mPointers = new SparseArray<MotionEvent.PointerCoords>();
mXPrecision = 1;
mYPrecision = 1;
}
public MonkeyMotionEvent(int type, long downTime, long eventTime, int action,
float x, float y, float pressure, float size, int metaState,
float xPrecision, float yPrecision, int deviceId, int edgeFlags) {
super(type);
mDownTime = downTime;
mEventTime = eventTime;
mAction = action;
mX = x;
mY = y;
mPressure = pressure;
mSize = size;
mMetaState = metaState;
mXPrecision = xPrecision;
mYPrecision = yPrecision;
mDeviceId = deviceId;
mEdgeFlags = edgeFlags;
}
public void setIntermediateNote(boolean b) {
public MonkeyMotionEvent addPointer(int id, float x, float y) {
return addPointer(id, x, y, 0, 0);
}
public MonkeyMotionEvent addPointer(int id, float x, float y,
float pressure, float size) {
MotionEvent.PointerCoords c = new MotionEvent.PointerCoords();
c.x = x;
c.y = y;
c.pressure = pressure;
c.size = size;
mPointers.append(id, c);
return this;
}
public MonkeyMotionEvent setIntermediateNote(boolean b) {
mIntermediateNote = b;
return this;
}
public boolean getIntermediateNote() {
return mIntermediateNote;
}
public float getX() {
return mX;
}
public float getY() {
return mY;
}
public int getAction() {
return mAction;
}
public long getDownTime() {
return mDownTime;
}
public long getEventTime() {
return mEventTime;
}
public void setDownTime(long downTime) {
public MonkeyMotionEvent setDownTime(long downTime) {
mDownTime = downTime;
return this;
}
public void setEventTime(long eventTime) {
public MonkeyMotionEvent setEventTime(long eventTime) {
mEventTime = eventTime;
return this;
}
public MonkeyMotionEvent setMetaState(int metaState) {
mMetaState = metaState;
return this;
}
public MonkeyMotionEvent setPrecision(float xPrecision, float yPrecision) {
mXPrecision = xPrecision;
mYPrecision = yPrecision;
return this;
}
public MonkeyMotionEvent setDeviceId(int deviceId) {
mDeviceId = deviceId;
return this;
}
public MonkeyMotionEvent setEdgeFlags(int edgeFlags) {
mEdgeFlags = edgeFlags;
return this;
}
/**
*
* @return instance of a motion event
*/
private MotionEvent getEvent() {
if (mDeviceId < 0) {
return MotionEvent.obtain(mDownTime, SystemClock.uptimeMillis(),
mAction, mX, mY, mMetaState);
int pointerCount = mPointers.size();
int[] pointerIds = new int[pointerCount];
MotionEvent.PointerCoords[] pointerCoords = new MotionEvent.PointerCoords[pointerCount];
for (int i = 0; i < pointerCount; i++) {
pointerIds[i] = mPointers.keyAt(i);
pointerCoords[i] = mPointers.valueAt(i);
}
// for scripts
return MotionEvent.obtain(mDownTime, mEventTime,
mAction, mX, mY, mPressure, mSize, mMetaState,
mXPrecision, mYPrecision, mDeviceId, mEdgeFlags);
MotionEvent ev = MotionEvent.obtain(mDownTime,
mEventTime < 0 ? SystemClock.uptimeMillis() : mEventTime,
mAction, pointerCount, pointerIds, pointerCoords,
mMetaState, mXPrecision, mYPrecision, mDeviceId, mEdgeFlags, mSource, mFlags);
return ev;
}
@Override
public boolean isThrottlable() {
return (getAction() == KeyEvent.ACTION_UP);
return (getAction() == MotionEvent.ACTION_UP);
}
@Override
public int injectEvent(IWindowManager iwm, IActivityManager iam, int verbose) {
String note;
MotionEvent me = getEvent();
if ((verbose > 0 && !mIntermediateNote) || verbose > 1) {
if (mAction == MotionEvent.ACTION_DOWN) {
note = "DOWN";
} else if (mAction == MotionEvent.ACTION_UP) {
note = "UP";
} else {
note = "MOVE";
StringBuilder msg = new StringBuilder(":Sending ");
msg.append(getTypeLabel()).append(" (");
switch (me.getActionMasked()) {
case MotionEvent.ACTION_DOWN:
msg.append("ACTION_DOWN");
break;
case MotionEvent.ACTION_MOVE:
msg.append("ACTION_MOVE");
break;
case MotionEvent.ACTION_UP:
msg.append("ACTION_UP");
break;
case MotionEvent.ACTION_CANCEL:
msg.append("ACTION_CANCEL");
break;
case MotionEvent.ACTION_POINTER_DOWN:
msg.append("ACTION_POINTER_DOWN ").append(me.getPointerId(me.getActionIndex()));
break;
case MotionEvent.ACTION_POINTER_UP:
msg.append("ACTION_POINTER_UP ").append(me.getPointerId(me.getActionIndex()));
break;
default:
msg.append(me.getAction());
break;
}
System.out.println(":Sending Pointer ACTION_" + note +
" x=" + mX + " y=" + mY);
msg.append("):");
int pointerCount = me.getPointerCount();
for (int i = 0; i < pointerCount; i++) {
msg.append(" ").append(me.getPointerId(i));
msg.append(":(").append(me.getX(i)).append(",").append(me.getY(i)).append(")");
}
System.out.println(msg.toString());
}
try {
int type = this.getEventType();
MotionEvent me = getEvent();
if ((type == MonkeyEvent.EVENT_TYPE_POINTER &&
!iwm.injectPointerEvent(me, false))
|| (type == MonkeyEvent.EVENT_TYPE_TRACKBALL &&
!iwm.injectTrackballEvent(me, false))) {
if (!injectMotionEvent(iwm, me)) {
return MonkeyEvent.INJECT_FAIL;
}
} catch (RemoteException ex) {
return MonkeyEvent.INJECT_ERROR_REMOTE_EXCEPTION;
} finally {
me.recycle();
}
return MonkeyEvent.INJECT_SUCCESS;
}
protected abstract String getTypeLabel();
protected abstract boolean injectMotionEvent(IWindowManager iwm, MotionEvent me)
throws RemoteException;
}

View File

@@ -159,8 +159,8 @@ public class MonkeySourceNetwork implements MonkeyEventSource {
return EARG;
}
queue.enqueueEvent(new MonkeyMotionEvent(MonkeyEvent.EVENT_TYPE_POINTER,
-1, action, x, y, 0));
queue.enqueueEvent(new MonkeyTouchEvent(action)
.addPointer(0, x, y));
return OK;
}
return EARG;
@@ -187,8 +187,8 @@ public class MonkeySourceNetwork implements MonkeyEventSource {
Log.e(TAG, "Got something that wasn't a number", e);
return EARG;
}
queue.enqueueEvent(new MonkeyMotionEvent(MonkeyEvent.EVENT_TYPE_TRACKBALL, -1,
MotionEvent.ACTION_MOVE, dx, dy, 0));
queue.enqueueEvent(new MonkeyTrackballEvent(MotionEvent.ACTION_MOVE)
.addPointer(0, dx, dy));
return OK;
}
@@ -341,12 +341,10 @@ public class MonkeySourceNetwork implements MonkeyEventSource {
return EARG;
}
queue.enqueueEvent(new MonkeyMotionEvent(MonkeyEvent.EVENT_TYPE_POINTER,
-1, MotionEvent.ACTION_DOWN,
x, y, 0));
queue.enqueueEvent(new MonkeyMotionEvent(MonkeyEvent.EVENT_TYPE_POINTER,
-1, MotionEvent.ACTION_UP,
x, y, 0));
queue.enqueueEvent(new MonkeyTouchEvent(MotionEvent.ACTION_DOWN)
.addPointer(0, x, y));
queue.enqueueEvent(new MonkeyTouchEvent(MotionEvent.ACTION_UP)
.addPointer(0, x, y));
return OK;
}
return EARG;

View File

@@ -17,6 +17,7 @@
package com.android.commands.monkey;
import android.content.ComponentName;
import android.graphics.PointF;
import android.os.SystemClock;
import android.view.Display;
import android.view.KeyCharacterMap;
@@ -65,15 +66,19 @@ public class MonkeySourceRandom implements MonkeyEventSource {
public static final int FACTOR_TOUCH = 0;
public static final int FACTOR_MOTION = 1;
public static final int FACTOR_TRACKBALL = 2;
public static final int FACTOR_NAV = 3;
public static final int FACTOR_MAJORNAV = 4;
public static final int FACTOR_SYSOPS = 5;
public static final int FACTOR_APPSWITCH = 6;
public static final int FACTOR_FLIP = 7;
public static final int FACTOR_ANYTHING = 8;
public static final int FACTORZ_COUNT = 9; // should be last+1
public static final int FACTOR_PINCHZOOM = 2;
public static final int FACTOR_TRACKBALL = 3;
public static final int FACTOR_NAV = 4;
public static final int FACTOR_MAJORNAV = 5;
public static final int FACTOR_SYSOPS = 6;
public static final int FACTOR_APPSWITCH = 7;
public static final int FACTOR_FLIP = 8;
public static final int FACTOR_ANYTHING = 9;
public static final int FACTORZ_COUNT = 10; // should be last+1
private static final int GESTURE_TAP = 0;
private static final int GESTURE_DRAG = 1;
private static final int GESTURE_PINCH_OR_ZOOM = 2;
/** percentages for each type of event. These will be remapped to working
* values after we read any optional values.
@@ -116,7 +121,8 @@ public class MonkeySourceRandom implements MonkeyEventSource {
mFactors[FACTOR_SYSOPS] = 2.0f;
mFactors[FACTOR_APPSWITCH] = 2.0f;
mFactors[FACTOR_FLIP] = 1.0f;
mFactors[FACTOR_ANYTHING] = 15.0f;
mFactors[FACTOR_ANYTHING] = 13.0f;
mFactors[FACTOR_PINCHZOOM] = 2.0f;
mRandom = random;
mMainApps = MainApps;
@@ -238,46 +244,84 @@ public class MonkeySourceRandom implements MonkeyEventSource {
* generate fling gestures, which are important).
*
* @param random Random number source for positioning
* @param motionEvent If false, touch/release. If true, touch/move/release.
* @param gesture The gesture to perform.
*
*/
private void generateMotionEvent(Random random, boolean motionEvent){
private void generatePointerEvent(Random random, int gesture){
Display display = WindowManagerImpl.getDefault().getDefaultDisplay();
float x = Math.abs(random.nextInt() % display.getWidth());
float y = Math.abs(random.nextInt() % display.getHeight());
long downAt = SystemClock.uptimeMillis();
long eventTime = SystemClock.uptimeMillis();
if (downAt == -1) {
downAt = eventTime;
}
PointF p1 = randomPoint(random, display);
PointF v1 = randomVector(random);
MonkeyMotionEvent e = new MonkeyMotionEvent(MonkeyEvent.EVENT_TYPE_POINTER,
downAt, MotionEvent.ACTION_DOWN, x, y, 0);
e.setIntermediateNote(false);
mQ.addLast(e);
long downAt = SystemClock.uptimeMillis();
mQ.addLast(new MonkeyTouchEvent(MotionEvent.ACTION_DOWN)
.setDownTime(downAt)
.addPointer(0, p1.x, p1.y)
.setIntermediateNote(false));
// sometimes we'll move during the touch
if (motionEvent) {
if (gesture == GESTURE_DRAG) {
int count = random.nextInt(10);
for (int i = 0; i < count; i++) {
// generate some slop in the up event
x = (x + (random.nextInt() % 10)) % display.getWidth();
y = (y + (random.nextInt() % 10)) % display.getHeight();
randomWalk(random, display, p1, v1);
e = new MonkeyMotionEvent(MonkeyEvent.EVENT_TYPE_POINTER,
downAt, MotionEvent.ACTION_MOVE, x, y, 0);
e.setIntermediateNote(true);
mQ.addLast(e);
mQ.addLast(new MonkeyTouchEvent(MotionEvent.ACTION_MOVE)
.setDownTime(downAt)
.addPointer(0, p1.x, p1.y)
.setIntermediateNote(true));
}
} else if (gesture == GESTURE_PINCH_OR_ZOOM) {
PointF p2 = randomPoint(random, display);
PointF v2 = randomVector(random);
randomWalk(random, display, p1, v1);
mQ.addLast(new MonkeyTouchEvent(MotionEvent.ACTION_POINTER_DOWN
| (1 << MotionEvent.ACTION_POINTER_INDEX_SHIFT))
.setDownTime(downAt)
.addPointer(0, p1.x, p1.y).addPointer(1, p2.x, p2.y)
.setIntermediateNote(true));
int count = random.nextInt(10);
for (int i = 0; i < count; i++) {
randomWalk(random, display, p1, v1);
randomWalk(random, display, p2, v2);
mQ.addLast(new MonkeyTouchEvent(MotionEvent.ACTION_MOVE)
.setDownTime(downAt)
.addPointer(0, p1.x, p1.y).addPointer(1, p2.x, p2.y)
.setIntermediateNote(true));
}
randomWalk(random, display, p1, v1);
randomWalk(random, display, p2, v2);
mQ.addLast(new MonkeyTouchEvent(MotionEvent.ACTION_POINTER_UP
| (1 << MotionEvent.ACTION_POINTER_INDEX_SHIFT))
.setDownTime(downAt)
.addPointer(0, p1.x, p1.y).addPointer(1, p2.x, p2.y)
.setIntermediateNote(true));
}
// TODO generate some slop in the up event
e = new MonkeyMotionEvent(MonkeyEvent.EVENT_TYPE_POINTER,
downAt, MotionEvent.ACTION_UP, x, y, 0);
e.setIntermediateNote(false);
mQ.addLast(e);
randomWalk(random, display, p1, v1);
mQ.addLast(new MonkeyTouchEvent(MotionEvent.ACTION_UP)
.setDownTime(downAt)
.addPointer(0, p1.x, p1.y)
.setIntermediateNote(false));
}
private PointF randomPoint(Random random, Display display) {
return new PointF(random.nextInt(display.getWidth()), random.nextInt(display.getHeight()));
}
private PointF randomVector(Random random) {
return new PointF((random.nextFloat() - 0.5f) * 50, (random.nextFloat() - 0.5f) * 50);
}
private void randomWalk(Random random, Display display, PointF point, PointF vector) {
point.x = (float) Math.max(Math.min(point.x + random.nextFloat() * vector.x,
display.getWidth()), 0);
point.y = (float) Math.max(Math.min(point.y + random.nextFloat() * vector.y,
display.getHeight()), 0);
}
/**
@@ -299,34 +343,29 @@ public class MonkeySourceRandom implements MonkeyEventSource {
boolean drop = false;
int count = random.nextInt(10);
MonkeyMotionEvent e;
for (int i = 0; i < 10; ++i) {
// generate a small random step
int dX = random.nextInt(10) - 5;
int dY = random.nextInt(10) - 5;
e = new MonkeyMotionEvent(MonkeyEvent.EVENT_TYPE_TRACKBALL, -1,
MotionEvent.ACTION_MOVE, dX, dY, 0);
e.setIntermediateNote(i > 0);
mQ.addLast(e);
mQ.addLast(new MonkeyTrackballEvent(MotionEvent.ACTION_MOVE)
.addPointer(0, dX, dY)
.setIntermediateNote(i > 0));
}
// 10% of trackball moves end with a click
if (0 == random.nextInt(10)) {
long downAt = SystemClock.uptimeMillis();
mQ.addLast(new MonkeyTrackballEvent(MotionEvent.ACTION_DOWN)
.setDownTime(downAt)
.addPointer(0, 0, 0)
.setIntermediateNote(true));
e = new MonkeyMotionEvent(MonkeyEvent.EVENT_TYPE_TRACKBALL, downAt,
MotionEvent.ACTION_DOWN, 0, 0, 0);
e.setIntermediateNote(true);
mQ.addLast(e);
e = new MonkeyMotionEvent(MonkeyEvent.EVENT_TYPE_TRACKBALL, downAt,
MotionEvent.ACTION_UP, 0, 0, 0);
e.setIntermediateNote(false);
mQ.addLast(e);
mQ.addLast(new MonkeyTrackballEvent(MotionEvent.ACTION_UP)
.setDownTime(downAt)
.addPointer(0, 0, 0)
.setIntermediateNote(false));
}
}
@@ -337,14 +376,16 @@ public class MonkeySourceRandom implements MonkeyEventSource {
float cls = mRandom.nextFloat();
int lastKey = 0;
boolean touchEvent = cls < mFactors[FACTOR_TOUCH];
boolean motionEvent = !touchEvent && (cls < mFactors[FACTOR_MOTION]);
if (touchEvent || motionEvent) {
generateMotionEvent(mRandom, motionEvent);
if (cls < mFactors[FACTOR_TOUCH]) {
generatePointerEvent(mRandom, GESTURE_TAP);
return;
}
if (cls < mFactors[FACTOR_TRACKBALL]) {
} else if (cls < mFactors[FACTOR_MOTION]) {
generatePointerEvent(mRandom, GESTURE_DRAG);
return;
} else if (cls < mFactors[FACTOR_PINCHZOOM]) {
generatePointerEvent(mRandom, GESTURE_PINCH_OR_ZOOM);
return;
} else if (cls < mFactors[FACTOR_TRACKBALL]) {
generateTrackballEvent(mRandom);
return;
}

View File

@@ -19,6 +19,7 @@ package com.android.commands.monkey;
import android.content.ComponentName;
import android.os.SystemClock;
import android.view.KeyEvent;
import android.view.MotionEvent;
import java.io.BufferedReader;
import java.io.DataInputStream;
@@ -267,12 +268,21 @@ public class MonkeySourceScript implements MonkeyEventSource {
float yPrecision = Float.parseFloat(args[9]);
int device = Integer.parseInt(args[10]);
int edgeFlags = Integer.parseInt(args[11]);
int type = MonkeyEvent.EVENT_TYPE_TRACKBALL;
MonkeyMotionEvent e;
if (s.indexOf("Pointer") > 0) {
type = MonkeyEvent.EVENT_TYPE_POINTER;
e = new MonkeyTouchEvent(action);
} else {
e = new MonkeyTrackballEvent(action);
}
MonkeyMotionEvent e = new MonkeyMotionEvent(type, downTime, eventTime, action, x,
y, pressure, size, metaState, xPrecision, yPrecision, device, edgeFlags);
e.setDownTime(downTime)
.setEventTime(eventTime)
.setMetaState(metaState)
.setPrecision(xPrecision, yPrecision)
.setDeviceId(device)
.setEdgeFlags(edgeFlags)
.addPointer(0, x, y, pressure, size);
mQ.addLast(e);
} catch (NumberFormatException e) {
}
@@ -287,23 +297,15 @@ public class MonkeySourceScript implements MonkeyEventSource {
// Set the default parameters
long downTime = SystemClock.uptimeMillis();
float pressure = 1;
float xPrecision = 1;
float yPrecision = 1;
int edgeFlags = 0;
float size = 5;
int device = 0;
int metaState = 0;
int type = MonkeyEvent.EVENT_TYPE_POINTER;
MonkeyMotionEvent e1 =
new MonkeyMotionEvent(type, downTime, downTime, KeyEvent.ACTION_DOWN, x,
y, pressure, size, metaState, xPrecision, yPrecision, device,
edgeFlags);
MonkeyMotionEvent e2 =
new MonkeyMotionEvent(type, downTime, downTime, KeyEvent.ACTION_UP, x,
y, pressure, size, metaState, xPrecision, yPrecision, device,
edgeFlags);
MonkeyMotionEvent e1 = new MonkeyTouchEvent(MotionEvent.ACTION_DOWN)
.setDownTime(downTime)
.setEventTime(downTime)
.addPointer(0, x, y, 1, 5);
MonkeyMotionEvent e2 = new MonkeyTouchEvent(MotionEvent.ACTION_UP)
.setDownTime(downTime)
.setEventTime(downTime)
.addPointer(0, x, y, 1, 5);
mQ.addLast(e1);
mQ.addLast(e2);
@@ -643,7 +645,7 @@ public class MonkeySourceScript implements MonkeyEventSource {
if (ev.getEventType() == MonkeyEvent.EVENT_TYPE_KEY) {
adjustKeyEventTime((MonkeyKeyEvent) ev);
} else if (ev.getEventType() == MonkeyEvent.EVENT_TYPE_POINTER
} else if (ev.getEventType() == MonkeyEvent.EVENT_TYPE_TOUCH
|| ev.getEventType() == MonkeyEvent.EVENT_TYPE_TRACKBALL) {
adjustMotionEventTime((MonkeyMotionEvent) ev);
}

View File

@@ -0,0 +1,43 @@
/*
* Copyright (C) 2010 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.android.commands.monkey;
import android.os.RemoteException;
import android.view.IWindowManager;
import android.view.InputDevice;
import android.view.MotionEvent;
/**
* monkey touch event
*/
public class MonkeyTouchEvent extends MonkeyMotionEvent {
public MonkeyTouchEvent(int action) {
super(MonkeyEvent.EVENT_TYPE_TOUCH, InputDevice.SOURCE_TOUCHSCREEN, action);
}
@Override
protected String getTypeLabel() {
return "Touch";
}
@Override
protected boolean injectMotionEvent(IWindowManager iwm, MotionEvent me)
throws RemoteException {
return iwm.injectPointerEvent(me, false);
}
}

View File

@@ -0,0 +1,43 @@
/*
* Copyright (C) 2010 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.android.commands.monkey;
import android.os.RemoteException;
import android.view.IWindowManager;
import android.view.InputDevice;
import android.view.MotionEvent;
/**
* monkey trackball event
*/
public class MonkeyTrackballEvent extends MonkeyMotionEvent {
public MonkeyTrackballEvent(int action) {
super(MonkeyEvent.EVENT_TYPE_TRACKBALL, InputDevice.SOURCE_TRACKBALL, action);
}
@Override
protected String getTypeLabel() {
return "Trackball";
}
@Override
protected boolean injectMotionEvent(IWindowManager iwm, MotionEvent me)
throws RemoteException {
return iwm.injectTrackballEvent(me, false);
}
}