From 4785c361f61647a99c58a4fcffa305d9112de8df Mon Sep 17 00:00:00 2001 From: SarContDeli <48789988+SaiCateDoan@users.noreply.github.com> Date: Sat, 19 Mar 2022 00:39:00 +0800 Subject: [PATCH] Fix: Improved the logic of getting package name on WSA --- module/device/app_control.py | 4 +++- module/device/method/wsa.py | 25 +++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/module/device/app_control.py b/module/device/app_control.py index 9c180c0ae..b62d10a07 100644 --- a/module/device/app_control.py +++ b/module/device/app_control.py @@ -12,7 +12,9 @@ class AppControl(Adb, WSA, Uiautomator2): def app_is_running(self) -> bool: method = self.config.Emulator_ControlMethod - if method == 'uiautomator2' or method == 'minitouch': + if 'wsa' in self.config.Emulator_Serial: + package = self.app_current_wsa() + elif method == 'uiautomator2' or method == 'minitouch': package = self.app_current_uiautomator2() else: package = self.app_current_adb() diff --git a/module/device/method/wsa.py b/module/device/method/wsa.py index a514f6568..a971063a7 100644 --- a/module/device/method/wsa.py +++ b/module/device/method/wsa.py @@ -54,6 +54,31 @@ def retry(func): class WSA(Connection): + @retry + def app_current_wsa(self): + """ + Returns: + str: Package name. + + Raises: + OSError + """ + # try: adb shell dumpsys activity top + _activityRE = re.compile( + r'ACTIVITY (?P[^\s]+)/(?P[^/\s]+) \w+ pid=(?P\d+)' + ) + package = self.config.Emulator_PackageName + output = self.adb_shell(['dumpsys', 'activity', 'top']) + ms = _activityRE.finditer(output) + ret = None + for m in ms: + ret = m.group('package') + if(ret == package): + return ret + if ret: # get last result + return ret + raise OSError("Couldn't get focused app") + @retry def app_start_wsa(self, package_name, display, allow_failure=False): """