if (mScriptFileName != null) {
// script mode, ignore other options
- mEventSource = new MonkeySourceScript(mScriptFileName);
+ mEventSource = new MonkeySourceScript(mScriptFileName, mThrottle);
mEventSource.setVerbose(mVerbose);
} else {
// random source by default
}
/**
+ * @return true if it is safe to throttle after this event, and false otherwise.
+ */
+ public boolean isThrottlable() {
+ return true;
+ }
+
+
+ /**
* a method for injecting event
* @param iwm wires to current window manager
* @param iam wires to current activity manager
--- /dev/null
+/*
+ * Copyright (C) 2008 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 java.util.LinkedList;
+
+/**
+ * class for keeping a monkey event queue
+ */
+@SuppressWarnings("serial")
+public class MonkeyEventQueue extends LinkedList<MonkeyEvent> {
+
+ private long mThrottle;
+
+ public MonkeyEventQueue(long throttle) {
+ super();
+ mThrottle = throttle;
+ }
+
+ @Override
+ public void addLast(MonkeyEvent e) {
+ super.add(e);
+ if (e.isThrottlable()) {
+ super.add(new MonkeyThrottleEvent(mThrottle));
+ }
+ }
+}
}
@Override
+ public boolean isThrottlable() {
+ return (getAction() == KeyEvent.ACTION_UP);
+ }
+
+ @Override
public int injectEvent(IWindowManager iwm, IActivityManager iam, int verbose) {
if (verbose > 1) {
String note;
import android.os.RemoteException;
import android.os.SystemClock;
import android.view.IWindowManager;
+import android.view.KeyEvent;
import android.view.MotionEvent;
}
@Override
+ public boolean isThrottlable() {
+ return (getAction() == KeyEvent.ACTION_UP);
+ }
+
+ @Override
public int injectEvent(IWindowManager iwm, IActivityManager iam, int verbose) {
String note;
/**
* monkey event queue
*/
-public class MonkeySourceRandom implements MonkeyEventSource{
+public class MonkeySourceRandom implements MonkeyEventSource {
/** Key events that move around the UI. */
private static final int[] NAV_KEYS = {
KeyEvent.KEYCODE_DPAD_UP, KeyEvent.KEYCODE_DPAD_DOWN,
private float[] mFactors = new float[FACTORZ_COUNT];
private ArrayList<ComponentName> mMainApps;
private int mEventCount = 0; //total number of events generated so far
- private LinkedList<MonkeyEvent> mQ = new LinkedList<MonkeyEvent>();
+ private MonkeyEventQueue mQ;
private Random mRandom;
private int mVerbose = 0;
private long mThrottle = 0;
mRandom = new SecureRandom();
mRandom.setSeed((seed == 0) ? -1 : seed);
mMainApps = MainApps;
- mThrottle = throttle;
+ mQ = new MonkeyEventQueue(throttle);
}
/**
downAt, MotionEvent.ACTION_UP, x, y, 0);
e.setIntermediateNote(false);
mQ.addLast(e);
- addThrottle();
}
/**
e.setIntermediateNote(false);
mQ.addLast(e);
}
- addThrottle();
}
/**
MonkeyActivityEvent e = new MonkeyActivityEvent(mMainApps.get(
mRandom.nextInt(mMainApps.size())));
mQ.addLast(e);
- addThrottle();
return;
} else if (cls < mFactors[FACTOR_FLIP]) {
MonkeyFlipEvent e = new MonkeyFlipEvent(mKeyboardOpen);
mKeyboardOpen = !mKeyboardOpen;
mQ.addLast(e);
- addThrottle();
return;
} else {
lastKey = 1 + mRandom.nextInt(KeyEvent.getMaxKeyCode() - 1);
e = new MonkeyKeyEvent(KeyEvent.ACTION_UP, lastKey);
mQ.addLast(e);
-
- addThrottle();
}
public boolean validate() {
mQ.removeFirst();
return e;
}
-
- private void addThrottle() {
- mQ.addLast(new MonkeyThrottleEvent(MonkeyEvent.EVENT_TYPE_THROTTLE, mThrottle));
- }
}
* type= raw events
* count= 10
* speed= 1.0
+ * start data >>
* captureDispatchPointer(5109520,5109520,0,230.75429,458.1814,0.20784314,
* 0.06666667,0,0.0,0.0,65539,0)
* captureDispatchKey(5113146,5113146,0,20,0,0,0,0)
* captureDispatchFlip(true)
* ...
*/
-public class MonkeySourceScript implements MonkeyEventSource{
+public class MonkeySourceScript implements MonkeyEventSource {
private int mEventCountInScript = 0; //total number of events in the file
private int mVerbose = 0;
private double mSpeed = 1.0;
private String mScriptFileName;
- private LinkedList<MonkeyEvent> mQ = new LinkedList<MonkeyEvent>();
+ private MonkeyEventQueue mQ;
private static final String HEADER_TYPE = "type=";
private static final String HEADER_COUNT = "count=";
// a line at the end of the header
private static final String STARTING_DATA_LINE = "start data >>";
private boolean mFileOpened = false;
+
FileInputStream mFStream;
DataInputStream mInputStream;
BufferedReader mBufferReader;
- public MonkeySourceScript(String filename) {
+ public MonkeySourceScript(String filename, long throttle) {
mScriptFileName = filename;
+ mQ = new MonkeyEventQueue(throttle);
}
/**
package com.android.commands.monkey;
+import java.util.List;
+
import android.app.IActivityManager;
-import android.os.RemoteException;
-import android.os.SystemClock;
import android.view.IWindowManager;
-import android.view.MotionEvent;
/**
public class MonkeyThrottleEvent extends MonkeyEvent {
private long mThrottle;
- public MonkeyThrottleEvent(int type, long throttle) {
- super(type);
+ public MonkeyThrottleEvent(long throttle) {
+ super(MonkeyEvent.EVENT_TYPE_THROTTLE);
mThrottle = throttle;
}