fix: USB 设备双路径——优先本机 adb 直连,其次 220 远程 adb server(原实现只查远程,本机 USB 会被误判不在 server)
This commit is contained in:
+19
-11
@@ -19,7 +19,7 @@ import uiautomator2 as u2
|
||||
from config import USB_ADB_HOST, USB_ADB_PORT
|
||||
from core.logger import get_logger
|
||||
from core import device_pool
|
||||
from .adb_helper import adb_connect, _adb_remote
|
||||
from .adb_helper import _adb, adb_connect, _adb_remote
|
||||
|
||||
_log = get_logger("core.worker")
|
||||
|
||||
@@ -62,22 +62,30 @@ class STFDevice:
|
||||
_log.info(f"[{self.serial}] 选定设备")
|
||||
|
||||
# 直连优先:serial 本身是 IP:5555(如 Tailscale 网络设备)时直接 adb connect。
|
||||
# 只 connect、绝不 disconnect/kill-server(红线),不影响 STF provider 的连接。
|
||||
# 只 connect、绝不 disconnect/kill-server(红线),不影响共享 adb transport。
|
||||
if ":" in self.serial:
|
||||
self.remote_adb_url = self.serial
|
||||
_log.info(f"[{self.serial}] 直连设备: {self.remote_adb_url}")
|
||||
if not adb_connect(self.remote_adb_url):
|
||||
raise STFError(f"adb connect 失败: {self.remote_adb_url}", "offline")
|
||||
else:
|
||||
# USB 设备:插在 220 上,本机 adb 看不到,经远程 adb server 驱动。
|
||||
# 无需 adb connect——设备已在远程 server 上,直接校验可见性。
|
||||
self.usb_server = f"{USB_ADB_HOST}:{USB_ADB_PORT}"
|
||||
_log.info(f"[{self.serial}] USB 设备,远程 adb server: {self.usb_server}")
|
||||
out = _adb_remote(USB_ADB_HOST, USB_ADB_PORT, "devices") or ""
|
||||
seen = {line.split()[0] for line in out.splitlines()[1:]
|
||||
if len(line.split()) >= 2}
|
||||
if self.serial not in seen:
|
||||
raise STFError(f"USB 设备 {self.serial} 不在远程 adb server", "offline")
|
||||
# USB 设备(serial 无冒号):优先本机 adb(插在平台本机),
|
||||
# 其次 220 远程 adb server(插在 220 上,经 Tailscale 驱动)。
|
||||
# 两者都不需要 adb connect——设备已连接在对应 server 上,只做可见性校验。
|
||||
local = {line.split()[0] for line in (_adb("devices") or "").splitlines()[1:]
|
||||
if len(line.split()) >= 2}
|
||||
if self.serial in local:
|
||||
self.remote_adb_url = self.serial # u2 走本地 adb(无需 connect)
|
||||
_log.info(f"[{self.serial}] USB 设备,本机 adb 直连")
|
||||
else:
|
||||
self.usb_server = f"{USB_ADB_HOST}:{USB_ADB_PORT}"
|
||||
_log.info(f"[{self.serial}] USB 设备,远程 adb server: {self.usb_server}")
|
||||
out = _adb_remote(USB_ADB_HOST, USB_ADB_PORT, "devices") or ""
|
||||
seen = {line.split()[0] for line in out.splitlines()[1:]
|
||||
if len(line.split()) >= 2}
|
||||
if self.serial not in seen:
|
||||
raise STFError(
|
||||
f"USB 设备 {self.serial} 不在本机 adb 也不在远程 adb server", "offline")
|
||||
time.sleep(2)
|
||||
|
||||
def _pick_free(self):
|
||||
|
||||
Reference in New Issue
Block a user