Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
monkeydancer.sh
#!/usr/bin/env bash -l
# set -x
echo "Usage: $0 -s $SERIAL < /path/to/script.monkey" 1>&2
echo " More info: https://github.com/android/platform_development/blob/master/cmds/monkey/README.NETWORK.txt" 1>&2
echo " Example: https://github.com/android/platform_development/blob/master/cmds/monkey/example_script.txt" 1>&2
echo "" 1>&2
echo " type 'Hello World'" 1>&2
echo " press KEYCODE_ENTER" 1>&2
echo "" 1>&2
function fail {
echo "$1" 1>&2
exit 1
}
function kill_monkey {
adb "$@" shell "ps|grep com.android.commands.monkey" |cut -d" " -f6|xargs adb "$@" shell kill
}
function onEXIT {
if [[ "$ADB_PID" != "" ]]; then
kill "$ADB_PID"
fi
kill_monkey
}
trap onEXIT EXIT
kill_monkey
adb "$@" forward tcp:7080 tcp:1080 || fail "Unable to forward port"
adb "$@" shell "monkey --port 1080 -vvvvvvv" &
ADB_PID=$!
sleep 2
cat | nc localhost 7080
echo "quit" | nc localhost 7080
sleep 10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment