Hi,
I encounter a annoied issue when using "adb shell monkey" to test
stability of my hardward. Monkey enters setting-->usb setting to
change "engineering mode (ADB)" to "mass storage mode" randomly. After
that, my desktop loses control of device. Unfortunately, there is no
interface in monkey to filter out a specific activity, so I add it
myself. The new "-x" option is used to indicate which component
(package/class) shall be filtered out. Below is the patch. Now, I want
to know if it's a correct way to resolve such issue?

Thx.

diff --git a/cmds/monkey/src/com/android/commands/monkey/Monkey.java
b/cmds/monkey/src/com/android/commands/monkey/Monkey.java
index 00fb40c..e36ded8 100644
--- a/cmds/monkey/src/com/android/commands/monkey/Monkey.java
+++ b/cmds/monkey/src/com/android/commands/monkey/Monkey.java
@@ -102,6 +102,8 @@ public class Monkey {

     /** Packages we are allowed to run, or empty if no restriction. */
     private HashSet<String> mValidPackages = new HashSet<String>();
+    /** Packages we are forbidden to run, or empty if no restriction. */
+    private HashSet<String> mExcludeComponent = new HashSet<String>();
     /** Categories we are allowed to launch **/
     ArrayList<String> mMainCategories = new ArrayList<String>();
     /** Applications we can switch to. */
@@ -136,7 +138,8 @@ public class Monkey {
      */
     private class ActivityWatcher extends IActivityWatcher.Stub {
         public boolean activityStarting(Intent intent, String pkg) {
-            boolean allow = checkEnteringPackage(pkg) ||
(DEBUG_ALLOW_ANY_STARTS != 0);
+            boolean allow = (checkEnteringIntent(intent) &&
+                    checkEnteringPackage(pkg)) ||
(DEBUG_ALLOW_ANY_STARTS != 0);
             if (mVerbose > 0) {
                 System.out.println("    // " + (allow ? "Allowing" :
"Rejecting")
                         + " start of " + intent + " in package " + pkg);
@@ -167,6 +170,20 @@ public class Monkey {
                 return mValidPackages.contains(pkg);
             }
         }
+
+        private boolean checkEnteringIntent(Intent intent) {
+            if (intent == null) {
+                return true;
+            }
+            System.out.println("checkEnteringIntent, Intent: " +
+                     intent.getComponent().flattenToString());
+            // preflight the hash lookup to avoid the cost of hash
key generation
+            if (mExcludeComponent.size() == 0)  {
+                return true;
+            } else  {
+                return
!mExcludeComponent.contains(intent.getComponent().flattenToString());
+            }
+        }

         public boolean appCrashed(String processName, int pid, String shortMsg,
                 String longMsg, byte[] crashData) {
@@ -474,6 +491,8 @@ public class Monkey {
                     mSeed = nextOptionLong("Seed");
                 } else if (opt.equals("-p")) {
                     mValidPackages.add(nextOptionData());
+                } else if (opt.equals("-x")) {
+                    mExcludeComponent.add(nextOptionData());
                 } else if (opt.equals("-c")) {
                     mMainCategories.add(nextOptionData());
                 } else if (opt.equals("-v")) {
@@ -886,6 +905,7 @@ public class Monkey {
      */
     private void showUsage() {
       System.err.println("usage: monkey [-p ALLOWED_PACKAGE [-p
ALLOWED_PACKAGE] ...]");
+      System.err.println("              [-x EXCLUDE_COMPONENT [-x
EXCLUDE_COMPONENT] ...]");
       System.err.println("              [-c MAIN_CATEGORY [-c
MAIN_CATEGORY] ...]");
       System.err.println("              [--ignore-crashes]
[--ignore-timeouts]");
       System.err.println("
[--ignore-security-exceptions] [--monitor-native-crashes]");

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"android-framework" group.
To post to this group, send email to android-framework@googlegroups.com
To unsubscribe from this group, send email to 
android-framework+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/android-framework?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to