diff --git a/testing/mozbase/mozdevice/mozdevice/adb.py b/testing/mozbase/mozdevice/mozdevice/adb.py index fefc8c532f7f..25142caf9f44 100644 --- a/testing/mozbase/mozdevice/mozdevice/adb.py +++ b/testing/mozbase/mozdevice/mozdevice/adb.py @@ -2990,13 +2990,21 @@ class ADBDevice(ADBCommand): :raises: * ADBTimeoutError * ADBError """ + if self.version < version_codes.Q: + return self._get_top_activity_P(timeout=timeout) + return self._get_top_activity_Q(timeout=timeout) + + def _get_top_activity_P(self, timeout=None): + """Returns the name of the top activity (focused app) reported by dumpsys + for Android 9 and earlier. + """ package = None data = None cmd = "dumpsys window windows" try: data = self.shell_output(cmd, timeout=timeout) except Exception: - # dumpsys intermittently fails on some platforms (4.3 arm emulator) + # dumpsys intermittently fails on some platforms. return package m = re.search('mFocusedApp(.+)/', data) if not m: @@ -3012,6 +3020,30 @@ class ADBDevice(ADBCommand): self._logger.debug('get_top_activity: %s' % str(package)) return package + def _get_top_activity_Q(self, timeout=None): + """Returns the name of the top activity (focused app) reported by dumpsys + for Android 10 and later. + """ + package = None + data = None + cmd = "dumpsys window" + try: + data = self.shell_output(cmd, timeout=timeout) + except Exception: + # dumpsys intermittently fails on some platforms (4.3 arm emulator) + return package + m = re.search('mFocusedApp=AppWindowToken{\w+ token=Token{' + '\w+ ActivityRecord{\w+ w+ (\w+)/w+ \w+}}}', data) + if m: + line = m.group(1) + # Extract package name: string of non-whitespace ending in forward slash + m = re.search('(\S+)/', line) + if m: + package = m.group(1) + if self._verbose: + self._logger.debug('get_top_activity: %s' % str(package)) + return package + # System control methods def is_device_ready(self, timeout=None): diff --git a/testing/mozbase/mozdevice/mozdevice/version_codes.py b/testing/mozbase/mozdevice/mozdevice/version_codes.py index 369a294ad5e2..15ef59b2159c 100644 --- a/testing/mozbase/mozdevice/mozdevice/version_codes.py +++ b/testing/mozbase/mozdevice/mozdevice/version_codes.py @@ -66,3 +66,5 @@ O = 26 O_MR1 = 27 # Pie P = 28 +# 10 +Q = 29