Example #1
0
    def check_screen_locked(self, times=1):
        """
        adb shell dumpsys window policy | grep isStatusBarKeyguard 确认是否有锁
        adb shell dumpsys window policy | grep ScreenOn 是否亮屏
        """
        try:
            if times >= 10:
                return False
            logger.info('({}) <尝试{}> 检查设备是否锁屏'.format(self.device_name, times))
            window_policy = command_execute(
                '{} shell dumpsys window policy'.format(
                    self.adb_command)).stdout.read()

            window_policy = deal_with_python_version(window_policy)

            locked_status = re.findall(r'isStatusBarKeyguard=(\w+)',
                                       window_policy)[0]
            bright_status = re.findall(r'mScreenOnFully=(\w+)',
                                       window_policy)[0]

            if locked_status == 'false' and bright_status == 'true':
                logger.info('({}) 设备是正常开锁状态!'.format(self.device_name))
                return True
            elif bright_status == 'false':
                logger.info('({}) 设备锁屏!'.format(self.device_name))
                self.wakeup_screen()
                time.sleep(1)
                self.unlock_screen()
                time.sleep(1)
                return self.check_screen_locked(times=times + 1)
        except Exception as e:
            logger.error(e)
            logger.error(traceback.format_exc())
            return self.check_screen_locked(times=times + 1)
Example #2
0
 def get_uid(self, pid):
     result = command_execute("{} shell cat /proc/{}/status".format(
         self.adb_command, pid)).stdout.readlines()
     result = deal_with_python_version(result)
     for i in result:
         if 'uid' in i.lower():
             return i.split()[1]
Example #3
0
 def get_battery_level(self):
     result = command_execute('{} shell dumpsys battery'.format(
         self.adb_command)).stdout.readlines()
     result = deal_with_python_version(result)
     for r in result:
         if 'level' in r:
             return int(r.split(':')[1])
     return 0
Example #4
0
    def get_process(self, package_name):
        if self.system is "Windows":
            pid_command = command_execute('{} shell "ps| grep {}"$'.format(
                self.adb_command, package_name)).stdout.readlines()
        else:
            pid_command = command_execute('{} shell "ps| grep -w {}"'.format(
                self.adb_command, package_name)).stdout.readlines()

        return deal_with_python_version(pid_command)
Example #5
0
 def output(self, p):
     if p.stdout:
         return deal_with_python_version(p.stdout.readlines())
     else:
         return deal_with_python_version(p.stderr.readlines())