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

ⅰ亾dé卋堺 提交于 2020-01-06 20:38:13

问题


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.


回答1:


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




回答2:


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 Dalvikto 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).



来源:https://stackoverflow.com/questions/23963237/delay-between-type-commands-in-adbclient-which-doesnt-exist-in-monkeyrunner

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!