fix: 启动时恢复已保存的 Android 设备 (#26)

This commit is contained in:
chengma
2026-08-07 14:53:28 +08:00
parent e40ce5a13c
commit dc9b000a36
4 changed files with 253 additions and 14 deletions
@@ -72,6 +72,58 @@ USB-002 unauthorized usb:1-2 transport_id:3
self.assertEqual(len(commands), 2)
self.assertIn("ro.build.version.release", commands[1])
def test_restore_saved_wifi_connects_before_search(self):
commands = []
def runner(command, _timeout):
command = list(command)
commands.append(command)
if command[:2] == ["adb", "connect"]:
return completed(
command,
"already connected to 192.168.0.173:5555\n",
)
if command == ["adb", "devices", "-l"]:
return completed(
command,
"List of devices attached\n"
"192.168.0.173:5555 device model:Phone\n",
)
return completed(command, "14\n")
devices = AndroidDeviceService(runner).restore_saved_device(
"192.168.0.173:5555"
)
self.assertEqual(devices[0].serial, "192.168.0.173:5555")
self.assertEqual(
commands[0],
["adb", "connect", "192.168.0.173:5555"],
)
def test_restore_saved_usb_only_searches(self):
commands = []
def runner(command, _timeout):
command = list(command)
commands.append(command)
if command == ["adb", "devices", "-l"]:
return completed(
command,
"List of devices attached\n"
"USB-001 device model:Phone\n",
)
return completed(command, "14\n")
devices = AndroidDeviceService(runner).restore_saved_device(
"USB-001"
)
self.assertEqual(devices[0].serial, "USB-001")
self.assertFalse(
any(command[:2] == ["adb", "connect"] for command in commands)
)
def test_missing_model_is_read_from_device(self):
def runner(command, _timeout):
if command == ["adb", "devices", "-l"]: