4

When doing a Monkey test on android device, I send

adb shell monkey --ignore-security-exceptions --ignore-crashes --ignore-timeouts --ignore-native-crashes --throttle 200 -s 222 -v -v -v 125000 > c:\all_monkey.txt

then Monkey will send a lot of random event to device, I can see a lot of swipe screen or click button. Will Monkey occasionally enter settings and click the restart button to restart device? Because I found when running for a while, device will restart itself. Can I avoid Monkey test click restart button by itself. thanks.

jiajia guo
  • 332
  • 2
  • 3
  • 16

2 Answers2

2

Yes, you can wrap your restart function with this check from ActivityManager:

if(!ActivityManager.isUserAMonkey()){
//your code
}

isUserAMonkey ():

Returns "true" if the user interface is currently being messed with by a monkey.

Edit: since I misinterpreted the question the first time, here some maybe useful answers from so:

-p flag

adb shell monkey -p your.application.id.here //to restrict mokey to your application

--pct-syskeys

By setting the -pct-sysevents to zero. However the catch here is the order of events. - kopos

Community
  • 1
  • 1
yennsarah
  • 5,467
  • 2
  • 27
  • 48
  • Restart button isn't in your app so that using this code, you can identify the monkey. – frogatto Nov 13 '15 at 10:18
  • Ah.. then I misinterpreted the question. ^^' But maybe this [SO question](http://stackoverflow.com/questions/20911714/disable-system-level-events-on-android-monkey) will help op. I just find the function name funny, so this was my first thought. :) – yennsarah Nov 13 '15 at 10:21
1

You can simply tell the Monkey () to mess up a particular app specified by a package name. (For example allow the Monkey to only mess up your app!)

For this, add -p <allowed-package-name> to your command.

Docs say:

If you specify one or more packages this way, the Monkey will only allow the system to visit activities within those packages. If your application requires access to activities in other packages (e.g. to select a contact) you'll need to specify those packages as well. If you don't specify any packages, the Monkey will allow the system to launch activities in all packages. To specify multiple packages, use the -p option multiple times — one -p option per package.

frogatto
  • 28,539
  • 11
  • 83
  • 129