I am making a switch from monkeyrunner to AndroidViewClient. It is nice because it is all Python. However, when issuing type or press commands, the lag between each command is like one second:
import sys
import os
import time
try:
sys.path.append(os.path.join(os.environ['ANDROID_VIEW_CLIENT_HOME'], 'src'))
except:
pass
from com.dtmilano.android.adb.adbclient import AdbClient, Device
device.type("hello")
# type a space
device.press('KEYCODE_SPACE', 'DOWN_AND_UP')
device.type("world")
The above code in monkeyrunner has literally no delay between "press" and "type." Why is AdbClient producing this delay? Isn't it going through the adb shell? It should be fast...
Note: the typing of "hello" and "world" IS fast. It is just there is a 1 second delay between each type command.
The reason for some delay between command is that adbclient
uses mostly a shell
connection to send them. This shell connection is not kept open. monkeyrunner
uses a socket to send commands to monkey
and thus why the delay between command is minimum.
adbclient
could re-use an open shell
connection or open a socket
to monkey
to do as monkeyrunner
.
This is not difficult to implement, but not in the roadmap yet. Anyway, patches are always welcome.
On the other hand, for other most common cases adbclient
is sevral times faster: http://dtmilano.blogspot.ca/2013/09/androidviewclientculebra-takesnapshot.html
Diego is wrong in his root cause analysis. The new shell connection is not that expensive. What takes the most time is starting a new java process - since device.type()
is executing adb shell input text
and input
is a console java app.
Monkeyrunner is faster because its device side java process starts only once. So unfortunately the persistent shell connection is not going to help you that much.
Also I have tried switching java runtime from Dalvik
to ART
hoping that it would help with java app start up times. It did cut it down about 20% (from 0.82s to 0.65s on the unit I tried it on).