From c690ed8b5fdf9d36298b3622d0581de43ea5d180 Mon Sep 17 00:00:00 2001 From: codematrixer Date: Sat, 14 Sep 2024 13:27:09 +0800 Subject: [PATCH] feat: adapt windows env --- hmdriver2/_client.py | 13 +++++++------ hmdriver2/hdc.py | 7 ++----- 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/hmdriver2/_client.py b/hmdriver2/_client.py index 27dc768..28ca3ad 100644 --- a/hmdriver2/_client.py +++ b/hmdriver2/_client.py @@ -154,9 +154,9 @@ def __check_device_so_file_exists() -> bool: def __get_remote_md5sum() -> str: """Get the MD5 checksum of the file on the device.""" - command = "md5sum /data/local/tmp/agent.so | awk '{ print $1 }'" - result = self.hdc.shell(command).output.strip() - return result + command = "md5sum /data/local/tmp/agent.so" + data = self.hdc.shell(command).output.strip() + return data.split()[0] def __get_local_md5sum(f: str) -> str: """Calculate the MD5 checksum of a local file.""" @@ -183,10 +183,11 @@ def _restart_uitest_service(self): shell 44416 1 2 11:03:42 ? 00:00:01 uitest start-daemon com.hmtest.uitest@4x9@1" """ try: - # pids: list = self.hdc.shell("pidof uitest").output.strip().split() - result = self.hdc.shell("ps -ef | grep uitest | grep singleness").output.strip() + result = self.hdc.shell("ps -ef").output.strip() lines = result.splitlines() - for line in lines: + filtered_lines = [line for line in lines if 'uitest' in line and 'singleness' in line] + + for line in filtered_lines: if 'uitest start-daemon singleness' in line: parts = line.split() pid = parts[1] diff --git a/hmdriver2/hdc.py b/hmdriver2/hdc.py index 5dba2a9..5747cc9 100644 --- a/hmdriver2/hdc.py +++ b/hmdriver2/hdc.py @@ -106,8 +106,8 @@ def list_apps(self) -> List[str]: return [item.strip() for item in raw] def has_app(self, package_name: str) -> bool: - data = self.shell(f"bm dump -a | grep {package_name}").output - return True if data else False + data = self.shell("bm dump -a").output + return True if package_name in data else False def start_app(self, package_name: str, ability_name: str): return self.shell(f"aa start -a {ability_name} -b {package_name}") @@ -170,9 +170,6 @@ def send_key(self, key_code: Union[KeyCode, int]) -> None: self.shell(f"uitest uiInput keyEvent {key_code}") - def hide_keyboard(self): - self.shell("uinput -K -d 2 -i 2 -u 2") - def tap(self, x: int, y: int) -> None: self.shell(f"uitest uiInput click {x} {y}")