- test_network.py: 网络功能测试 (IP/DNS/WiFi/流量) - test_system.py: 系统工具测试 (设备信息/电源/进程) - test_android_api.py: Android API 综合测试 (Intent/集合/文件/Base64/数学/日历) - 所有测试通过
98 lines
3.0 KiB
Python
98 lines
3.0 KiB
Python
"""
|
|
系统工具测试脚本 - 基于 Android-pyApi
|
|
模拟 Operit 的 system_tools.js 功能
|
|
"""
|
|
|
|
import sys
|
|
import os
|
|
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
|
|
|
from android_pyapi import (
|
|
Build, PowerManager, BatteryManager, ActivityManager,
|
|
Environment, Log
|
|
)
|
|
from android_pyapi._windows_impl import (
|
|
WindowsPower, WindowsProcess, WindowsDisplay, WindowsShell
|
|
)
|
|
|
|
|
|
def test_system():
|
|
"""测试系统工具功能"""
|
|
print("=" * 60)
|
|
print("Android-pyApi 系统工具测试")
|
|
print("=" * 60)
|
|
|
|
# 1. 设备信息 (Build)
|
|
print("\n[1] 设备信息 (Build):")
|
|
print(f" MODEL: {Build.MODEL}")
|
|
print(f" MANUFACTURER: {Build.MANUFACTURER}")
|
|
print(f" BRAND: {Build.BRAND}")
|
|
print(f" DEVICE: {Build.DEVICE}")
|
|
print(f" PRODUCT: {Build.PRODUCT}")
|
|
print(f" FINGERPRINT: {Build.FINGERPRINT}")
|
|
|
|
# 2. 系统信息
|
|
print("\n[2] 系统信息:")
|
|
sys_info = WindowsProcess.get_system_info()
|
|
print(f" 主机名: {sys_info.get('hostname', 'N/A')}")
|
|
print(f" 平台: {sys_info.get('platform', 'N/A')}")
|
|
print(f" 版本: {sys_info.get('windows_version', 'N/A')}")
|
|
print(f" 架构: {sys_info.get('arch', 'N/A')}")
|
|
print(f" Python: {sys_info.get('python', 'N/A')}")
|
|
if 'cpu_count' in sys_info:
|
|
print(f" CPU 核心: {sys_info['cpu_count']}")
|
|
if 'memory_total' in sys_info:
|
|
print(f" 内存总量: {sys_info['memory_total'] / 1024 / 1024 / 1024:.2f} GB")
|
|
|
|
# 3. 电源信息
|
|
print("\n[3] 电源信息:")
|
|
battery = WindowsPower.get_battery_info()
|
|
print(f" 电池存在: {battery['present']}")
|
|
print(f" 电量: {battery['level']}%")
|
|
print(f" 状态: {battery['status']}")
|
|
|
|
power = WindowsPower.get_power_status()
|
|
print(f" 充电中: {power['is_charging']}")
|
|
|
|
# 4. CPU 和内存
|
|
print("\n[4] CPU 和内存:")
|
|
cpu = WindowsPower.get_cpu_usage()
|
|
print(f" CPU 使用率: {cpu}%")
|
|
|
|
mem = WindowsPower.get_memory_info()
|
|
print(f" 内存使用率: {mem['percent']}%")
|
|
print(f" 可用内存: {mem['available'] / 1024 / 1024 / 1024:.2f} GB")
|
|
|
|
# 5. 显示信息
|
|
print("\n[5] 显示信息:")
|
|
w, h = WindowsDisplay.get_screen_size()
|
|
print(f" 屏幕尺寸: {w}x{h}")
|
|
|
|
x, y = WindowsDisplay.get_mouse_position()
|
|
print(f" 鼠标位置: ({x}, {y})")
|
|
|
|
# 6. 进程列表
|
|
print("\n[6] 进程列表 (前10个):")
|
|
procs = WindowsProcess.list_processes()
|
|
for p in procs[:10]:
|
|
print(f" - {p.get('name', 'N/A')} (PID: {p.get('pid', 'N/A')})")
|
|
|
|
# 7. 运行中的应用
|
|
print("\n[7] 运行中的应用 (前5个):")
|
|
apps = WindowsProcess.get_running_apps()
|
|
for app in apps[:5]:
|
|
print(f" - {app.get('name', 'N/A')}")
|
|
|
|
# 8. Shell 命令测试
|
|
print("\n[8] Shell 命令测试:")
|
|
result = WindowsShell.exec("echo Hello from Android-pyApi!")
|
|
print(f" 输出: {result.get('stdout', 'N/A')}")
|
|
|
|
print("\n" + "=" * 60)
|
|
print("测试完成!")
|
|
print("=" * 60)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
test_system()
|