feat: 新增 42 个 Android API 模块
新增模块覆盖: 系统层 (14): system, security, print, opengl, renderscript, transition, test, service_notification, service_controls, service_quicksettings, service_wallpaper, service_autofill, service_dreams, service_vr 应用层 (13): app_admin, app_backup, app_job, app_usage, app_role, app_people, appwidget, companion, credentials, mtp, sip, telecom, speech 硬件媒体层 (15): hardware_display, hardware_fingerprint, hardware_usb, hardware_input, media_audiofx, media_browse, media_session, media_tv, media_midi, media_projection, uwb, se, view_autofill, view_textclassifier, view_translation 总计 94 个模块,75,342 行代码
This commit is contained in:
1 parent
8ad62be068
commit
506f9ac725
43 files changed
+16704
-23
No files matched your search
@@ -0,0 +1,264 @@
|
||||
"""
|
||||
Android Service Wallpaper 组件 — WallpaperService, Engine, SurfaceHolder 等
|
||||
方法签名完全对齐 Android SDK (android.service.wallpaper 包)
|
||||
"""
|
||||
|
||||
import time
|
||||
from typing import Any, Callable, Dict, List, Optional, Tuple
|
||||
|
||||
from .._core import Stub, AndroidOnlyError
|
||||
|
||||
|
||||
# ═══════════════════════════════════════════════════════════════
|
||||
# SurfaceHolder
|
||||
# ═══════════════════════════════════════════════════════════════
|
||||
|
||||
class SurfaceHolder(Stub):
|
||||
"""SurfaceHolder — 表面持有者 (桌面存根)"""
|
||||
|
||||
# 表面类型
|
||||
SURFACE_TYPE_NORMAL = 0
|
||||
SURFACE_TYPE_HARDWARE = 1
|
||||
SURFACE_TYPE_GPU = 2
|
||||
SURFACE_TYPE_PUSH_BUFFERS = 3
|
||||
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
self._surface: Optional[Any] = None
|
||||
self._surface_frame: Optional[Any] = None
|
||||
self._surface_type: int = SurfaceHolder.SURFACE_TYPE_NORMAL
|
||||
self._fixed_size: Optional[Tuple[int, int]] = None
|
||||
self._format: int = 0 # PixelFormat.UNKNOWN
|
||||
self._callbacks: List[Any] = []
|
||||
|
||||
def getSurface(self) -> Any:
|
||||
"""获取 Surface"""
|
||||
return self._surface
|
||||
|
||||
def getSurfaceFrame(self) -> Any:
|
||||
return self._surface_frame
|
||||
|
||||
def isCreating(self) -> bool:
|
||||
return False
|
||||
|
||||
def setType(self, surface_type: int):
|
||||
self._surface_type = surface_type
|
||||
|
||||
def getType(self) -> int:
|
||||
return self._surface_type
|
||||
|
||||
def setFormat(self, format: int):
|
||||
self._format = format
|
||||
|
||||
def getFormat(self) -> int:
|
||||
return self._format
|
||||
|
||||
def setFixedSize(self, width: int, height: int):
|
||||
self._fixed_size = (width, height)
|
||||
|
||||
def setSizeFromLayout(self):
|
||||
pass
|
||||
|
||||
def addCallback(self, callback: Any):
|
||||
if callback not in self._callbacks:
|
||||
self._callbacks.append(callback)
|
||||
|
||||
def removeCallback(self, callback: Any):
|
||||
if callback in self._callbacks:
|
||||
self._callbacks.remove(callback)
|
||||
|
||||
def notifySurfaceCreated(self):
|
||||
for cb in self._callbacks:
|
||||
if hasattr(cb, 'surfaceCreated'):
|
||||
cb.surfaceCreated(self)
|
||||
|
||||
def notifySurfaceChanged(self, format: int, width: int, height: int):
|
||||
for cb in self._callbacks:
|
||||
if hasattr(cb, 'surfaceChanged'):
|
||||
cb.surfaceChanged(self, format, width, height)
|
||||
|
||||
def notifySurfaceDestroyed(self):
|
||||
for cb in self._callbacks:
|
||||
if hasattr(cb, 'surfaceDestroyed'):
|
||||
cb.surfaceDestroyed(self)
|
||||
|
||||
def lockCanvas(self) -> Any:
|
||||
"""锁定画布"""
|
||||
return None
|
||||
|
||||
def lockCanvas(self, dirty: Any) -> Any:
|
||||
"""锁定画布 (指定脏区域)"""
|
||||
return None
|
||||
|
||||
def unlockCanvasAndPost(self, canvas: Any):
|
||||
"""解锁并提交画布"""
|
||||
pass
|
||||
|
||||
def toString(self) -> str:
|
||||
size_str = (f"{self._fixed_size[0]}x{self._fixed_size[1]}"
|
||||
if self._fixed_size else "dynamic")
|
||||
return f"SurfaceHolder(size={size_str}, callbacks={len(self._callbacks)})"
|
||||
|
||||
def hashCode(self) -> int:
|
||||
return id(self) & 0x7FFFFFFF
|
||||
|
||||
def equals(self, other) -> bool:
|
||||
return self is other
|
||||
|
||||
|
||||
# ═══════════════════════════════════════════════════════════════
|
||||
# WallpaperService
|
||||
# ═══════════════════════════════════════════════════════════════
|
||||
|
||||
class WallpaperService(Stub):
|
||||
"""WallpaperService — 动态壁纸服务基类"""
|
||||
|
||||
# 服务接口
|
||||
SERVICE_INTERFACE = "android.service.wallpaper.WallpaperService"
|
||||
ACTION_LIVE_WALLPAPER_CHOOSER = (
|
||||
"android.service.wallpaper.LIVE_WALLPAPER_CHOOSER"
|
||||
)
|
||||
|
||||
# 元数据
|
||||
META_DATA_WALLPAPER = "android.service.wallpaper"
|
||||
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
|
||||
def onCreate(self):
|
||||
"""创建壁纸服务"""
|
||||
pass
|
||||
|
||||
def onCreateEngine(self) -> "WallpaperService.Engine":
|
||||
"""创建壁纸引擎"""
|
||||
return WallpaperService.Engine(self)
|
||||
|
||||
def onDestroy(self):
|
||||
"""销毁壁纸服务"""
|
||||
pass
|
||||
|
||||
def toString(self) -> str:
|
||||
return f"WallpaperService@{hex(id(self))}"
|
||||
|
||||
def hashCode(self) -> int:
|
||||
return id(self) & 0x7FFFFFFF
|
||||
|
||||
def equals(self, other) -> bool:
|
||||
return self is other
|
||||
|
||||
# ── Engine ──
|
||||
|
||||
class Engine(Stub):
|
||||
"""Engine — 壁纸引擎"""
|
||||
|
||||
def __init__(self, service: "WallpaperService" = None):
|
||||
super().__init__()
|
||||
self._service = service
|
||||
self._is_visible: bool = True
|
||||
self._is_created: bool = False
|
||||
self._surface_holder = SurfaceHolder()
|
||||
self._surface_holder.addCallback(self)
|
||||
self._offset: Tuple[float, float, float, float, float] = (0, 0, 0, 0, 0)
|
||||
self._x_ppw: float = 1.0
|
||||
self._y_ppw: float = 1.0
|
||||
self._desired_width: int = 0
|
||||
self._desired_height: int = 0
|
||||
self._touch_events_enabled: bool = False
|
||||
self._offset_notifications_enabled: bool = False
|
||||
self._draw_count: int = 0
|
||||
|
||||
def onCreate(self, surface_holder: SurfaceHolder):
|
||||
"""创建引擎"""
|
||||
self._is_created = True
|
||||
|
||||
def onSurfaceCreated(self, holder: SurfaceHolder):
|
||||
"""表面创建时回调"""
|
||||
pass
|
||||
|
||||
def onSurfaceDestroyed(self, holder: SurfaceHolder):
|
||||
"""表面销毁时回调"""
|
||||
pass
|
||||
|
||||
def onSurfaceChanged(self, holder: SurfaceHolder,
|
||||
format: int, width: int, height: int):
|
||||
"""表面尺寸变化时回调"""
|
||||
pass
|
||||
|
||||
def onDraw(self, canvas: Any):
|
||||
"""绘制壁纸"""
|
||||
self._draw_count += 1
|
||||
|
||||
def onOffsetsChanged(self, x_offset: float, y_offset: float,
|
||||
x_step: float, y_step: float,
|
||||
x_pixel_offset: int, y_pixel_offset: int):
|
||||
"""偏移量变化回调"""
|
||||
self._offset = (x_offset, y_offset, x_step, y_step)
|
||||
|
||||
def onTouchEvent(self, motion_event: Any):
|
||||
"""触摸事件回调"""
|
||||
pass
|
||||
|
||||
def onVisibilityChanged(self, visible: bool):
|
||||
"""可见性变化回调"""
|
||||
self._is_visible = visible
|
||||
|
||||
def setOffsetNotifications(self, x_ppw: float, y_ppw: float):
|
||||
"""设置偏移通知"""
|
||||
self._x_ppw = x_ppw
|
||||
self._y_ppw = y_ppw
|
||||
self._offset_notifications_enabled = True
|
||||
|
||||
def getSurfaceHolder(self) -> SurfaceHolder:
|
||||
"""获取表面持有者"""
|
||||
return self._surface_holder
|
||||
|
||||
def getDesiredMinimumWidth(self) -> int:
|
||||
return self._desired_width
|
||||
|
||||
def getDesiredMinimumHeight(self) -> int:
|
||||
return self._desired_height
|
||||
|
||||
def isVisible(self) -> bool:
|
||||
return self._is_visible
|
||||
|
||||
def isPreview(self) -> bool:
|
||||
return False
|
||||
|
||||
def setTouchEventsEnabled(self, enabled: bool):
|
||||
self._touch_events_enabled = enabled
|
||||
|
||||
def setCreateSurfaceFromSurfaceControlResult(self, result: Any):
|
||||
pass
|
||||
|
||||
def surfaceCreated(self, holder: SurfaceHolder):
|
||||
"""SurfaceHolder.Callback — 表面创建"""
|
||||
self.onSurfaceCreated(holder)
|
||||
|
||||
def surfaceChanged(self, holder: SurfaceHolder,
|
||||
format: int, width: int, height: int):
|
||||
"""SurfaceHolder.Callback — 表面变化"""
|
||||
self.onSurfaceChanged(holder, format, width, height)
|
||||
|
||||
def surfaceDestroyed(self, holder: SurfaceHolder):
|
||||
"""SurfaceHolder.Callback — 表面销毁"""
|
||||
self.onSurfaceDestroyed(holder)
|
||||
|
||||
def toString(self) -> str:
|
||||
return (f"Engine(visible={self._is_visible}, "
|
||||
f"draws={self._draw_count})")
|
||||
|
||||
def hashCode(self) -> int:
|
||||
return id(self) & 0x7FFFFFFF
|
||||
|
||||
def equals(self, other) -> bool:
|
||||
return self is other
|
||||
|
||||
|
||||
# ═══════════════════════════════════════════════════════════════
|
||||
# __all__
|
||||
# ═══════════════════════════════════════════════════════════════
|
||||
|
||||
__all__ = [
|
||||
"WallpaperService",
|
||||
"SurfaceHolder",
|
||||
]
|
||||
Reference in new issue
Block a user