-
-
Save Chubukov-Aleksey/9fb690b0ec4b749c3bb29547689c1dcf to your computer and use it in GitHub Desktop.
Connect Wireless Debug from Terminal on Android11
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
""" | |
Android11 | |
Pair and connect devices for wireless debug on terminal | |
python-zeroconf: A pure python implementation of multicast DNS service discovery | |
https://github.com/jstasiak/python-zeroconf | |
""" | |
import subprocess | |
import logging | |
from zeroconf import ServiceBrowser, Zeroconf | |
NAME = "debug" | |
PASS = "900594" | |
FORMAT_QR = "WIFI:T:ADB;S:%s;P:%s;;" | |
CMD_SHOW = "qrencode -t UTF8 '%s'" | |
CMD_PAIR = "adb pair %s:%s %s" | |
CMD_CONNECT = "adb connect %s:%s" | |
CMD_DEVICES = "adb devices -l" | |
logging.basicConfig(level='DEBUG') | |
log = logging.getLogger('debug_from_qr') | |
class BaseListener: | |
def __init__(self, zeroconf=None): | |
self.zeroconf = zeroconf | |
self.services = dict() | |
def run(self, info): | |
raise NotImplementedError | |
def add_service(self, zeroconf, type, name): | |
log.debug("Service %s added.", name) | |
info = zeroconf.get_service_info(type, name) | |
log.info("service info: %s\n" % info) | |
self.run(info) | |
def update_service(self, zeroconf, type, name): | |
log.debug("Service %s changed.", name) | |
info = zeroconf.get_service_info(type, name) | |
log.info("service info: %s\n" % info) | |
self.run(info) | |
def remove_service(self, zeroconf, type, name): | |
log.debug("Service %s removed.", name) | |
class ConnectListener(BaseListener): | |
def run(self, info): | |
cmd = CMD_CONNECT % (info.server, info.port) | |
log.debug(cmd) | |
subprocess.run(cmd, shell=True) | |
class PairingListener(BaseListener): | |
def run(self, info): | |
cmd = CMD_PAIR % (info.server, info.port, PASS) | |
log.debug(cmd) | |
subprocess.run(cmd, shell=True) | |
def main(): | |
text = FORMAT_QR % (NAME, PASS) | |
subprocess.run(CMD_SHOW % text, shell=True) | |
print("Scan QR code to pair new devices.") | |
print("[Developer options]-[Wireless debugging]-[Pair device with QR code]") | |
zeroconf = Zeroconf() | |
browser = ServiceBrowser(zeroconf, "_adb-tls-pairing._tcp.local.", PairingListener()) | |
browser2 = ServiceBrowser(zeroconf, "_adb-tls-connect._tcp.local.", ConnectListener()) | |
try: | |
input("Press enter to exit...\n\n") | |
finally: | |
zeroconf.close() | |
subprocess.run(CMD_DEVICES, shell=True) | |
# FIXME: implement connection after pairing | |
if __name__ == '__main__': | |
main() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment