if (mVerbose >= 2) { // check seeding performance
System.out.println("// Seeded: " + mSeed);
}
- mEventSource = new MonkeySourceRandom(mSeed, mMainApps);
+ mEventSource = new MonkeySourceRandom(mSeed, mMainApps, mThrottle);
mEventSource.setVerbose(mVerbose);
//set any of the factors that has been set
for (int i = 0; i < MonkeySourceRandom.FACTORZ_COUNT; i++) {
}
}
- try {
- Thread.sleep(mThrottle);
- } catch (InterruptedException e1) {
- System.out.println("** Monkey interrupted in sleep.");
- return i;
- }
-
// In this debugging mode, we never send any events. This is primarily
// here so you can manually test the package or category limits, while manually
// exercising the system.
MonkeyEvent ev = mEventSource.getNextEvent();
if (ev != null) {
- i++;
+ // We don't want to count throttling as an event.
+ if (!(ev instanceof MonkeyThrottleEvent)) {
+ i++;
+ }
int injectCode = ev.injectEvent(mWm, mAm, mVerbose);
if (injectCode == MonkeyEvent.INJECT_FAIL) {
if (ev instanceof MonkeyKeyEvent) {
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
+ public static final int EVENT_TYPE_THROTTLE = 5;
public static final int INJECT_SUCCESS = 1;
public static final int INJECT_FAIL = 0;
private LinkedList<MonkeyEvent> mQ = new LinkedList<MonkeyEvent>();
private Random mRandom;
private int mVerbose = 0;
+ private long mThrottle = 0;
private boolean mKeyboardOpen = false;
return KEY_NAMES[keycode];
}
- public MonkeySourceRandom(long seed, ArrayList<ComponentName> MainApps) {
+ public MonkeySourceRandom(long seed, ArrayList<ComponentName> MainApps, long throttle) {
// default values for random distributions
// note, these are straight percentages, to match user input (cmd line args)
// but they will be converted to 0..1 values before the main loop runs.
mRandom = new SecureRandom();
mRandom.setSeed((seed == 0) ? -1 : seed);
mMainApps = MainApps;
+ mThrottle = 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));
+ }
}
--- /dev/null
+/*
+ * Copyright (C) 2009 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.app.IActivityManager;
+import android.os.RemoteException;
+import android.os.SystemClock;
+import android.view.IWindowManager;
+import android.view.MotionEvent;
+
+
+/**
+ * monkey throttle event
+ */
+public class MonkeyThrottleEvent extends MonkeyEvent {
+ private long mThrottle;
+
+ public MonkeyThrottleEvent(int type, long throttle) {
+ super(type);
+ mThrottle = throttle;
+ }
+
+ @Override
+ public int injectEvent(IWindowManager iwm, IActivityManager iam, int verbose) {
+
+ if (verbose > 1) {
+ System.out.println("Sleeping for " + mThrottle + " milliseconds");
+ }
+ try {
+ Thread.sleep(mThrottle);
+ } catch (InterruptedException e1) {
+ System.out.println("** Monkey interrupted in sleep.");
+ return MonkeyEvent.INJECT_FAIL;
+ }
+
+ return MonkeyEvent.INJECT_SUCCESS;
+ }
+}