Pref: [ALAS] Connect all possible serial at once

(cherry picked from commit 14a3f57d789fba50297c1371934da82474d5690b)
This commit is contained in:
LmeSzinc 2024-08-11 00:44:23 +08:00
parent e89c8e7013
commit 58da4a7144

View File

@ -692,13 +692,9 @@ class Connection(ConnectionAttr):
# Brute force connect nearby ports to handle serial switches
if self.is_mumu12_family:
before = self.serial
for port_offset in [1, -1, 2, -2]:
port = self.port + port_offset
serial = self.serial.replace(str(self.port), str(port))
msg = self.adb_client.connect(serial)
logger.info(msg)
if 'connected' in msg:
break
serial_list = [self.serial.replace(str(self.port), str(self.port + offset))
for offset in [1, -1, 2, -2]]
self.adb_brute_force_connect(serial_list)
self.detect_device()
if self.serial != before:
return True
@ -711,6 +707,25 @@ class Connection(ConnectionAttr):
self.detect_device()
return False
def adb_brute_force_connect(self, serial_list):
"""
Args:
serial_list (list[str]):
"""
import asyncio
ev = asyncio.new_event_loop()
def _connect(serial):
msg = self.adb_client.connect(serial)
logger.info(msg)
return msg
async def connect():
tasks = [ev.run_in_executor(None, _connect, serial) for serial in serial_list]
await asyncio.gather(*tasks)
ev.run_until_complete(connect())
@Config.when(DEVICE_OVER_HTTP=True)
def adb_connect(self):
# No adb connect if over http