feat: Linux 真实实现层 — 从存根库变为可用生产力工具
新增 _linux_impl.py (800+行): - LinuxNetwork: 真实IP/接口/DNS/网关/MAC (ip命令+/proc/net) - LinuxBluetooth: 真实蓝牙状态/扫描/配对/连接 (bluetoothctl) - LinuxSensors: 真实温度/CPU频率/风扇 (/sys/class/hwmon) - LinuxAudio: 真实音量控制/静音 (amixer) - LinuxClipboard: 真实剪贴板读写 (xclip+tkinter回退) - LinuxPower: 真实CPU/内存/电池 (psutil+/sys/class/power_supply) - LinuxLocation: 真实IP地理定位 (ip-api.com) - LinuxNotify: 真实桌面通知 (notify-send) - LinuxDisplay: 真实屏幕尺寸/截屏/鼠标位置 (xdotool+X11) - LinuxUIAutomation: 真实点击/输入/按键/滚动 (xdotool) - LinuxCamera: 真实摄像头拍照 (opencv/V4L2) - LinuxProcess: 真实进程列表/系统信息/应用管理 (psutil+/proc) - LinuxShell: 真实命令执行 (subprocess) 改造10+核心类使用Linux真实实现: - BluetoothAdapter/SensorManager/AudioManager - ConnectivityManager/WifiManager/TelephonyManager - LocationManager/PowerManager/BatteryManager/Build - ActivityManager/Activity/Toast/Display/ClipboardManager - NotificationManager 15项真实行为测试全部通过: - 真实IP: 10.60.218.244 - 真实位置: 北京 39.9042, 116.407 - 真实主机名: work-41-vci-g427c - 真实内核: 5.15.120.byteatom-ck.14 - 真实内存: 1.8GB/3.8GB - 真实进程列表
This commit is contained in:
1 parent
8c3bd3c415
commit
690022cea3
17 files changed
+2083
-8
No files matched your search
@@ -19,6 +19,12 @@ from .._core import (
|
||||
_sdcard_root, _app_data_dir, _package_name,
|
||||
)
|
||||
|
||||
try:
|
||||
from .._linux_impl import IS_LINUX, LinuxNotify, LinuxShell, LinuxProcess, LinuxDisplay, LinuxUIAutomation, LinuxPower
|
||||
_USE_LINUX = IS_LINUX
|
||||
except ImportError:
|
||||
_USE_LINUX = False
|
||||
|
||||
|
||||
# ═══════════════════════════════════════════════════════════════
|
||||
# Intent
|
||||
@@ -834,10 +840,16 @@ class NotificationManager(Stub):
|
||||
|
||||
def notify(self, id_: int, notification: Notification):
|
||||
self._notifications[id_] = notification
|
||||
sys.stderr.write(
|
||||
f"[NotificationManager] notify id={id_}: "
|
||||
f"title={notification._title} text={notification._text}\n"
|
||||
)
|
||||
if _USE_LINUX:
|
||||
title = getattr(notification, "_title", "") or ""
|
||||
text = getattr(notification, "_text", "") or ""
|
||||
if title or text:
|
||||
LinuxNotify.send(title, text)
|
||||
else:
|
||||
sys.stderr.write(
|
||||
f"[NotificationManager] notify id={id_}: "
|
||||
f"title={notification._title} text={notification._text}\n"
|
||||
)
|
||||
|
||||
def notifyAsPackage(self, package_name: str, tag: Optional[str], id_: int, notification: Notification):
|
||||
self.notify(id_, notification)
|
||||
@@ -1821,6 +1833,48 @@ class Activity(Stub):
|
||||
def getTheme(self):
|
||||
return getattr(self, '_theme', 0)
|
||||
|
||||
def getDeviceInfo(self):
|
||||
"""获取设备信息"""
|
||||
if _USE_LINUX:
|
||||
return LinuxProcess.get_system_info()
|
||||
return {}
|
||||
|
||||
def executeShell(self, command):
|
||||
"""执行 Shell 命令"""
|
||||
if _USE_LINUX:
|
||||
return LinuxShell.exec(command)
|
||||
return {"success": False, "output": "Shell not available"}
|
||||
|
||||
def screenshot(self, path=None):
|
||||
"""截屏"""
|
||||
if _USE_LINUX:
|
||||
return LinuxDisplay.screenshot(path)
|
||||
return None
|
||||
|
||||
def getScreenSize(self):
|
||||
"""获取屏幕尺寸"""
|
||||
if _USE_LINUX:
|
||||
return LinuxDisplay.get_screen_size()
|
||||
return (1920, 1080)
|
||||
|
||||
def click(self, x, y):
|
||||
"""点击屏幕坐标"""
|
||||
if _USE_LINUX:
|
||||
return LinuxUIAutomation.click(x, y)
|
||||
return False
|
||||
|
||||
def typeText(self, text):
|
||||
"""输入文本"""
|
||||
if _USE_LINUX:
|
||||
return LinuxUIAutomation.type_text(text)
|
||||
return False
|
||||
|
||||
def pressKey(self, key):
|
||||
"""按键"""
|
||||
if _USE_LINUX:
|
||||
return LinuxUIAutomation.press_key(key)
|
||||
return False
|
||||
|
||||
|
||||
# ═══════════════════════════════════════════════════════════════
|
||||
# Service
|
||||
@@ -2009,9 +2063,13 @@ class ActivityManager(Stub):
|
||||
self._memory_info = self.MemoryInfo()
|
||||
|
||||
def getMemoryInfo(self) -> "ActivityManager.MemoryInfo":
|
||||
if _USE_LINUX:
|
||||
return LinuxPower.get_memory_info()
|
||||
return self._memory_info
|
||||
|
||||
def getRunningAppProcesses(self) -> Optional[List["ActivityManager.RunningAppProcessInfo"]]:
|
||||
if _USE_LINUX:
|
||||
return LinuxProcess.list_processes()
|
||||
return []
|
||||
|
||||
def killBackgroundProcesses(self, package_name: str):
|
||||
|
||||
Reference in new issue
Block a user