| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748 |
- import subprocess
- from tools import loggerKit
- # 检查app运行状态
- def is_app_running(device_id, package_name):
- # 执行 adb shell pidof 命令检测应用程序是否运行
- command = ['adb', '-s', device_id, 'shell', 'pidof', package_name]
- result = subprocess.run(command, capture_output=True, text=True)
- # 检查命令执行结果
- if result.returncode == 0 and result.stdout.strip().isdigit():
- return True
- else:
- return False
- # 检查app运行状态
- def check_app_running(device_id, package_name):
- # 执行 adb shell pidof 命令检测应用程序是否运行
- try:
- command = ['adb', '-s', device_id, 'shell', 'pidof', package_name]
- result = subprocess.check_output(command, stderr=subprocess.STDOUT, text=True)
- return result.strip().isdigit()
- except subprocess.CalledProcessError as e:
- loggerKit.error("Failed to check if app {0} is running on device {1}, 异常信息:{2}", package_name, device_id,
- e.output)
- return True
- # 检查app运行状态
- # check app运行状态
- def check_app_status(device_id, package_name):
- try:
- # Execute adb command to check if the app process is running
- command = ['adb', '-s', device_id, 'shell', 'pidof', package_name]
- result = subprocess.run(command, capture_output=True, text=True, check=True)
- # Check the return code to determine if the app process is running
- if result.returncode == 0:
- return True
- else:
- loggerKit.error("app {0} 未运行 on device {1}", package_name, device_id)
- return False
- except subprocess.CalledProcessError as e:
- loggerKit.error("Failed to check if app {0} is running on device {1}, 异常信息:{2}", package_name, device_id,
- e)
- return False
|