ConnectionTracer
when connected devices changed, do sth :)
How it works?
Use a socket to connect adb server. Nothing about subprocess
or os.system
.
View socket2adb for detail.
Installation
pip install ConnectionTracer
How to use?
import ConnectionTracer
import time
# also, you can custom port and host
ConnectionTracer.config.PORT = 5037
# bind hook function
def hook_function(devices: set):
print(devices)
ConnectionTracer.start(hook_function)
# also you can directly run:
# ConnectionTracer.start(hook_function, port=8080)
print('tracer already started :)')
# get connection status
print('now status: ', ConnectionTracer.get_status())
# do something else you want
time.sleep(30)
# stop it
ConnectionTracer.stop()
print('tracer stopped')
When connected devices changed, hook_function
would be called.
More?
Code is quite simple, you can view 100-lines-ver for detail.