15

Looking through the Android apis I found a method call isUserAMonkey(), says it returns true if the phone is being messed with by a monkey.

Is this a joke, or what is it used for?

Gallal
  • 4,267
  • 6
  • 38
  • 61
MattoTodd
  • 14,467
  • 16
  • 59
  • 76
  • 6
    My customer tests the app for crashes like a professional musican. He drums on the phone/tablet with 10 fingers... thats like a monkey... – WarrenFaith Sep 25 '11 at 15:17

1 Answers1

15

Look at monkeyrunner, it will give you the answer.

Quote from the document:

The monkeyrunner tool provides an API for writing programs that control an Android device or emulator from outside of Android code. With monkeyrunner, you can write a Python program that installs an Android application or test package, runs it, sends keystrokes to it, takes screenshots of its user interface, and stores screenshots on the workstation. The monkeyrunner tool is primarily designed to test applications and devices at the functional/framework level and for running unit test suites, but you are free to use it for other purposes.

So if you are running a package using Monkeyrunner, then this function will return true.

theisenp
  • 8,639
  • 5
  • 39
  • 47
Gallal
  • 4,267
  • 6
  • 38
  • 61
  • 10
    To elaborate, since the monkey testing tool can potentially cause a lot of mischief, if you use it to test your app it is good practice to make sure that you protect operations within your app with a call to `isUserAMonkey` and ignore the operation if it returns true. Otherwise you might have monkeys sending email, posting random gibberish to the internet, triggering operations that cost money, etc. – adamp Sep 25 '11 at 17:30
  • 4
    @adamp - i don't like those monkeys – MattoTodd Sep 25 '11 at 22:41
  • 5
    I believe MonkeyRunner mentioning is wrong here. isUserMonkey() checks whether monkey tool is running (not a monkeyrunner). MonkeyRunner is a framework to write UI automation tests. Monkey tool is a tool to generate random events. – Victor Ronin Nov 15 '12 at 22:51