From 4e7f7322131ab4e5dfe477dc174bdaba9a22bcc9 Mon Sep 17 00:00:00 2001 From: rook828 <68120007+rook828@users.noreply.github.com> Date: Thu, 17 Sep 2020 09:37:22 -0400 Subject: [PATCH] Updated getTopActivityNameAndPid to ignore overlays and get visible activity --- src/com/dtmilano/android/adb/adbclient.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/com/dtmilano/android/adb/adbclient.py b/src/com/dtmilano/android/adb/adbclient.py index ce906f7f..272f02ef 100644 --- a/src/com/dtmilano/android/adb/adbclient.py +++ b/src/com/dtmilano/android/adb/adbclient.py @@ -1337,13 +1337,12 @@ def getFocusedWindowName(self): def getTopActivityNameAndPid(self): dat = self.shell('dumpsys activity top') - lines = dat.splitlines() activityRE = re.compile('\s*ACTIVITY ([A-Za-z0-9_.]+)/([A-Za-z0-9_.\$]+) \w+ pid=(\d+)') - m = activityRE.search(lines[1]) - if m: - return m.group(1), m.group(2), m.group(3) + m = activityRE.findall(dat) + if len(m) > 0: + return m[-1] else: - warnings.warn("NO MATCH:" + lines[1]) + warnings.warn("NO MATCH:" + dat) return None def getTopActivityName(self):