OSDN Git Service

Prevent monkey from turning off the screen. (DO NOT MERGE)
authorJeff Brown <jeffbrown@google.com>
Thu, 20 Jan 2011 03:38:03 +0000 (19:38 -0800)
committerJeff Brown <jeffbrown@google.com>
Fri, 21 Jan 2011 01:54:53 +0000 (17:54 -0800)
Bug: 3371251
Change-Id: I33005005fadc0f994f39fded10faafe21116f82a

cmds/monkey/src/com/android/commands/monkey/MonkeySourceRandom.java

index f1edae1..3d7834c 100644 (file)
@@ -479,7 +479,7 @@ public class MonkeySourceRandom implements MonkeyEventSource {
         }
 
         // The remaining event categories are injected as key events
-        do {
+        for (;;) {
             if (cls < mFactors[FACTOR_NAV]) {
                 lastKey = NAV_KEYS[mRandom.nextInt(NAV_KEYS.length)];
             } else if (cls < mFactors[FACTOR_MAJORNAV]) {
@@ -499,7 +499,13 @@ public class MonkeySourceRandom implements MonkeyEventSource {
             } else {
                 lastKey = 1 + mRandom.nextInt(KeyEvent.getMaxKeyCode() - 1);
             }
-        } while (!PHYSICAL_KEY_EXISTS[lastKey]);
+
+            if (lastKey != KeyEvent.KEYCODE_POWER
+                    && lastKey != KeyEvent.KEYCODE_ENDCALL
+                    && PHYSICAL_KEY_EXISTS[lastKey]) {
+                break;
+            }
+        }
 
         MonkeyKeyEvent e = new MonkeyKeyEvent(KeyEvent.ACTION_DOWN, lastKey);
         mQ.addLast(e);