Merge "Add the new option for the scripted monkey profile testing." into gingerbread
diff --git a/cmds/monkey/src/com/android/commands/monkey/Monkey.java b/cmds/monkey/src/com/android/commands/monkey/Monkey.java
index 4de86cf..511b27c 100644
--- a/cmds/monkey/src/com/android/commands/monkey/Monkey.java
+++ b/cmds/monkey/src/com/android/commands/monkey/Monkey.java
@@ -172,6 +172,9 @@
 
     long mDroppedFlipEvents = 0;
 
+    /** The delay between user actions. This is for the scripted monkey. **/
+    long mProfileWaitTime = 5000;
+
     /** a filename to the setup script (if any) */
     private String mSetupFileName = null;
 
@@ -444,18 +447,18 @@
         if (mScriptFileNames != null && mScriptFileNames.size() == 1) {
             // script mode, ignore other options
             mEventSource = new MonkeySourceScript(mRandom, mScriptFileNames.get(0), mThrottle,
-                    mRandomizeThrottle);
+                    mRandomizeThrottle, mProfileWaitTime);
             mEventSource.setVerbose(mVerbose);
 
             mCountEvents = false;
         } else if (mScriptFileNames != null && mScriptFileNames.size() > 1) {
             if (mSetupFileName != null) {
                 mEventSource = new MonkeySourceRandomScript(mSetupFileName, mScriptFileNames,
-                        mThrottle, mRandomizeThrottle, mRandom);
+                        mThrottle, mRandomizeThrottle, mRandom, mProfileWaitTime);
                 mCount++;
             } else {
                 mEventSource = new MonkeySourceRandomScript(mScriptFileNames, mThrottle,
-                        mRandomizeThrottle, mRandom);
+                        mRandomizeThrottle, mRandom, mProfileWaitTime);
             }
             mEventSource.setVerbose(mVerbose);
             mCountEvents = false;
@@ -638,6 +641,9 @@
                     mSetupFileName = nextOptionData();
                 } else if (opt.equals("-f")) {
                     mScriptFileNames.add(nextOptionData());
+                } else if (opt.equals("--profile-wait")) {
+                    mProfileWaitTime = nextOptionLong("Profile delay" +
+                                " (in milliseconds) to wait between user action");
                 } else if (opt.equals("-h")) {
                     showUsage();
                     return false;
@@ -1108,7 +1114,8 @@
         usage.append("              [--port port]\n");
         usage.append("              [-s SEED] [-v [-v] ...]\n");
         usage.append("              [--throttle MILLISEC] [--randomize-throttle]\n");
-        usage.append("              COUNT");
+        usage.append("              [--profile-wait MILLISEC]\n");
+        usage.append("              COUNT\n");
         System.err.println(usage.toString());
     }
 }
diff --git a/cmds/monkey/src/com/android/commands/monkey/MonkeySourceRandomScript.java b/cmds/monkey/src/com/android/commands/monkey/MonkeySourceRandomScript.java
index fb60c93..81daf01 100644
--- a/cmds/monkey/src/com/android/commands/monkey/MonkeySourceRandomScript.java
+++ b/cmds/monkey/src/com/android/commands/monkey/MonkeySourceRandomScript.java
@@ -48,16 +48,16 @@
      * @param random The random number generator.
      */
     public MonkeySourceRandomScript(String setupFileName, ArrayList<String> scriptFileNames,
-            long throttle, boolean randomizeThrottle, Random random) {
+            long throttle, boolean randomizeThrottle, Random random, long profileWaitTime) {
         if (setupFileName != null) {
             mSetupSource = new MonkeySourceScript(random, setupFileName, throttle,
-                    randomizeThrottle);
+                    randomizeThrottle, profileWaitTime);
             mCurrentSource = mSetupSource;
         }
 
         for (String fileName: scriptFileNames) {
             mScriptSources.add(new MonkeySourceScript(random, fileName, throttle,
-                      randomizeThrottle));
+                      randomizeThrottle, profileWaitTime));
         }
 
         mRandom = random;
@@ -72,8 +72,8 @@
      * @param random The random number generator.
      */
     public MonkeySourceRandomScript(ArrayList<String> scriptFileNames, long throttle,
-            boolean randomizeThrottle, Random random) {
-        this(null, scriptFileNames, throttle, randomizeThrottle, random);
+            boolean randomizeThrottle, Random random, long profileWaitTime) {
+        this(null, scriptFileNames, throttle, randomizeThrottle, random, profileWaitTime);
     }
 
     /**
diff --git a/cmds/monkey/src/com/android/commands/monkey/MonkeySourceScript.java b/cmds/monkey/src/com/android/commands/monkey/MonkeySourceScript.java
index 841182c..8507e7f 100644
--- a/cmds/monkey/src/com/android/commands/monkey/MonkeySourceScript.java
+++ b/cmds/monkey/src/com/android/commands/monkey/MonkeySourceScript.java
@@ -106,6 +106,8 @@
 
     private static final String EVENT_KEYWORD_TAP = "Tap";
 
+    private static final String EVENT_KEYWORD_PROFILE_WAIT = "ProfileWait";
+
     // a line at the end of the header
     private static final String STARTING_DATA_LINE = "start data >>";
 
@@ -113,6 +115,8 @@
 
     private static int LONGPRESS_WAIT_TIME = 2000; // wait time for the long
 
+    private long mProfileWaitTime = 5000; //Wait time for each user profile
+
     FileInputStream mFStream;
 
     DataInputStream mInputStream;
@@ -126,9 +130,10 @@
      * @param throttle The amount of time in ms to sleep between events.
      */
     public MonkeySourceScript(Random random, String filename, long throttle,
-            boolean randomizeThrottle) {
+            boolean randomizeThrottle, long profileWaitTime) {
         mScriptFileName = filename;
         mQ = new MonkeyEventQueue(random, throttle, randomizeThrottle);
+        mProfileWaitTime = profileWaitTime;
     }
 
     /**
@@ -350,6 +355,14 @@
             return;
         }
 
+
+        // Handle the profile wait time
+        if (s.indexOf(EVENT_KEYWORD_PROFILE_WAIT) >= 0) {
+            MonkeyWaitEvent e = new MonkeyWaitEvent(mProfileWaitTime);
+            mQ.addLast(e);
+            return;
+        }
+
         // Handle keypress events
         if (s.indexOf(EVENT_KEYWORD_KEYPRESS) >= 0 && args.length == 1) {
             String key_name = args[0];