Skip to content

Commit cb0ed25

Browse files
feat: multi-device ADB executor
1 parent 75b0565 commit cb0ed25

1 file changed

Lines changed: 38 additions & 0 deletions

File tree

multi_adb.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#!/usr/bin/env python3
2+
"""multi_adb.py -- Run ADB command on all connected devices in parallel"""
3+
import subprocess, threading, sys, time
4+
5+
def get_devices():
6+
r = subprocess.run("adb devices", shell=True, capture_output=True, text=True)
7+
return [l.split()[0] for l in r.stdout.splitlines()[1:] if l.strip() and "device" in l]
8+
9+
def run_on_device(serial, cmd, results):
10+
r = subprocess.run(f"adb -s {serial} shell {cmd}", shell=True, capture_output=True, text=True)
11+
results[serial] = r.stdout.strip()
12+
13+
def main():
14+
if len(sys.argv) < 2:
15+
print("Usage: python3 multi_adb.py <adb command>")
16+
print("Example: python3 multi_adb.py 'getprop ro.build.version.release'")
17+
sys.exit(1)
18+
19+
cmd = " ".join(sys.argv[1:])
20+
devices = get_devices()
21+
if not devices:
22+
print("No devices connected.")
23+
return
24+
25+
print(f"Running on {len(devices)} device(s): {cmd}\n")
26+
results = {}
27+
threads = [threading.Thread(target=run_on_device, args=(d, cmd, results)) for d in devices]
28+
for t in threads:
29+
t.start()
30+
for t in threads:
31+
t.join()
32+
33+
for serial in devices:
34+
print(f"[{serial}]")
35+
print(f" {results.get(serial, '(timeout)')}")
36+
37+
if __name__ == "__main__":
38+
main()

0 commit comments

Comments
 (0)