@@ -786,7 +786,7 @@ def keyevent(self, key_code: typing.Union[int, str]) -> str:
786786 def __is_percent (self , v ):
787787 return isinstance (v , float ) and v <= 1.0
788788
789- def click (self , x , y ):
789+ def click (self , x , y ) -> None :
790790 """
791791 simulate android tap
792792
@@ -799,9 +799,9 @@ def click(self, x, y):
799799 x = int (x * w ) if is_percent (x ) else x
800800 y = int (y * h ) if is_percent (y ) else y
801801 x , y = map (str , [x , y ])
802- return self .shell (['input' , 'tap' , x , y ])
802+ self .shell (['input' , 'tap' , x , y ])
803803
804- def swipe (self , sx , sy , ex , ey , duration : float = 1.0 ):
804+ def swipe (self , sx , sy , ex , ey , duration : float = 1.0 ) -> None :
805805 """
806806 swipe from start point to end point
807807
@@ -817,7 +817,7 @@ def swipe(self, sx, sy, ex, ey, duration: float = 1.0):
817817 ex = int (ex * w ) if is_percent (ex ) else ex
818818 ey = int (ey * h ) if is_percent (ey ) else ey
819819 x1 , y1 , x2 , y2 = map (str , [sx , sy , ex , ey ])
820- return self .shell (
820+ self .shell (
821821 ['input' , 'swipe' , x1 , y1 , x2 , y2 ,
822822 str (int (duration * 1000 ))])
823823
@@ -1225,15 +1225,19 @@ def dump_hierarchy(self) -> str:
12251225 Raises:
12261226 AdbError
12271227 """
1228+ target = '/data/local/tmp/uidump.xml'
12281229 output = self .shell (
1229- ' uiautomator dump /data/local/tmp/uidump.xml && echo success' )
1230- if " success" not in output :
1230+ f'rm -f { target } ; uiautomator dump { target } && echo success' )
1231+ if 'ERROR' in output or ' success' not in output :
12311232 raise AdbError ("uiautomator dump failed" , output )
12321233
12331234 buf = b''
1234- for chunk in self .sync .iter_content ("/data/local/tmp/uidump.xml" ):
1235+ for chunk in self .sync .iter_content (target ):
12351236 buf += chunk
1236- return buf .decode ("utf-8" )
1237+ xml_data = buf .decode ("utf-8" )
1238+ if not xml_data .startswith ('<?xml' ):
1239+ raise AdbError ("dump output is not xml" , xml_data )
1240+ return xml_data
12371241
12381242 @retry (AdbError , delay = .5 , tries = 3 , jitter = .1 )
12391243 def app_current (self ) -> RunningAppInfo :
0 commit comments