summaryrefslogtreecommitdiffstats
path: root/cmds
diff options
context:
space:
mode:
authorEvan Millar <>2009-03-27 17:10:47 -0700
committerThe Android Open Source Project <initial-contribution@android.com>2009-03-27 17:10:47 -0700
commit62c4d9bfc5eca4a7bd160e8fb67c0bbc066d9ce8 (patch)
tree6e5691d8c7e57987e01fc9d99794005d32a32056 /cmds
parent745fd9097525faa5f4da9a06550b541b7ca9d469 (diff)
downloadandroid_development-62c4d9bfc5eca4a7bd160e8fb67c0bbc066d9ce8.tar.gz
android_development-62c4d9bfc5eca4a7bd160e8fb67c0bbc066d9ce8.tar.bz2
android_development-62c4d9bfc5eca4a7bd160e8fb67c0bbc066d9ce8.zip
AI 143190: am: CL 142951 Change the way we handle monkey throttling. We now will only sleep after complete down/[move]/up sequences. This avoids unwanted long pressing. We will need to add code to explicitly long press at some point.
Original author: emillar Merged from: //branches/cupcake/... Automated import of CL 143190
Diffstat (limited to 'cmds')
-rw-r--r--cmds/monkey/src/com/android/commands/monkey/Monkey.java14
-rw-r--r--cmds/monkey/src/com/android/commands/monkey/MonkeyEvent.java1
-rw-r--r--cmds/monkey/src/com/android/commands/monkey/MonkeySourceRandom.java14
-rw-r--r--cmds/monkey/src/com/android/commands/monkey/MonkeyThrottleEvent.java52
4 files changed, 71 insertions, 10 deletions
diff --git a/cmds/monkey/src/com/android/commands/monkey/Monkey.java b/cmds/monkey/src/com/android/commands/monkey/Monkey.java
index f6ab19d73..00fb40cb9 100644
--- a/cmds/monkey/src/com/android/commands/monkey/Monkey.java
+++ b/cmds/monkey/src/com/android/commands/monkey/Monkey.java
@@ -369,7 +369,7 @@ public class Monkey {
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++) {
@@ -709,13 +709,6 @@ public class Monkey {
}
}
- 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.
@@ -730,7 +723,10 @@ public class Monkey {
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) {
diff --git a/cmds/monkey/src/com/android/commands/monkey/MonkeyEvent.java b/cmds/monkey/src/com/android/commands/monkey/MonkeyEvent.java
index ff99f5f06..7176073b9 100644
--- a/cmds/monkey/src/com/android/commands/monkey/MonkeyEvent.java
+++ b/cmds/monkey/src/com/android/commands/monkey/MonkeyEvent.java
@@ -29,6 +29,7 @@ public abstract class MonkeyEvent {
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;
diff --git a/cmds/monkey/src/com/android/commands/monkey/MonkeySourceRandom.java b/cmds/monkey/src/com/android/commands/monkey/MonkeySourceRandom.java
index 3dbb575aa..902d8e84c 100644
--- a/cmds/monkey/src/com/android/commands/monkey/MonkeySourceRandom.java
+++ b/cmds/monkey/src/com/android/commands/monkey/MonkeySourceRandom.java
@@ -171,6 +171,7 @@ public class MonkeySourceRandom implements MonkeyEventSource{
private LinkedList<MonkeyEvent> mQ = new LinkedList<MonkeyEvent>();
private Random mRandom;
private int mVerbose = 0;
+ private long mThrottle = 0;
private boolean mKeyboardOpen = false;
@@ -185,7 +186,7 @@ public class MonkeySourceRandom implements MonkeyEventSource{
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.
@@ -202,6 +203,7 @@ public class MonkeySourceRandom implements MonkeyEventSource{
mRandom = new SecureRandom();
mRandom.setSeed((seed == 0) ? -1 : seed);
mMainApps = MainApps;
+ mThrottle = throttle;
}
/**
@@ -334,6 +336,7 @@ public class MonkeySourceRandom implements MonkeyEventSource{
downAt, MotionEvent.ACTION_UP, x, y, 0);
e.setIntermediateNote(false);
mQ.addLast(e);
+ addThrottle();
}
/**
@@ -384,6 +387,7 @@ public class MonkeySourceRandom implements MonkeyEventSource{
e.setIntermediateNote(false);
mQ.addLast(e);
}
+ addThrottle();
}
/**
@@ -416,11 +420,13 @@ public class MonkeySourceRandom implements MonkeyEventSource{
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);
@@ -431,6 +437,8 @@ public class MonkeySourceRandom implements MonkeyEventSource{
e = new MonkeyKeyEvent(KeyEvent.ACTION_UP, lastKey);
mQ.addLast(e);
+
+ addThrottle();
}
public boolean validate() {
@@ -464,4 +472,8 @@ public class MonkeySourceRandom implements MonkeyEventSource{
mQ.removeFirst();
return e;
}
+
+ private void addThrottle() {
+ mQ.addLast(new MonkeyThrottleEvent(MonkeyEvent.EVENT_TYPE_THROTTLE, mThrottle));
+ }
}
diff --git a/cmds/monkey/src/com/android/commands/monkey/MonkeyThrottleEvent.java b/cmds/monkey/src/com/android/commands/monkey/MonkeyThrottleEvent.java
new file mode 100644
index 000000000..3d7d48aa5
--- /dev/null
+++ b/cmds/monkey/src/com/android/commands/monkey/MonkeyThrottleEvent.java
@@ -0,0 +1,52 @@
+/*
+ * 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;
+ }
+}