1*90c8c64dSAndroid Build Coastguard WorkerSIMPLE PROTOCOL FOR AUTOMATED NETWORK CONTROL 2*90c8c64dSAndroid Build Coastguard Worker 3*90c8c64dSAndroid Build Coastguard WorkerThe Simple Protocol for Automated Network Control was designed to be a 4*90c8c64dSAndroid Build Coastguard Workerlow-level way to programmability inject KeyEvents and MotionEvents 5*90c8c64dSAndroid Build Coastguard Workerinto the input system. The idea is that a process will run on a host 6*90c8c64dSAndroid Build Coastguard Workercomputer that will support higher-level operations (like conditionals, 7*90c8c64dSAndroid Build Coastguard Workeretc.) and will talk (via TCP over ADB) to the device in Simple 8*90c8c64dSAndroid Build Coastguard WorkerProtocol for Automated Network Control. For security reasons, the 9*90c8c64dSAndroid Build Coastguard WorkerMonkey only binds to localhost, so you will need to use adb to setup 10*90c8c64dSAndroid Build Coastguard Workerport forwarding to actually talk to the device. 11*90c8c64dSAndroid Build Coastguard Worker 12*90c8c64dSAndroid Build Coastguard WorkerINITIAL SETUP 13*90c8c64dSAndroid Build Coastguard Worker 14*90c8c64dSAndroid Build Coastguard WorkerSetup port forwarding from a local port on your machine to a port on 15*90c8c64dSAndroid Build Coastguard Workerthe device: 16*90c8c64dSAndroid Build Coastguard Worker 17*90c8c64dSAndroid Build Coastguard Worker$ adb forward tcp:1080 tcp:1080 18*90c8c64dSAndroid Build Coastguard Worker 19*90c8c64dSAndroid Build Coastguard WorkerStart the monkey server 20*90c8c64dSAndroid Build Coastguard Worker 21*90c8c64dSAndroid Build Coastguard Worker$ adb shell monkey --port 1080 22*90c8c64dSAndroid Build Coastguard Worker 23*90c8c64dSAndroid Build Coastguard WorkerNow you're ready to run commands 24*90c8c64dSAndroid Build Coastguard Worker 25*90c8c64dSAndroid Build Coastguard WorkerCOMMAND LIST 26*90c8c64dSAndroid Build Coastguard Worker 27*90c8c64dSAndroid Build Coastguard WorkerIndividual commands are separated by newlines. The Monkey will 28*90c8c64dSAndroid Build Coastguard Workerrespond to every command with a line starting with OK for commands 29*90c8c64dSAndroid Build Coastguard Workerthat executed without a problem, or a line starting with ERROR for 30*90c8c64dSAndroid Build Coastguard Workercommands that had problems being run. For commands that return a 31*90c8c64dSAndroid Build Coastguard Workervalue, that value is returned on the same line as the OK or ERROR 32*90c8c64dSAndroid Build Coastguard Workerresponse. The value is everything after (but not include) the colon 33*90c8c64dSAndroid Build Coastguard Workeron that line. For ERROR values, this could be a message indicating 34*90c8c64dSAndroid Build Coastguard Workerwhat happened. A possible example: 35*90c8c64dSAndroid Build Coastguard Worker 36*90c8c64dSAndroid Build Coastguard Workerkey down menu 37*90c8c64dSAndroid Build Coastguard WorkerOK 38*90c8c64dSAndroid Build Coastguard Workertouch monkey 39*90c8c64dSAndroid Build Coastguard WorkerERROR: monkey not a number 40*90c8c64dSAndroid Build Coastguard Workergetvar sdk 41*90c8c64dSAndroid Build Coastguard WorkerOK: donut 42*90c8c64dSAndroid Build Coastguard Workergetvar foo 43*90c8c64dSAndroid Build Coastguard WorkerERROR: no such var 44*90c8c64dSAndroid Build Coastguard Worker 45*90c8c64dSAndroid Build Coastguard WorkerThe complete list of commands follows: 46*90c8c64dSAndroid Build Coastguard Worker 47*90c8c64dSAndroid Build Coastguard Workerkey [down|up] keycode 48*90c8c64dSAndroid Build Coastguard Worker 49*90c8c64dSAndroid Build Coastguard WorkerThis command injects KeyEvent's into the input system. The keycode 50*90c8c64dSAndroid Build Coastguard Workerparameter refers to the KEYCODE list in the KeyEvent class 51*90c8c64dSAndroid Build Coastguard Worker(http://developer.android.com/reference/android/view/KeyEvent.html). 52*90c8c64dSAndroid Build Coastguard WorkerThe format of that parameter is quite flexible. Using the menu key as 53*90c8c64dSAndroid Build Coastguard Workeran example, it can be 82 (the integer value of the keycode), 54*90c8c64dSAndroid Build Coastguard WorkerKEYCODE_MENU (the name of the keycode), or just menu (and the Monkey 55*90c8c64dSAndroid Build Coastguard Workerwill add the KEYCODE part). Do note that this last part doesn't work 56*90c8c64dSAndroid Build Coastguard Workerfor things like KEYCODE_1 for obvious reasons. 57*90c8c64dSAndroid Build Coastguard Worker 58*90c8c64dSAndroid Build Coastguard WorkerNote that sending a full button press requires sending both the down 59*90c8c64dSAndroid Build Coastguard Workerand the up event for that key 60*90c8c64dSAndroid Build Coastguard Worker 61*90c8c64dSAndroid Build Coastguard Workertouch [down|up|move] x y 62*90c8c64dSAndroid Build Coastguard Worker 63*90c8c64dSAndroid Build Coastguard WorkerThis command injects a MotionEvent into the input system that 64*90c8c64dSAndroid Build Coastguard Workersimulates a user touching the touchscreen (or a pointer event). x and 65*90c8c64dSAndroid Build Coastguard Workery specify coordinates on the display (0 0 being the upper left) for 66*90c8c64dSAndroid Build Coastguard Workerthe touch event to happen. Just like key events, touch events at a 67*90c8c64dSAndroid Build Coastguard Workersingle location require both a down and an up. To simulate dragging, 68*90c8c64dSAndroid Build Coastguard Workersend a "touch down", then a series of "touch move" events (to simulate 69*90c8c64dSAndroid Build Coastguard Workerthe drag), followed by a "touch up" at the final location. 70*90c8c64dSAndroid Build Coastguard Worker 71*90c8c64dSAndroid Build Coastguard Workertrackball dx dy 72*90c8c64dSAndroid Build Coastguard Worker 73*90c8c64dSAndroid Build Coastguard WorkerThis command injects a MotionEvent into the input system that 74*90c8c64dSAndroid Build Coastguard Workersimulates a user using the trackball. dx and dy indicates the amount 75*90c8c64dSAndroid Build Coastguard Workerof change in the trackball location (as opposed to exact coordinates 76*90c8c64dSAndroid Build Coastguard Workerthat the touch events use) 77*90c8c64dSAndroid Build Coastguard Worker 78*90c8c64dSAndroid Build Coastguard Workerflip [open|close] 79*90c8c64dSAndroid Build Coastguard Worker 80*90c8c64dSAndroid Build Coastguard WorkerThis simulates the opening or closing the keyboard (like on dream). 81*90c8c64dSAndroid Build Coastguard Worker 82*90c8c64dSAndroid Build Coastguard Workerwake 83*90c8c64dSAndroid Build Coastguard Worker 84*90c8c64dSAndroid Build Coastguard WorkerThis command will wake the device up from sleep and allow user input. 85*90c8c64dSAndroid Build Coastguard Worker 86*90c8c64dSAndroid Build Coastguard Workertap x y 87*90c8c64dSAndroid Build Coastguard WorkerThe tap command is a shortcut for the touch command. It will 88*90c8c64dSAndroid Build Coastguard Workerautomatically send both the up and the down event. 89*90c8c64dSAndroid Build Coastguard Worker 90*90c8c64dSAndroid Build Coastguard Workerpress keycode 91*90c8c64dSAndroid Build Coastguard Worker 92*90c8c64dSAndroid Build Coastguard WorkerThe press command is a shortcut for the key command. The keycode 93*90c8c64dSAndroid Build Coastguard Workerparamter works just like the key command and will automatically send 94*90c8c64dSAndroid Build Coastguard Workerboth the up and the down event. 95*90c8c64dSAndroid Build Coastguard Worker 96*90c8c64dSAndroid Build Coastguard Workertype string 97*90c8c64dSAndroid Build Coastguard Worker 98*90c8c64dSAndroid Build Coastguard WorkerThis command will simulate a user typing the given string on the 99*90c8c64dSAndroid Build Coastguard Workerkeyboard by generating the proper KeyEvents. 100*90c8c64dSAndroid Build Coastguard Worker 101*90c8c64dSAndroid Build Coastguard Workerlistvar 102*90c8c64dSAndroid Build Coastguard Worker 103*90c8c64dSAndroid Build Coastguard WorkerThis command lists all the vars that the monkey knows about. They are 104*90c8c64dSAndroid Build Coastguard Workerreturned as a whitespace separated list. 105*90c8c64dSAndroid Build Coastguard Worker 106*90c8c64dSAndroid Build Coastguard Workergetvar varname 107*90c8c64dSAndroid Build Coastguard Worker 108*90c8c64dSAndroid Build Coastguard WorkerThis command returns the value of the given var. listvar can be used 109*90c8c64dSAndroid Build Coastguard Workerto find out what vars are supported. 110*90c8c64dSAndroid Build Coastguard Worker 111*90c8c64dSAndroid Build Coastguard Workerquit 112*90c8c64dSAndroid Build Coastguard Worker 113*90c8c64dSAndroid Build Coastguard WorkerFully quit the monkey and accept no new sessions. 114*90c8c64dSAndroid Build Coastguard Worker 115*90c8c64dSAndroid Build Coastguard Workerdone 116*90c8c64dSAndroid Build Coastguard Worker 117*90c8c64dSAndroid Build Coastguard WorkerClose the current session and allow a new session to connect 118*90c8c64dSAndroid Build Coastguard Worker 119*90c8c64dSAndroid Build Coastguard WorkerOTHER NOTES 120*90c8c64dSAndroid Build Coastguard Worker 121*90c8c64dSAndroid Build Coastguard WorkerThere are some convenience features added to allow running without 122*90c8c64dSAndroid Build Coastguard Workerneeding a host process. 123*90c8c64dSAndroid Build Coastguard Worker 124*90c8c64dSAndroid Build Coastguard WorkerLines starting with a # character are considered comments. The Monkey 125*90c8c64dSAndroid Build Coastguard Workereats them and returns no indication that it did anything (no ERROR and 126*90c8c64dSAndroid Build Coastguard Workerno OK). 127*90c8c64dSAndroid Build Coastguard Worker 128*90c8c64dSAndroid Build Coastguard WorkerYou can put the Monkey to sleep by using the "sleep" command with a 129*90c8c64dSAndroid Build Coastguard Workersingle argument, how many ms to sleep. 130