feat: 新增设备画面截图、列表复选框/排序/批量停止,修复端口绑定失败

This commit is contained in:
2026-08-07 15:08:36 +08:00
parent bce48fc137
commit 0fe2a2fc5f
7 changed files with 355 additions and 55 deletions
+29
View File
@@ -124,6 +124,35 @@ def adb_disconnect(remote_adb_url):
pass
def screenshot(serial, timeout=5):
"""获取设备当前画面截图(PNG bytes)。
用 `adb exec-out -s <serial> shell screencap -p`,只读操作,
不抢占 u2 的 atx-agent 通道,任务运行中调用安全。
返回 (ok, png_bytes_or_errmsg)。
"""
if not serial:
return False, "缺少 serial"
# 先尝试连一下(任务运行中设备已 connect,这里是幂等的)
if not adb_connect_light(serial):
return False, "adb connect 失败"
try:
r = subprocess.run(
[ADB_PATH, "-s", serial, "exec-out", "screencap", "-p"],
capture_output=True, timeout=timeout,
)
# PNG 文件头:\x89PNG
if r.stdout and r.stdout[:4] == b"\x89PNG":
return True, r.stdout
# 失败时 stdout 可能为空,看 stderr
err = (r.stderr or b"").decode("utf-8", errors="replace").strip()
return False, err or "截图失败(设备可能离线)"
except subprocess.TimeoutExpired:
return False, "截图超时"
except Exception as e:
return False, str(e)
def identify_device(serial, duration=3):
"""让设备响铃以供识别(直连 serial,不经过 STF)。