1717@author: diego
1818'''
1919
20- __version__ = '2.3.6 '
20+ __version__ = '2.3.7 '
2121
2222import sys
2323import subprocess
3333from com .android .monkeyrunner import MonkeyDevice , MonkeyRunner
3434
3535DEBUG = False
36- DEBUG_DEVICE = DEBUG and True
37- DEBUG_RECEIVED = DEBUG and False
36+ DEBUG_DEVICE = DEBUG and False
37+ DEBUG_RECEIVED = DEBUG and True
3838DEBUG_TREE = DEBUG and False
3939DEBUG_GETATTR = DEBUG and False
40- DEBUG_COORDS = DEBUG and True
40+ DEBUG_COORDS = DEBUG and False
4141DEBUG_TOUCH = DEBUG and False
4242DEBUG_STATUSBAR = DEBUG and False
4343DEBUG_WINDOWS = DEBUG and False
@@ -927,8 +927,10 @@ def __init__(self, device, serialno, adb=None, autodump=True, forceviewserveruse
927927 if self .useUiAutomator :
928928 self .textProperty = TEXT_PROPERTY_UI_AUTOMATOR
929929 else :
930- # FIXME: not true for API <= 10
931- self .textProperty = TEXT_PROPERTY
930+ if self .build [VERSION_SDK_PROPERTY ] <= 10 :
931+ self .textProperty = TEXT_PROPERTY_API_10
932+ else :
933+ self .textProperty = TEXT_PROPERTY
932934 if startviewserver :
933935 if not self .serviceResponse (device .shell ('service call window 3' )):
934936 try :
@@ -1296,7 +1298,7 @@ def __splitAttrs(self, strArgs, addViewToViewsById=False):
12961298 raise RuntimeError ("This method is not compatible with UIAutomator" )
12971299 # replace the spaces in text:mText to preserve them in later split
12981300 # they are translated back after the attribute matches
1299- textRE = re .compile ('%s=%s,' % (TEXT_PROPERTY , __nd ('len' )))
1301+ textRE = re .compile ('%s=%s,' % (self . textProperty , __nd ('len' )))
13001302 m = textRE .search (strArgs )
13011303 if m :
13021304 __textStart = m .end ()
@@ -1316,7 +1318,7 @@ def __splitAttrs(self, strArgs, addViewToViewsById=False):
13161318 if m :
13171319 viewId = m .group ('viewId' )
13181320 if DEBUG :
1319- print >> sys .stderr , "found %s" % viewId
1321+ print >> sys .stderr , "found view with id= %s" % viewId
13201322
13211323 for attr in strArgs .split ():
13221324 m = attrRE .match (attr )
@@ -1327,7 +1329,7 @@ def __splitAttrs(self, strArgs, addViewToViewsById=False):
13271329 __val = m .group ('val' )
13281330 if WARNINGS and __len != len (__val ):
13291331 warnings .warn ("Invalid len: expected: %d found: %d s=%s e=%s" % (__len , len (__val ), __val [:50 ], __val [- 50 :]))
1330- if __attr == TEXT_PROPERTY :
1332+ if __attr == self . textProperty :
13311333 # restore spaces that have been replaced
13321334 __val = __val .replace (WS , ' ' )
13331335 attrs [__attr + __parens ] = __val
@@ -1476,6 +1478,7 @@ def dump(self, windowId=-1, sleep=1):
14761478 MonkeyRunner .sleep (sleep )
14771479
14781480 if self .useUiAutomator :
1481+ # FIXME: this might not be the path on some devices
14791482 windowDump = '/mnt/sdcard/window_dump.xml'
14801483 output = self .device .shell ('uiautomator dump %s' % windowDump )
14811484 if not output :
@@ -1486,7 +1489,12 @@ def dump(self, windowId=-1, sleep=1):
14861489 if received :
14871490 received = received .encode ('ascii' , 'ignore' )
14881491 else :
1489- raise RuntimeError ("ERROR: Received empty UIAutomator dump" )
1492+ msg = ''
1493+ output = self .device .shell ('mount' )
1494+ if output :
1495+ if not re .search ('sdcard' , output ):
1496+ msg = ", it seems there's no sdcard mounted and uiautomator creates dump there."
1497+ raise RuntimeError ("ERROR: Received empty UIAutomator dump" + msg )
14901498 if DEBUG :
14911499 self .received = received
14921500 if DEBUG_RECEIVED :
@@ -1707,6 +1715,9 @@ def getViewIds(self):
17071715
17081716 def __getFocusedWindowPosition (self ):
17091717 return self .__getFocusedWindowId ()
1718+
1719+ def getSdkVersion (self ):
1720+ return self .build [VERSION_SDK_PROPERTY ]
17101721
17111722
17121723if __name__ == "__main__" :
0 commit comments