From 890832134315b5ca94eed0ec7e96de2950ab60e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=83=9D=E6=99=93=E9=B9=8F?= Date: Fri, 10 May 2024 18:18:48 +0800 Subject: [PATCH] =?UTF-8?q?fix:=E5=85=BC=E5=AE=B9iOS17.4=E7=B3=BB=E7=BB=9F?= =?UTF-8?q?start=5Ftunnel?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tidevice3/cli/tunneld.py | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/tidevice3/cli/tunneld.py b/tidevice3/cli/tunneld.py index d4064e7..02bf211 100644 --- a/tidevice3/cli/tunneld.py +++ b/tidevice3/cli/tunneld.py @@ -28,6 +28,7 @@ logger = logging.getLogger(__name__) os_utils = OsUtils.create() + class Address(NamedTuple): ip: str port: int @@ -43,6 +44,16 @@ def get_connected_devices() -> list[str]: return [d.Identifier for d in devices if Version(d.ProductVersion) >= Version("17")] +def get_need_lockdown_devices() -> list[str]: + """return list of udid""" + try: + devices = list_devices(usb=True, network=False) + except MuxException as e: + logger.error("list_devices failed: %s", e) + return [] + return [d.Identifier for d in devices if Version(d.ProductVersion) >= Version("17.4")] + + def guess_pymobiledevice3_cmd() -> List[str]: pmd3path = shutil.which("pymobiledevice3") if not pmd3path: @@ -64,7 +75,10 @@ def start_tunnel(pmd3_path: List[str], udid: str) -> Tuple[Address, subprocess.P """ # cmd = ["bash", "-c", "echo ::1 1234; sleep 10001"] log_prefix = f"[{udid}]" - cmdargs = pmd3_path + f"remote start-tunnel --script-mode --udid {udid}".split() + start_tunnel_cmd = "remote" + if udid in get_need_lockdown_devices(): + start_tunnel_cmd = "lockdown" + cmdargs = pmd3_path + f"{start_tunnel_cmd} start-tunnel --script-mode --udid {udid}".split() logger.info("%s cmd: %s", log_prefix, shlex.join(cmdargs)) process = subprocess.Popen( cmdargs, stdin=subprocess.DEVNULL, stdout=subprocess.PIPE @@ -120,9 +134,9 @@ def _start_tunnel_keeper(self, udid: str): except TunnelError: logger.exception("udid: %s start-tunnel failed", udid) time.sleep(3) - + def _wait_process_exit(self, process: subprocess.Popen, udid: str): - while True: + while True: try: process.wait(1.0) self.addresses.pop(udid, None)