Skip to content

Commit b4dd78a

Browse files
committed
fix: launch开头自动检测设备+锁定serial,_adb_cmd统一用_adb_args()
根因:config.device_name为空时,launch之前的_keep_screen_awake和force-stop 都不带-s参数,多设备环境下adb命令可能发到错误设备。 修复: 1. launch开头调用check_device()自动锁定第一台设备serial 2. _adb_cmd()改为使用_adb_args()统一获取带serial的前缀 3. 确保launch全流程(亮屏/force-stop/Session创建/APP启动)都指向正确设备
1 parent 9b464a7 commit b4dd78a

1 file changed

Lines changed: 12 additions & 4 deletions

File tree

src/controller/android.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -414,6 +414,17 @@ async def launch(self) -> None:
414414
await self._launch_ios()
415415
return
416416

417+
# 多设备环境自动检测:如果没有指定device_name,先获取设备列表并锁定第一台
418+
if not self._config.device_name:
419+
try:
420+
dev_result = await self.check_device()
421+
if dev_result.get("ok") and dev_result.get("devices"):
422+
self._config.device_name = dev_result["devices"][0]
423+
self._device.extra["serial"] = self._config.device_name
424+
logger.info("自动锁定设备: {}", self._config.device_name)
425+
except Exception:
426+
pass
427+
417428
capabilities = {
418429
"platformName": self._config.platform_name,
419430
"appium:automationName": self._config.automation_name,
@@ -1499,10 +1510,7 @@ def _grant():
14991510

15001511
def _adb_cmd(self, *args: str) -> str:
15011512
"""执行adb命令并返回stdout。"""
1502-
cmd = ["adb"]
1503-
serial = self._config.device_name
1504-
if serial:
1505-
cmd.extend(["-s", serial])
1513+
cmd = self._adb_args()
15061514
cmd.extend(args)
15071515
try:
15081516
result = subprocess.run(cmd, capture_output=True, text=True, timeout=10)

0 commit comments

Comments
 (0)