def current_activity(self):
     """Returns the current focused activity on the system"""
     # https://github.com/aldonin/appium-adb/blob/7b4ed3e7e2b384333bb85f8a2952a3083873a90e/lib/adb.js#L1278
     windows = Adb.shell(self.id, 'dumpsys window windows')
     null_re = r'mFocusedApp=null'
     # https://regex101.com/r/xZ8vF7/1
     current_focus_re = r'mCurrentFocus.+\s([^\s\/\}]+)\/[^\s\/\}]+(\.[^\s\/\}]+)}'
     focused_app_re = r'mFocusedApp.+Record\{.*\s([^\s\/\}]+)\/([^\s\/\}\,]+)(\s[^\s\/\}]+)*\}'
     match = None
     found_null = False
     for line in windows.split('\n'):
         current_focus = re.search(current_focus_re, line)
         focused_app = re.search(focused_app_re, line)
         if current_focus:
             match = current_focus
         elif focused_app and match is None:
             match = focused_app
         elif re.search(null_re, line):
             found_null = True
     if match:
         result = match.group(1).strip()
         self.logger.debug('Current activity: %s' % result)
         return result
     elif found_null:
         self.logger.debug('Current activity: null')
         return None
     else:
         self.logger.error('Results from dumpsys window windows: \n%s' %
                           windows)
         raise AdbError('Could not parse activity from dumpsys')
Пример #2
0
 def su_unplug(self, restart):
     """Root unplugs the device"""
     self.root_plug_value = Adb.shell_su(self.id,
                                         'cat %s' % self.root_unplug_file)
     if 'su: not found' in self.root_plug_value:
         raise AdbError("%s %s: is not rooted" % (self.id, self.name))
     if 'No such file or directory' in self.root_plug_value:
         raise ConfigError(
             '%s %s: the root unplug file seems to be invalid' %
             (self.id, self.name))
     if restart:
         self.check_plug_value()
     Adb.shell_su(
         self.id,
         'echo %s > %s' % (self.root_unplug_value, self.root_unplug_file))
 def launch_package(self, package):
     """Launches a package by name without activity, returns instantly"""
     # https://stackoverflow.com/a/25398877
     result = Adb.shell(self.id, 'monkey -p {} 1'.format(package))
     if 'monkey aborted' in result:
         raise AdbError('Could not launch "{}"'.format(package))
 def install(self, apk):
     """Check if the file exists, and then install the package"""
     if not op.isfile(apk):
         raise AdbError("%s is not found" % apk)
     Adb.install(self.id, apk)