Home » Android » android – Change screen orientations during monkey run

android – Change screen orientations during monkey run

Posted by: admin June 15, 2020 Leave a comment


I’m using monkey command to do some stress testing on my app. But i want to test it more with respect to screen orientations to detect and capture some heapupdates while changing orientations. I searched all over android official site about monkey commands/arguments which will do screen orientations while running on any app/activity. But no luck and thought of asking professionals like you.

If idea on this, please let me know.

How to&Answers:

Monkey has a number of undocumented options, including --pct-rotation. Add that switch to your command and watch your screen rotate like it’s possessed by demons:

Up to (including) adb version 1.0.31:

adb shell monkey -p com.example.app -v --pct-rotation=70 500

Since adb version 1.0.32:

adb shell monkey -p com.example.app -v --pct-rotation 70 500

Look in the processOptions() method of the monkey command to see all of the supported options: https://android.googlesource.com/platform/development.git/+/master/cmds/monkey/src/com/android/commands/monkey/Monkey.java

Look at the constructor for the MonkeySourceRandom class to see the default percentages for all of the event types. These are the current values in the master branch at the time of this post. Note that the default for rotation is 0:

    // default values for random distributions
    // note, these are straight percentages, to match user input (cmd line args)
    // but they will be converted to 0..1 values before the main loop runs.
    mFactors[FACTOR_TOUCH] = 15.0f;
    mFactors[FACTOR_MOTION] = 10.0f;
    mFactors[FACTOR_TRACKBALL] = 15.0f;
    // Adjust the values if we want to enable rotation by default.
    mFactors[FACTOR_ROTATION] = 0.0f;
    mFactors[FACTOR_NAV] = 25.0f;
    mFactors[FACTOR_MAJORNAV] = 15.0f;
    mFactors[FACTOR_SYSOPS] = 2.0f;
    mFactors[FACTOR_APPSWITCH] = 2.0f;
    mFactors[FACTOR_FLIP] = 1.0f;
    mFactors[FACTOR_ANYTHING] = 13.0f;
    mFactors[FACTOR_PINCHZOOM] = 2.0f;



The Test Monkey uses random input. It will change the screen orientation, but there is no guarantee that it will do so on any given test run.


Although there is no guarantee that Monkey will change orientation during a given run, you can reach your desired outcome by figuring out a SEED that will cause monkey to change orientation and re-using that SEED in future runs.

# monkey -h
usage: monkey [-p ALLOWED_PACKAGE [-p ALLOWED_PACKAGE] ...]
              [-s SEED] [-v [-v] ...]