|
23 | 23 | import subprocess |
24 | 24 | import threading |
25 | 25 | import unicodedata |
| 26 | +from typing import Optional |
26 | 27 |
|
27 | 28 | from com.dtmilano.android.adb.dumpsys import Dumpsys |
28 | 29 |
|
29 | | -__version__ = '21.4.4' |
| 30 | +__version__ = '21.5.0' |
30 | 31 |
|
31 | 32 | import sys |
32 | 33 | import warnings |
@@ -388,7 +389,8 @@ def checkConnected(self, sock=None): |
388 | 389 |
|
389 | 390 | def checkVersion(self, ignoreversioncheck=False, reconnect=True): |
390 | 391 | if DEBUG: |
391 | | - print("checkVersion(reconnect=%s) ignoreversioncheck=%s" % (reconnect, ignoreversioncheck), file=sys.stderr) |
| 392 | + print("checkVersion(reconnect=%s) ignoreversioncheck=%s" % (reconnect, ignoreversioncheck), |
| 393 | + file=sys.stderr) |
392 | 394 | self.__send('host:version', reconnect=False) |
393 | 395 | # HACK: MSG_WAITALL not available on windows |
394 | 396 | # version = self.socket.recv(8, socket.MSG_WAITALL) |
@@ -849,7 +851,8 @@ def takeSnapshot(self, reconnect=False): |
849 | 851 | if DEBUG: |
850 | 852 | if version == 1: |
851 | 853 | print(" takeSnapshot:", ( |
852 | | - version, bpp, size, width, height, roffset, rlen, boffset, blen, goffset, glen, aoffset, alen), file=sys.stderr) |
| 854 | + version, bpp, size, width, height, roffset, rlen, boffset, blen, goffset, glen, aoffset, alen), |
| 855 | + file=sys.stderr) |
853 | 856 | elif version == 2: |
854 | 857 | print(" takeSnapshot:", ( |
855 | 858 | version, bpp, colorspace, width, height, roffset, rlen, boffset, blen, goffset, glen, aoffset, |
@@ -952,21 +955,23 @@ def __transformPointByOrientation(self, xxx_todo_changeme, orientationOrig, orie |
952 | 955 |
|
953 | 956 | def touch(self, x, y, orientation=-1, eventType=DOWN_AND_UP): |
954 | 957 | if DEBUG_TOUCH: |
955 | | - print("touch(x=", x, ", y=", y, ", orientation=", orientation, ", eventType=", eventType, ")", file=sys.stderr) |
| 958 | + print("touch(x=", x, ", y=", y, ", orientation=", orientation, ", eventType=", eventType, ")", |
| 959 | + file=sys.stderr) |
956 | 960 | self.__checkTransport() |
957 | 961 | if orientation == -1: |
958 | 962 | orientation = self.display['orientation'] |
959 | 963 | version = self.getSdkVersion() |
960 | 964 | if version > 10: |
961 | 965 | self.shell( |
962 | | - 'input tap %d %d' % self.__transformPointByOrientation((x, y), orientation, self.display['orientation'])) |
| 966 | + 'input tap %d %d' % self.__transformPointByOrientation((x, y), orientation, |
| 967 | + self.display['orientation'])) |
963 | 968 | else: |
964 | 969 | raise RuntimeError('drag: API <= 10 not supported (version=%d)' % version) |
965 | 970 |
|
966 | | - |
967 | 971 | def touchDip(self, x, y, orientation=-1, eventType=DOWN_AND_UP): |
968 | 972 | if DEBUG_TOUCH: |
969 | | - print("touchDip(x=", x, ", y=", y, ", orientation=", orientation, ", eventType=", eventType, ")", file=sys.stderr) |
| 973 | + print("touchDip(x=", x, ", y=", y, ", orientation=", orientation, ", eventType=", eventType, ")", |
| 974 | + file=sys.stderr) |
970 | 975 | self.__checkTransport() |
971 | 976 | if orientation == -1: |
972 | 977 | orientation = self.display['orientation'] |
@@ -1082,7 +1087,7 @@ def isScreenOn(self): |
1082 | 1087 |
|
1083 | 1088 | self.__checkTransport() |
1084 | 1089 | window_policy = self.shell('dumpsys window policy') |
1085 | | - |
| 1090 | + |
1086 | 1091 | # Deprecated in API 20, removed in API 29 |
1087 | 1092 | screenOnRE = re.compile('mScreenOnFully=(true|false)') |
1088 | 1093 | m = screenOnRE.search(window_policy) |
@@ -1118,7 +1123,7 @@ def percentSame(image1, image2): |
1118 | 1123 | size_x1, size_y1 = image1.size |
1119 | 1124 | size_x2, size_y2 = image2.size |
1120 | 1125 | if (size_x1 != size_x2 or |
1121 | | - size_y1 != size_y2): |
| 1126 | + size_y1 != size_y2): |
1122 | 1127 | return 0 |
1123 | 1128 |
|
1124 | 1129 | # Images are the same size |
@@ -1214,7 +1219,8 @@ def initDisplayProperties(self): |
1214 | 1219 |
|
1215 | 1220 | def log(self, tag, message, priority='D', verbose=False): |
1216 | 1221 | if DEBUG_LOG: |
1217 | | - print("log(tag=%s, message=%s, priority=%s, verbose=%s)" % (tag, message, priority, verbose), file=sys.stderr) |
| 1222 | + print("log(tag=%s, message=%s, priority=%s, verbose=%s)" % (tag, message, priority, verbose), |
| 1223 | + file=sys.stderr) |
1218 | 1224 | self.__checkTransport() |
1219 | 1225 | message = self.substituteDeviceTemplate(message) |
1220 | 1226 | if verbose or priority == 'V': |
@@ -1389,6 +1395,20 @@ def getTopActivityName(self): |
1389 | 1395 | else: |
1390 | 1396 | return None |
1391 | 1397 |
|
| 1398 | + def getTopActivityUri(self) -> Optional[str]: |
| 1399 | + tan = self.getTopActivityName() |
| 1400 | + dat = self.shell('dumpsys activity') |
| 1401 | + startActivityRE = re.compile(r'^\s*mStartActivity:') |
| 1402 | + intentRE = re.compile(f'^\\s*Intent {{ act=(\\S+) dat=(\\S+) flg=(\\S+) cmp={tan} }}') |
| 1403 | + lines = dat.splitlines() |
| 1404 | + for n, _line in enumerate(lines): |
| 1405 | + if startActivityRE.match(_line): |
| 1406 | + for i in range(n, n + 6): |
| 1407 | + m = intentRE.match(lines[i]) |
| 1408 | + if m: |
| 1409 | + return m.group(2) |
| 1410 | + return None |
| 1411 | + |
1392 | 1412 | def substituteDeviceTemplate(self, template): |
1393 | 1413 | serialno = self.serialno.replace('.', '_').replace(':', '-') |
1394 | 1414 | window_name = self.getFocusedWindowName() or 'no_name' |
|
0 commit comments