Last active
September 23, 2019 03:46
-
-
Save Grohden/9b75907b9a30377d7f518059b9b3b6d2 to your computer and use it in GitHub Desktop.
After reading the android monkey sources, i came up with this: a way to make a monkey runner "script" by hand
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Let's suppose you have this in adb: | |
const adbCommands = `input tap 450 450 | |
input tap 740 280 | |
input tap 683 614 | |
input tap 950 411 | |
input tap 1188 248 | |
input tap 915 713 | |
input tap 1176 560 | |
input tap 1428 358 | |
input tap 1149 789 | |
input tap 1444 695 | |
input tap 1707 556` | |
// The do a tap at XY | |
// you can convert them to a monkey script using this: | |
const splitAdbCommands = adbCommands.split('\n') | |
const monkeyInputs = splitAdbCommands | |
.map(it => it.replace('input tap', '').trim().split(' ')) | |
.map(([x, y]) => [ | |
// what is changed here is the action (0 and 1) and the x and y coordinates | |
`DispatchPointer(6934862,6934862,0,${x}.0,${y}.0,0.0,0.0,0,1.0,1.0,0,0)`, | |
`DispatchPointer(6934862,6934862,1,${x}.0,${y}.0,0.0,0.0,0,1.0,1.0,0,0)` | |
].join('\n') | |
).join('\n') | |
// Give a look at the original source to understand better: | |
// https://android.googlesource.com/platform/development.git/+/master/cmds/monkey/src/com/android/commands/monkey/MonkeySourceScript.java#307 | |
// The final monkey script should have a header also: | |
const script = ` | |
type= raw events | |
count= ${splitAdbCommands.length * 2} | |
speed= 1.0 | |
start data >> | |
${monkeyInputs} | |
` | |
// with the script output on a monkey.script file, you can run | |
// adb push monkey.script sdcard | |
// adb shell monkey -f sdcard/monkey.script | |
// Btw i recommend using the following: | |
/* | |
adb shell monkey \ | |
-p <package-name> \ | |
-c android.intent.category.DEFAULT \ #or any that applies here | |
-f sdcard/monkey.script \ | |
--throttle 45 \ | |
COUNT | |
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type= raw events | |
count= 11 | |
speed= 1.0 | |
start data >> | |
DispatchPointer(6934862,6934862,0,450.0,450.0,0.0,0.0,0,1.0,1.0,0,0) | |
DispatchPointer(6934862,6934862,1,450.0,450.0,0.0,0.0,0,1.0,1.0,0,0) | |
DispatchPointer(6934862,6934862,0,740.0,280.0,0.0,0.0,0,1.0,1.0,0,0) | |
DispatchPointer(6934862,6934862,1,740.0,280.0,0.0,0.0,0,1.0,1.0,0,0) | |
DispatchPointer(6934862,6934862,0,683.0,614.0,0.0,0.0,0,1.0,1.0,0,0) | |
DispatchPointer(6934862,6934862,1,683.0,614.0,0.0,0.0,0,1.0,1.0,0,0) | |
DispatchPointer(6934862,6934862,0,950.0,411.0,0.0,0.0,0,1.0,1.0,0,0) | |
DispatchPointer(6934862,6934862,1,950.0,411.0,0.0,0.0,0,1.0,1.0,0,0) | |
DispatchPointer(6934862,6934862,0,1188.0,248.0,0.0,0.0,0,1.0,1.0,0,0) | |
DispatchPointer(6934862,6934862,1,1188.0,248.0,0.0,0.0,0,1.0,1.0,0,0) | |
DispatchPointer(6934862,6934862,0,915.0,713.0,0.0,0.0,0,1.0,1.0,0,0) | |
DispatchPointer(6934862,6934862,1,915.0,713.0,0.0,0.0,0,1.0,1.0,0,0) | |
DispatchPointer(6934862,6934862,0,1176.0,560.0,0.0,0.0,0,1.0,1.0,0,0) | |
DispatchPointer(6934862,6934862,1,1176.0,560.0,0.0,0.0,0,1.0,1.0,0,0) | |
DispatchPointer(6934862,6934862,0,1428.0,358.0,0.0,0.0,0,1.0,1.0,0,0) | |
DispatchPointer(6934862,6934862,1,1428.0,358.0,0.0,0.0,0,1.0,1.0,0,0) | |
DispatchPointer(6934862,6934862,0,1149.0,789.0,0.0,0.0,0,1.0,1.0,0,0) | |
DispatchPointer(6934862,6934862,1,1149.0,789.0,0.0,0.0,0,1.0,1.0,0,0) | |
DispatchPointer(6934862,6934862,0,1444.0,695.0,0.0,0.0,0,1.0,1.0,0,0) | |
DispatchPointer(6934862,6934862,1,1444.0,695.0,0.0,0.0,0,1.0,1.0,0,0) | |
DispatchPointer(6934862,6934862,0,1707.0,556.0,0.0,0.0,0,1.0,1.0,0,0) | |
DispatchPointer(6934862,6934862,1,1707.0,556.0,0.0,0.0,0,1.0,1.0,0,0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment