def disconnect_all(self): try: command_string = 'adb disconnect' command_string_list = command_string.split(" ") adb_output = subprocess.check_output(command_string_list) adb_output_string = adb_output.decode("utf-8") log_d(adb_output_string) except subprocess.CalledProcessError as e: log_e(str(e))
def adb_tcpip(self, device_id, port): try: command_string = 'adb -s {0} tcpip {1}'.format(device_id, port) command_string_list = command_string.split(" ") adb_output = subprocess.check_output(command_string_list) adb_output_string = adb_output.decode("utf-8") log_d(adb_output_string) except subprocess.CalledProcessError as e: log_e(str(e))
def dump_load(self, device_id): if not os.path.isdir(Const.LOG_FOLDER_NAME): os.mkdir(Const.LOG_FOLDER_NAME) adb_shell = AdbShellAdapter() log_path = self._get_log_name(device_id) log_file = open(log_path, 'w') command = 'adb -s {0} logcat -d -v threadtime'.format(device_id) log_d(log_path) log_file.write(adb_shell.adb_execute(command))
def adb_push(self, device_id, src, des): try: command = 'adb -s {0} push {1} {2}'.format(device_id, src, des) command_list = command.split(" ") adb_output = subprocess.check_output(command_list) adb_output_string = adb_output.decode("utf-8") if '100%' in adb_output_string: log_d("Successfully push {0}!".format(des)) return True else: return False except subprocess.CalledProcessError as e: print(e) return False
def adb_install(self, device_id, path_to_device_apk): try: command = 'adb -s {0} shell pm install -r {1}'.format( device_id, path_to_device_apk) command_list = command.split(" ") adb_output = subprocess.check_output(command_list) adb_output_string = adb_output.decode("utf-8") if 'Success' in adb_output_string: log_d("Successfully install {0}!".format(path_to_device_apk)) return True else: return False except subprocess.CalledProcessError as e: log_e(str(e)) return False
def get_deviceid_and_validport(self): attached_devices = self.adbAdapter.adb_devices() used_ports = [] deviceIds = [] for device in attached_devices: if ":" in device: port = int(device.split(":")[1]) used_ports.append(port) else: deviceIds.append(device) valid_port = 8888 if len(used_ports) > 0: used_port_max = max(used_ports) valid_port = used_port_max + 1 log_d('ID:{0}, Port:{1}'.format(deviceIds[0], valid_port)) return deviceIds[0], valid_port
def get_device_wifi_ip(self, device_id): ip_address = "" try: command = 'adb -s {0} shell ip addr show wlan0 | grep inet'.format( device_id) command_list = command.split(" ") adb_output = subprocess.check_output(command_list) adb_output_string = adb_output.decode("utf-8") adb_output_string_list = adb_output_string.split("\n") inet_info_list = adb_output_string_list[0].lstrip().split(" ") ip_address = inet_info_list[1].split("/")[0] except subprocess.CalledProcessError as e: log_e(str(e)) log_d('defice ip: {0}'.format(ip_address)) return ip_address