feat: 内置并统一使用项目 ADB (#149)

This commit is contained in:
chengma
2026-08-11 12:01:07 +08:00
parent 56b1a46c5c
commit 8f2037db2f
21 changed files with 355 additions and 46 deletions
+13 -2
View File
@@ -16,6 +16,8 @@ import xml.etree.ElementTree as ET
from collections.abc import Callable
from typing import Any
from src.adb_runtime import configure_bundled_adb_environment
PDD_PACKAGE_NAME = "com.xunmeng.pinduoduo"
READY_MARKERS = ("发起拼单", "立即购买", "单独购买", "免拼购买", "快要抢光")
@@ -59,11 +61,20 @@ def wait_goods_ready(device: Any, first_xml: str, timeout: float) -> None:
def measure_once(serial: str, goods_url: str, cold: bool) -> dict[str, int]:
adb_executable = str(configure_bundled_adb_environment())
import uiautomator2 as u2
if cold:
subprocess.run(
["adb", "-s", serial, "shell", "am", "force-stop", PDD_PACKAGE_NAME],
[
adb_executable,
"-s",
serial,
"shell",
"am",
"force-stop",
PDD_PACKAGE_NAME,
],
check=True,
capture_output=True,
text=True,
@@ -80,7 +91,7 @@ def measure_once(serial: str, goods_url: str, cold: bool) -> dict[str, int]:
_, result["adb_device_check"] = measure_call(
"adb_device_check",
lambda: subprocess.run(
["adb", "-s", serial, "get-state"],
[adb_executable, "-s", serial, "get-state"],
check=True,
capture_output=True,
text=True,
+4 -2
View File
@@ -26,6 +26,7 @@ from src.pdd_page_classifier import ( # noqa: E402
PAGE_HOME,
classify_pdd_page,
)
from src.adb_runtime import configure_bundled_adb_environment # noqa: E402
TEST_URL = "https://mobile.yangkeduo.com/goods.html"
@@ -143,15 +144,16 @@ def run_diagnostic(
address = str(device_address or "").strip()
if not address:
raise ValueError("必须提供 Android 设备地址")
adb_executable = str(configure_bundled_adb_environment())
adb_runner(
["adb", "-s", address, "get-state"],
[adb_executable, "-s", address, "get-state"],
check=True,
capture_output=True,
text=True,
)
adb_runner(
[
"adb", "-s", address, "shell", "am", "start",
adb_executable, "-s", address, "shell", "am", "start",
"-a", "android.intent.action.VIEW", "-d", TEST_URL,
],
check=True,