def clean_sdcard(self) -> None: adb.get_root_permissions(self) adb.adb_command(self, "remount", timeout=settings.ADB_REGULAR_COMMAND_TIMEOUT) adb.shell_command(self, "mount -o rw,remount /", timeout=settings.ADB_REGULAR_COMMAND_TIMEOUT) adb.shell_command(self, "rm -rf /mnt/sdcard/*", timeout=settings.ADB_REGULAR_COMMAND_TIMEOUT)
def send_command(self, device: Device, package_name: str, command: str) -> str: """ :param command: to send through the socket and be run by the runner. :return: the response of the runner as a string. """ # ensure there is only one return character at the end of the command command = command.rstrip("\n") + "\n" # set up evolutiz runner in emulator adb.adb_command(device, f"forward tcp:{self.port} tcp:{self.port}") adb.shell_command( device, f"evolutiz -p {package_name} -c android.intent.category.LAUNCHER --port {self.port} &", discard_output=True) # wait for evolutiz runner to be ready output = "" tries = 0 while "Using EvolutizSourceNetwork" not in output: if tries >= 6: raise Exception( f"Unable to connect to Evolutiz test runner for command: {command}." ) tries += 1 output, errors, result_code = adb.adb_command( device, f"logcat -s Evolutiz -d | tail -n 1") time.sleep(0.5) # send command and collect result with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s: s.connect((self.host, self.port)) s.sendall(command.encode('utf-8')) data = self.receive_data(s) s.close() # need to manually kill evolutiz after working adb.pkill(device, "evolutiz") if data is None: raise Exception(f"Unable to parse result of command {command}.") else: return data.rstrip("\n")
def install(self, device: Device) -> bool: adb.get_root_permissions(device) # remount partitions output, errors, result_code = adb.adb_command(device, "remount", retry=5) if result_code != 0: raise Exception(f"Unable to remount partitions on device: {device.name} - {errors} - {output}") # make /mnt/sdcard writable output, errors, result_code = adb.shell_command(device, "mount -o rw,remount /") if result_code != 0: raise Exception(f"Unable to remount root partition on device: {device.name}") # push adb.push(device, self.test_runner_jar_path, f"/system/framework/{self.test_runner_name}.jar") output, errors, result_code = adb.shell_command( device, f"chmod 777 /system/framework/{self.test_runner_name}.jar" ) if result_code != 0: raise Exception(f"Unable to install test runner on device: {device.name}") adb.push(device, self.test_runner_executable_path, f"/system/bin/{self.test_runner_name}") output, errors, result_code = adb.shell_command(device, f"chmod 777 /system/bin/{self.test_runner_name}") if result_code != 0: raise Exception(f"Unable to install test runner on device: {device.name}") return True
def reboot(self) -> None: Device.reboot(self) output, errors, result_code = adb.adb_command( self, "reboot", timeout=settings.ADB_REGULAR_COMMAND_TIMEOUT) if result_code != 0: logger.log_progress(f"\nUnable to reboot device: {self.name}") logger.log_progress("\nPlease, turn it off and on manually.") raise Exception(f"Unable to reboot device: {self.name}")
def forward_port(self, host_port: int, emulator_port: int) -> None: if host_port in self.forwarded_ports: # This port was already forwarded for this device return output, errors, result_code = adb.adb_command( self, f"forward tcp:{host_port} tcp:{emulator_port}") if result_code != 0: raise Exception( f"Unable to forward TCP relay port from emulator to local PC: {output} {errors}" ) self.forwarded_ports.add(host_port)
def shutdown(self) -> None: Device.shutdown(self) adb.adb_command(self, "emu kill") time.sleep(3)