def get_sign_info(self): keytool = os.path.join(PathManager.get_java_path(), Constant.KEYTOOL_FILENAME) code, result = star.runcmd([keytool, '-printcert', '-jarfile', self._filename]) result = result.decode("gb2312", "ignore") if code==0: pass return result
def kill_server(self): """ Kill adb server daemon on host :return: result of star.runcmd() execution """ adb_full_cmd = [ADB_COMMAND_PREFIX, ADB_COMMAND_KILL_SERVER] return star.runcmd(adb_full_cmd)
def get_state(self): """ Get state of device connected per adb :return: result of star.runcmd() execution """ adb_full_cmd = [ADB_COMMAND_PREFIX, ADB_COMMAND_GET_STATE] return star.runcmd(adb_full_cmd)
def install(self, apk, opts=None): """ Install *.apk on target :param apk: string path to apk on host to install :param opts: list command options (e.g. "-r", "-a") :return: result of star.runcmd() execution """ cmds = [ADB_COMMAND_PREFIX] if len(self._devices) > 1 or not self._deviceSelected: cmds.append("-s") cmds.append(self._deviceSelected) cmds.append(ADB_COMMAND_INSTALL) if opts is not None: cmds.append(opts) cmds.append(apk) code, ret = star.runcmd(cmds) if ret.find('Failure') != -1: pattern = re.compile('Failure(.*?)\r\n', re.U | re.S) result = pattern.search(ret) reason = '' if result is not None: reason = result.group(1).strip() logging.error('[x] Failure ' + reason) return False return True
def start_server(self): """ Startd adb server daemon on host :return: result of star.runcmd() execution """ adb_full_cmd = [ADB_COMMAND_PREFIX, ADB_COMMAND_START_SERVER] return star.runcmd(adb_full_cmd)
def wait_for_device(self): """ Block execution until the device is online :return: result of star.runcmd() execution """ adb_full_cmd = [ADB_COMMAND_PREFIX, ADB_COMMAND_WAITFORDEVICE] return star.runcmd(adb_full_cmd)
def get_log(self, timeout=40): cmds = [ADB_COMMAND_PREFIX] if len(self._devices) > 1 or not self._deviceSelected: cmds.append("-s") cmds.append(self._deviceSelected) cmds.append('logcat -v time ActivityManager:I *:S') code, result = star.runcmd(cmds) return result
def sync(self): """ Copy host->device only if changed :return: result of star.runcmd() execution """ adb_full_cmd = [ ADB_COMMAND_PREFIX, ADB_COMMAND_SHELL, ADB_COMMAND_SYNC ] return star.runcmd(adb_full_cmd)
def pull(self, src, dest): """ Pull object from target to host :param src: string path of object on target :param dest: string destination path on host :return: result of star.runcmd() execution """ adb_full_cmd = [ADB_COMMAND_PREFIX, ADB_COMMAND_PULL, src, dest] return star.runcmd(adb_full_cmd)
def push(self, src, dest): """ Push object from host to target :param src: string path to source object on host :param dest: string destination path on target :return: result of star.runcmd() execution """ adb_full_cmd = [ADB_COMMAND_PREFIX, ADB_COMMAND_PUSH, src, dest] return star.runcmd(adb_full_cmd)
def get_adb_version(self): adb_full_cmd = [ADB_COMMAND_PREFIX, ADB_COMMAND_VERSION] code, ret = star.runcmd(adb_full_cmd) try: pattern = re.compile(r"version\s(.*?)\s") version = pattern.search(ret).group(1) except Exception as e: print(e) version = None return version
def reboot_wait_completed(self, _timeout=180): '''等待手机启动完成''' # 手机重启完后 adbd Insecure 启动时会导致adb断开重连,qt4a框架己经实现了adb root权限功能,测试手机请不要安装 adbd Insecure import time cmds = self.gen_adb_args('wait-for-_adb') star.runcmd(cmds, timeout=_timeout) boot_complete = False attempts = 0 wait_period = 5 while not boot_complete and (attempts * wait_period) < _timeout: code, output = self.runshellcmd("getprop sys.boot_completed", retry_count=1) output = output.strip() if output == "1": boot_complete = True else: time.sleep(wait_period) attempts += 1 if not boot_complete: raise RuntimeError("dev.bootcomplete 标志在 %s 秒后仍未设置,手机重启失败" % _timeout)
def uninstall(self, app, opts=[]): """ Uninstall app from target :param app: app name to uninstall from target (e.g. "com.example.android.valid") :param opts: list command options (e.g. ["-r", "-a"]) :return: result of star.runcmd() execution """ adb_full_cmd = [ ADB_COMMAND_PREFIX, ADB_COMMAND_UNINSTALL, self._convert_opts(opts), app ] return star.runcmd(adb_full_cmd)
def shell(self, cmd): """ Execute shell command on target :param cmd: string shell command to execute :return: result of star.runcmd() execution """ cmds = [ADB_COMMAND_PREFIX] if len(self._devices) > 1 or not self._deviceSelected: cmds.append("-s") cmds.append(self._deviceSelected) cmds.append(ADB_COMMAND_SHELL) cmds.append(cmd) return star.runcmd(cmds)
def get_serialno(self): """ Get serial number for all available target devices :return: result of star.runcmd() execution """ cmds = [ADB_COMMAND_PREFIX] if len(self._devices) > 1 or not self._deviceSelected: cmds.append("-s") cmds.append(self._deviceSelected) cmds.append(ADB_COMMAND_GETSERIALNO) code, ret = star.runcmd(cmds) if code == 0: return ret else: return None
def runshellcmd(self, cmd): cmds = [ADB_COMMAND_PREFIX, 'shell', cmd] return star.runcmd(cmds)