I have a simple code snippet as below using AVC to perform some sequential actions to a Nexus3 phone.
#! /usr/bin/python
import sys, os, 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
#from com.dtmilano.android.viewclient import ViewClient
adbc=AdbClient(serialno='.*')
print 'taking snapshot...'
adbc.takeSnapshot()
print 'touch 1st time...'
adbc.touch(50,70)
time.sleep(1)
print 'touch 2nd time...'
adbc.touch(50,70)
with the takeSnapshot() code before touch(), the touch() failed with below exception:
touch 1st time...
sending 0015shell:input tap 50 70
shell(cmd=input tap 50 70)
__send(shell:input tap 50 70, checkok=True, reconnect=False)
__checkOk()
checkConnected()
checkConnected: returning True
setAlarm(150)
__checkOk: recv= ''
setAlarm(0)
Traceback (most recent call last):
File "/home/swang/engine/test.py", line 19, in <module>
adbc.touch(50,70)
File "/home/swang/engine/com/dtmilano/android/adb/adbclient.py", line 430, in touch
self.shell('input tap %d %d' % (x, y))
File "/home/swang/engine/com/dtmilano/android/adb/adbclient.py", line 260, in shell
self.__send('shell:%s' % cmd, checkok=True, reconnect=False)
File "/home/swang/engine/com/dtmilano/android/adb/adbclient.py", line 157, in __send
self.__checkOk()
File "/home/swang/engine/com/dtmilano/android/adb/adbclient.py", line 193, in __checkOk
raise RuntimeError("ERROR: %s %s" % (repr(recv), error))
RuntimeError: ERROR: ''
Closing socket... <socket._socketobject object at 0xa9da60>
but if I remove the takeSnapshot(), the following 2 touch() would be successful. I'm using the recent AVC release. Am I overlooking something here?
For historical reasons AdbClient.takeSnapshot()
is defined as
def takeSnapshot(self, reconnect=False):
...
which means that there will be a disconnection after taking the screenshot. So all you have to do in your script is
...
adbc=AdbClient(serialno='.*')
print 'taking snapshot...'
adbc.takeSnapshot(reconnect=True)
print 'touch 1st time...'
adbc.touch(50,70)
time.sleep(1)
print 'touch 2nd time...'
adbc.touch(50,70)
and it will work.