Strange function in ActivityManager: isUserAMonkey. What does this mean, what is its use?

Android

Android Problem Overview


I found the following function in package android.app.ActivityManager.

public static boolean isUserAMonkey ()

The reference describes:

> public static boolean isUserAMonkey () Since: API Level 8 > > Returns "true" if the user interface is currently being messed with by a monkey.

I was shocked by this strange function. And have a few questions.

  • What does this (user interface is currently being messed with by a monkey) mean?

  • What is the practical use of this function?

  • Why do they use isUserAMonkey for the function name?

Android Solutions


Solution 1 - Android

This method is for checking whether the current user is a test user by some automatic testing, called 'monkey' by Android devs.

Solution 2 - Android

The Monkey is a program that runs on your emulator or device and generates pseudo-random streams of user events such as clicks, touches, or gestures, as well as a number of system-level events. You can use the Monkey to stress-test applications that you are developing, in a random yet repeatable manner.

just refer these links also:

Solution 3 - Android

The story of how this method was created is quite interesting and i couldn't resist sharing it. I think it explains perfectly why such a method is needed.

> "One day i walked into the monkey lab to hear a voice say, '911 -What's > your emergency?" That situation resulted in Dianne adding a new > function to the API, isUserAMonkey() which is used to gate actions > that monkeys shouldn't take during tests (including dialing the phone > and resetting the device). > > Androids: The Team That Built the Android Operating System (Haase, Chet)

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
Questiongtiwari333View Question on Stackoverflow
Solution 1 - AndroidHefferWolfView Answer on Stackoverflow
Solution 2 - AndroidharikrishnanView Answer on Stackoverflow
Solution 3 - AndroidSarantis TofasView Answer on Stackoverflow