autool/DroidBot/platforms/android/utils.py
2026-06-17 19:44:18 +08:00

33 lines
763 B
Python

import re
import subprocess
import hashlib
def get_available_devices():
"""
Get a list of device serials connected via adb
:return: list of str, each str is a device serial number
"""
try:
r = subprocess.check_output(["adb", "devices"])
except Exception:
return []
if not isinstance(r, str):
r = r.decode()
devices = []
for line in r.splitlines():
segs = line.strip().split()
if len(segs) == 2 and segs[1] == "device":
devices.append(segs[0])
return devices
def md5(input_str):
"""
Calculate MD5 hash of a string
:param input_str: input string
:return: MD5 hex digest
"""
return hashlib.md5(input_str.encode('utf-8')).hexdigest()