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:
shuiyu1123 committed 2026-06-24 15:40:49 +00:00
1 parent 8c3bd3c415
commit 690022cea3
17 files changed
+2083 -8

No files matched your search

+82
View File
@@ -10,6 +10,13 @@ from typing import Any, Callable, Dict, List, Optional, Tuple
from .._core import Stub, AndroidOnlyError, android_context, HAS_PIL
# Linux 真实实现导入
try:
from .._linux_impl import IS_LINUX, LinuxBluetooth, LinuxSensors, HAS_BLUETOOTHCTL
_USE_LINUX = IS_LINUX
except ImportError:
_USE_LINUX = False
# ═══════════════════════════════════════════════════════════════
# Sensor
@@ -251,14 +258,89 @@ class SensorManager(Stub):
self._sensors[type_] = Sensor(type_)
def getDefaultSensor(self, type_: int) -> Optional[Sensor]:
if _USE_LINUX:
sensor = self._build_linux_sensor(type_)
if sensor is not None:
return sensor
return self._sensors.get(type_)
def _build_linux_sensor(self, type_: int) -> Optional[Sensor]:
"""根据 Linux 真实传感器数据构造 Sensor 对象"""
try:
if type_ == Sensor.TYPE_AMBIENT_TEMPERATURE:
temps = LinuxSensors.get_temperatures()
if temps:
t = temps[0]
return Sensor(Sensor.TYPE_AMBIENT_TEMPERATURE,
name=t.get("name", "Linux Temperature"),
vendor="Linux", resolution=0.01,
max_range=125.0, power=0.0, min_delay=1000)
return None
if type_ == Sensor.TYPE_LIGHT:
light = LinuxSensors.get_light_level()
if light is not None:
return Sensor(Sensor.TYPE_LIGHT, name="Linux Light Sensor",
vendor="Linux", resolution=0.001,
max_range=40000.0, power=0.0, min_delay=1000)
return None
except Exception:
return None
return None
def getSensorList(self, type_: int) -> List[Sensor]:
if _USE_LINUX:
return self._get_linux_sensor_list(type_)
if type_ == -1: # ALL
return list(self._sensors.values())
sensor = self._sensors.get(type_)
return [sensor] if sensor else []
def _get_linux_sensor_list(self, type_: int) -> List[Sensor]:
"""从 Linux 真实传感器数据生成传感器列表"""
sensors: List[Sensor] = []
try:
if type_ == -1 or type_ == Sensor.TYPE_AMBIENT_TEMPERATURE:
for t in LinuxSensors.get_temperatures():
sensors.append(Sensor(
Sensor.TYPE_AMBIENT_TEMPERATURE,
name=t.get("name", "Linux Temperature"),
vendor="Linux", resolution=0.01,
max_range=125.0, power=0.0, min_delay=1000))
if type_ == -1 or type_ == Sensor.TYPE_LIGHT:
light = LinuxSensors.get_light_level()
if light is not None:
sensors.append(Sensor(
Sensor.TYPE_LIGHT, name="Linux Light Sensor",
vendor="Linux", resolution=0.001,
max_range=40000.0, power=0.0, min_delay=1000))
# CPU 频率作为附加传感器 (映射到压力传感器类型以承载真实数据)
if type_ == -1 or type_ == Sensor.TYPE_PRESSURE:
for f in LinuxSensors.get_cpu_frequency():
sensors.append(Sensor(
Sensor.TYPE_PRESSURE,
name=f"CPU{f.get('cpu', 0)} Frequency",
vendor="Linux", resolution=1.0,
max_range=10000.0, power=0.0, min_delay=1000))
# 风扇转速作为附加传感器 (映射到相对湿度类型以承载真实数据)
if type_ == -1 or type_ == Sensor.TYPE_RELATIVE_HUMIDITY:
for fan in LinuxSensors.get_fan_speeds():
sensors.append(Sensor(
Sensor.TYPE_RELATIVE_HUMIDITY,
name=f"Fan {fan.get('name', '')}",
vendor="Linux", resolution=1.0,
max_range=10000.0, power=0.0, min_delay=1000))
except Exception:
pass
# 若未取到真实数据则回退到模拟传感器
if not sensors:
if type_ == -1:
sensors = list(self._sensors.values())
else:
sensor = self._sensors.get(type_)
if sensor:
sensors = [sensor]
return sensors
def getSensors(self) -> List[Sensor]:
return list(self._sensors.values())