From b212eb32a64d435a8b37e002376039c8ea7104e9 Mon Sep 17 00:00:00 2001 From: Liam Mark Date: Fri, 14 Mar 2014 15:47:14 -0700 Subject: Monkey support to sort the app list Add support to sort the apps list. By sorting the app list we can ensure that monkey deterministically launches apps in the same order regardless of what order they were installed on the device. Change-Id: I5a12333f8e13d5d7c2f9a5833ece6a211977fe0f --- cmds/monkey/src/com/android/commands/monkey/Monkey.java | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/cmds/monkey/src/com/android/commands/monkey/Monkey.java b/cmds/monkey/src/com/android/commands/monkey/Monkey.java index dfcb4b02c..4953242af 100644 --- a/cmds/monkey/src/com/android/commands/monkey/Monkey.java +++ b/cmds/monkey/src/com/android/commands/monkey/Monkey.java @@ -49,6 +49,7 @@ import java.io.InputStreamReader; import java.io.Writer; import java.security.SecureRandom; import java.util.ArrayList; +import java.util.Collections; import java.util.HashSet; import java.util.Iterator; import java.util.List; @@ -235,6 +236,9 @@ public class Monkey { /** a filename to the setup script (if any) */ private String mSetupFileName = null; + /** Sort the app list */ + private boolean mSortAppList = false; + /** filenames of the script (if any) */ private ArrayList mScriptFileNames = new ArrayList(); @@ -828,6 +832,8 @@ public class Monkey { mServerPort = (int) nextOptionLong("Server port to listen on for commands"); } else if (opt.equals("--setup")) { mSetupFileName = nextOptionData(); + } else if (opt.equals("--sort-app-list")) { + mSortAppList = true; } else if (opt.equals("-f")) { mScriptFileNames.add(nextOptionData()); } else if (opt.equals("--profile-wait")) { @@ -1038,6 +1044,16 @@ public class Monkey { return false; } + if (mSortAppList) { + Collections.sort(mMainApps); + if (mVerbose >= 2) { // very verbose + System.out.println("// Sorted main activity list"); + for (ComponentName cn : mMainApps) { + System.out.println("// + Using main activity " + cn); + } + } + } + return true; } @@ -1358,6 +1374,7 @@ public class Monkey { usage.append(" [--setup scriptfile] [-f scriptfile [-f scriptfile] ...]\n"); usage.append(" [--port port]\n"); usage.append(" [-s SEED] [-v [-v] ...]\n"); + usage.append(" [--sort-app-list]\n"); usage.append(" [--throttle MILLISEC] [--randomize-throttle]\n"); usage.append(" [--profile-wait MILLISEC]\n"); usage.append(" [--device-sleep-time MILLISEC]\n"); -- cgit v1.2.3