MCPcopy
hub / github.com/zai-org/Open-AutoGLM / ADBConnection

Class ADBConnection

phone_agent/adb/connection.py:31–328  ·  view source on GitHub ↗

Manages ADB connections to Android devices. Supports USB, WiFi, and remote TCP/IP connections. Example: >>> conn = ADBConnection() >>> # Connect to remote device >>> conn.connect("192.168.1.100:5555") >>> # List devices >>> devices = conn.list_d

Source from the content-addressed store, hash-verified

29
30
31class ADBConnection:
32 """
33 Manages ADB connections to Android devices.
34
35 Supports USB, WiFi, and remote TCP/IP connections.
36
37 Example:
38 >>> conn = ADBConnection()
39 >>> # Connect to remote device
40 >>> conn.connect("192.168.1.100:5555")
41 >>> # List devices
42 >>> devices = conn.list_devices()
43 >>> # Disconnect
44 >>> conn.disconnect("192.168.1.100:5555")
45 """
46
47 def __init__(self, adb_path: str = "adb"):
48 """
49 Initialize ADB connection manager.
50
51 Args:
52 adb_path: Path to ADB executable.
53 """
54 self.adb_path = adb_path
55
56 def connect(self, address: str, timeout: int = 10) -> tuple[bool, str]:
57 """
58 Connect to a remote device via TCP/IP.
59
60 Args:
61 address: Device address in format "host:port" (e.g., "192.168.1.100:5555").
62 timeout: Connection timeout in seconds.
63
64 Returns:
65 Tuple of (success, message).
66
67 Note:
68 The remote device must have TCP/IP debugging enabled.
69 On the device, run: adb tcpip 5555
70 """
71 # Validate address format
72 if ":" not in address:
73 address = f"{address}:5555" # Default ADB port
74
75 try:
76 result = subprocess.run(
77 [self.adb_path, "connect", address],
78 capture_output=True,
79 text=True,
80 timeout=timeout,
81 )
82
83 output = result.stdout + result.stderr
84
85 if "connected" in output.lower():
86 return True, f"Connected to {address}"
87 elif "already connected" in output.lower():
88 return True, f"Already connected to {address}"

Callers 3

example_remote_deviceFunction · 0.90
quick_connectFunction · 0.85
list_devicesFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected