• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

development


Commit MetaInfo

Révision4d88b72e476429b72a9c5aca76f04dccc6fe3301 (tree)
l'heure2009-03-27 03:36:18
AuteurEvan Millar <>
CommiterThe Android Open Source Project

Message de Log

Automated import from //branches/cupcake/...@142951,142951

Change Summary

Modification

--- 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 {
369369 if (mVerbose >= 2) { // check seeding performance
370370 System.out.println("// Seeded: " + mSeed);
371371 }
372- mEventSource = new MonkeySourceRandom(mSeed, mMainApps);
372+ mEventSource = new MonkeySourceRandom(mSeed, mMainApps, mThrottle);
373373 mEventSource.setVerbose(mVerbose);
374374 //set any of the factors that has been set
375375 for (int i = 0; i < MonkeySourceRandom.FACTORZ_COUNT; i++) {
@@ -709,13 +709,6 @@ public class Monkey {
709709 }
710710 }
711711
712- try {
713- Thread.sleep(mThrottle);
714- } catch (InterruptedException e1) {
715- System.out.println("** Monkey interrupted in sleep.");
716- return i;
717- }
718-
719712 // In this debugging mode, we never send any events. This is primarily
720713 // here so you can manually test the package or category limits, while manually
721714 // exercising the system.
@@ -730,7 +723,10 @@ public class Monkey {
730723
731724 MonkeyEvent ev = mEventSource.getNextEvent();
732725 if (ev != null) {
733- i++;
726+ // We don't want to count throttling as an event.
727+ if (!(ev instanceof MonkeyThrottleEvent)) {
728+ i++;
729+ }
734730 int injectCode = ev.injectEvent(mWm, mAm, mVerbose);
735731 if (injectCode == MonkeyEvent.INJECT_FAIL) {
736732 if (ev instanceof MonkeyKeyEvent) {
--- 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 {
2929 public static final int EVENT_TYPE_TRACKBALL = 2;
3030 public static final int EVENT_TYPE_ACTIVITY = 3;
3131 public static final int EVENT_TYPE_FLIP = 4; // Keyboard flip
32+ public static final int EVENT_TYPE_THROTTLE = 5;
3233
3334 public static final int INJECT_SUCCESS = 1;
3435 public static final int INJECT_FAIL = 0;
--- 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{
171171 private LinkedList<MonkeyEvent> mQ = new LinkedList<MonkeyEvent>();
172172 private Random mRandom;
173173 private int mVerbose = 0;
174+ private long mThrottle = 0;
174175
175176 private boolean mKeyboardOpen = false;
176177
@@ -185,7 +186,7 @@ public class MonkeySourceRandom implements MonkeyEventSource{
185186 return KEY_NAMES[keycode];
186187 }
187188
188- public MonkeySourceRandom(long seed, ArrayList<ComponentName> MainApps) {
189+ public MonkeySourceRandom(long seed, ArrayList<ComponentName> MainApps, long throttle) {
189190 // default values for random distributions
190191 // note, these are straight percentages, to match user input (cmd line args)
191192 // but they will be converted to 0..1 values before the main loop runs.
@@ -202,6 +203,7 @@ public class MonkeySourceRandom implements MonkeyEventSource{
202203 mRandom = new SecureRandom();
203204 mRandom.setSeed((seed == 0) ? -1 : seed);
204205 mMainApps = MainApps;
206+ mThrottle = throttle;
205207 }
206208
207209 /**
@@ -334,6 +336,7 @@ public class MonkeySourceRandom implements MonkeyEventSource{
334336 downAt, MotionEvent.ACTION_UP, x, y, 0);
335337 e.setIntermediateNote(false);
336338 mQ.addLast(e);
339+ addThrottle();
337340 }
338341
339342 /**
@@ -384,6 +387,7 @@ public class MonkeySourceRandom implements MonkeyEventSource{
384387 e.setIntermediateNote(false);
385388 mQ.addLast(e);
386389 }
390+ addThrottle();
387391 }
388392
389393 /**
@@ -416,11 +420,13 @@ public class MonkeySourceRandom implements MonkeyEventSource{
416420 MonkeyActivityEvent e = new MonkeyActivityEvent(mMainApps.get(
417421 mRandom.nextInt(mMainApps.size())));
418422 mQ.addLast(e);
423+ addThrottle();
419424 return;
420425 } else if (cls < mFactors[FACTOR_FLIP]) {
421426 MonkeyFlipEvent e = new MonkeyFlipEvent(mKeyboardOpen);
422427 mKeyboardOpen = !mKeyboardOpen;
423428 mQ.addLast(e);
429+ addThrottle();
424430 return;
425431 } else {
426432 lastKey = 1 + mRandom.nextInt(KeyEvent.getMaxKeyCode() - 1);
@@ -431,6 +437,8 @@ public class MonkeySourceRandom implements MonkeyEventSource{
431437
432438 e = new MonkeyKeyEvent(KeyEvent.ACTION_UP, lastKey);
433439 mQ.addLast(e);
440+
441+ addThrottle();
434442 }
435443
436444 public boolean validate() {
@@ -464,4 +472,8 @@ public class MonkeySourceRandom implements MonkeyEventSource{
464472 mQ.removeFirst();
465473 return e;
466474 }
475+
476+ private void addThrottle() {
477+ mQ.addLast(new MonkeyThrottleEvent(MonkeyEvent.EVENT_TYPE_THROTTLE, mThrottle));
478+ }
467479 }
--- /dev/null
+++ b/cmds/monkey/src/com/android/commands/monkey/MonkeyThrottleEvent.java
@@ -0,0 +1,52 @@
1+/*
2+ * Copyright (C) 2009 The Android Open Source Project
3+ *
4+ * Licensed under the Apache License, Version 2.0 (the "License");
5+ * you may not use this file except in compliance with the License.
6+ * You may obtain a copy of the License at
7+ *
8+ * http://www.apache.org/licenses/LICENSE-2.0
9+ *
10+ * Unless required by applicable law or agreed to in writing, software
11+ * distributed under the License is distributed on an "AS IS" BASIS,
12+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+ * See the License for the specific language governing permissions and
14+ * limitations under the License.
15+ */
16+
17+package com.android.commands.monkey;
18+
19+import android.app.IActivityManager;
20+import android.os.RemoteException;
21+import android.os.SystemClock;
22+import android.view.IWindowManager;
23+import android.view.MotionEvent;
24+
25+
26+/**
27+ * monkey throttle event
28+ */
29+public class MonkeyThrottleEvent extends MonkeyEvent {
30+ private long mThrottle;
31+
32+ public MonkeyThrottleEvent(int type, long throttle) {
33+ super(type);
34+ mThrottle = throttle;
35+ }
36+
37+ @Override
38+ public int injectEvent(IWindowManager iwm, IActivityManager iam, int verbose) {
39+
40+ if (verbose > 1) {
41+ System.out.println("Sleeping for " + mThrottle + " milliseconds");
42+ }
43+ try {
44+ Thread.sleep(mThrottle);
45+ } catch (InterruptedException e1) {
46+ System.out.println("** Monkey interrupted in sleep.");
47+ return MonkeyEvent.INJECT_FAIL;
48+ }
49+
50+ return MonkeyEvent.INJECT_SUCCESS;
51+ }
52+}