feat: 设备自动发现——定时扫描局域网+Tailscale 网段开放 adb 5555 的设备进入待连接池,用户确认后才加入正式设备池(不自动连接);socket 并发探测+adb 短超时验证(state=device 过滤 unauthorized),配置存 app_meta 可前端调整;配套:adb_connect_light 验证短超时、DISABLE_SCHEDULER 回归开关
This commit is contained in:
+9
-6
@@ -19,17 +19,18 @@ _ADB_LOCK = threading.Lock()
|
||||
_ADB_TIMEOUT = 30
|
||||
|
||||
|
||||
def _adb(*args):
|
||||
def _adb(*args, timeout=_ADB_TIMEOUT):
|
||||
"""执行 adb 命令,返回 (stdout+stderr) 文本。不用 shell=True,避免子进程环境问题。
|
||||
|
||||
用 bytes 模式自己解码(Windows 下 subprocess text=True 会用 GBK 读 adb 输出,
|
||||
遇到非 GBK 字节会崩溃)。
|
||||
带 30s 超时:adb connect 到不可达地址可能挂很久,超时返回空串由调用方处理。
|
||||
timeout 可覆盖(扫描验证等非关键路径用短超时快速失败)。
|
||||
"""
|
||||
try:
|
||||
r = subprocess.run([ADB_PATH, *args], capture_output=True, timeout=_ADB_TIMEOUT)
|
||||
r = subprocess.run([ADB_PATH, *args], capture_output=True, timeout=timeout)
|
||||
except subprocess.TimeoutExpired:
|
||||
_log.warning(f"adb {' '.join(args)} 超时 {_ADB_TIMEOUT}s")
|
||||
_log.warning(f"adb {' '.join(args)} 超时 {timeout}s")
|
||||
return ""
|
||||
return _decode(r)
|
||||
|
||||
@@ -157,16 +158,18 @@ def _try_connect(remote_adb_url, retries):
|
||||
return False
|
||||
|
||||
|
||||
def adb_connect_light(remote_adb_url):
|
||||
"""轻量 adb connect(扫描专用):单次尝试,不重试,绝不 kill-server。
|
||||
def adb_connect_light(remote_adb_url, timeout=5):
|
||||
"""轻量 adb connect(扫描/验证专用):单次尝试,不重试,绝不 kill-server。
|
||||
|
||||
与 adb_connect 的区别:
|
||||
- 不重试:失败立即返回 False
|
||||
- 不 kill-server:避免断开其他 worker 正在使用的 ADB 连接
|
||||
- 短超时(默认 5s):验证场景(设备发现)连不上的主机快速放弃,
|
||||
避免每台卡 30s 拖慢整轮发现并长时间占用全局 adb 锁
|
||||
用于前台 App 扫描等非关键路径,连不上就跳过,不影响正在运行的任务。
|
||||
"""
|
||||
with _ADB_LOCK:
|
||||
out = _adb("connect", remote_adb_url)
|
||||
out = _adb("connect", remote_adb_url, timeout=timeout)
|
||||
if "connected" in out.lower() and "failed" not in out.lower():
|
||||
return True
|
||||
return False
|
||||
|
||||
Reference in New Issue
Block a user