forked from cr4n5/XiaoYuanKouSuan
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathadb_manager.py
25 lines (22 loc) · 1.06 KB
/
adb_manager.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
import subprocess
class ADBManager:
@staticmethod
def check_adb_installed():
try:
result = subprocess.run(["adb", "devices"], stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True)
if result.returncode != 0:
raise RuntimeError(result.stderr)
except FileNotFoundError:
raise RuntimeError("ADB 未找到,请先安装 ADB 工具。")
@staticmethod
def connect(adb_ip):
result = subprocess.run(["adb", "connect", adb_ip], stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True)
if "connected" not in result.stdout:
raise RuntimeError(result.stderr)
print(f"已连接到 {adb_ip}")
@staticmethod
def clear_and_restart_app(package_name):
subprocess.run(["adb", "shell", "am", "force-stop", package_name])
subprocess.run(["adb", "shell", "pm", "clear", package_name])
subprocess.run(["adb", "shell", "am", "start", "-n", f"{package_name}/.activity.RouterActivity"])
print(f"已清除缓存并重启应用: {package_name}")