fix(wifi-adb): force openscreen mdns backend for scan discovery

This commit is contained in:
Your Name committed 2026-06-01 09:49:32 +08:00
1 parent f76232f2fc
commit e33b42597c
2 files changed
+21

No files matched your search

+6
View File
@@ -9,6 +9,7 @@
from __future__ import annotations
import ipaddress
import os
import re
import socket
import subprocess
@@ -386,6 +387,10 @@ def scan_open_ports(
def _run_adb(adb_exe: str, args: list[str], timeout: float = 5.0) -> tuple[int, str]:
"""运行 adb 命令,返回 (returncode, stdout+stderr)。"""
env = os.environ.copy()
# Windows 常见:Bonjour backend 无 daemon,mDNS 发现始终为空。
# 默认强制 openscreen,除非用户显式覆盖。
env.setdefault("ADB_MDNS_OPENSCREEN", "1")
try:
proc = subprocess.run(
[adb_exe, *args],
@@ -395,6 +400,7 @@ def _run_adb(adb_exe: str, args: list[str], timeout: float = 5.0) -> tuple[int,
errors="replace",
check=False,
timeout=timeout,
env=env,
)
except subprocess.TimeoutExpired:
return -1, "timeout"
+15
View File
@@ -276,6 +276,21 @@ garbage line
assert scan.discover_mdns_targets("/adb") == []
class TestRunAdbEnv:
def test_sets_openscreen_mdns_by_default(self):
called = {}
def fake_run(*args, **kwargs):
called["env"] = kwargs.get("env", {})
return _proc("", "", 0)
with patch("subprocess.run", side_effect=fake_run):
scan._run_adb("/adb", ["mdns", "services"])
env = called.get("env", {})
assert env.get("ADB_MDNS_OPENSCREEN") == "1"
# ============================================================
# discover_adb_devices —— 主入口集成测试
# ============================================================