Search code examples
androidpythonmonkeyrunnerandroidviewclient

Delay between "type" commands in AdbClient (which doesn't exist in monkeyrunner)


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.


Solution

  • 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