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,299 @@
|
||||
"""
|
||||
Android hardware.display 组件 — DisplayManager, VirtualDisplay, WifiDisplay 等
|
||||
方法签名完全对齐 Android SDK
|
||||
"""
|
||||
|
||||
import time
|
||||
from typing import Any, Callable, Dict, List, Optional, Tuple
|
||||
|
||||
from .._core import Stub, AndroidOnlyError
|
||||
|
||||
|
||||
# ═══════════════════════════════════════════════════════════════
|
||||
# DisplayManager
|
||||
# ═══════════════════════════════════════════════════════════════
|
||||
|
||||
class DisplayManager(Stub):
|
||||
"""DisplayManager — 显示管理器"""
|
||||
|
||||
VIRTUAL_DISPLAY_FLAG_AUTO_MIRROR = 1
|
||||
VIRTUAL_DISPLAY_FLAG_OWN_CONTENT_ONLY = 4
|
||||
VIRTUAL_DISPLAY_FLAG_PUBLIC_DISPLAY = 8
|
||||
VIRTUAL_DISPLAY_FLAG_PRESENTATION = 2
|
||||
VIRTUAL_DISPLAY_FLAG_SECURE = 16
|
||||
VIRTUAL_DISPLAY_FLAG_SUPPORTS_HDR = 32
|
||||
|
||||
MATCH_DEFAULT_DISPLAY = -1
|
||||
MATCH_ALL_DISPLAYS = 0
|
||||
|
||||
# ═══════════════════════════════════════════════════════════
|
||||
# DisplayListener
|
||||
# ═══════════════════════════════════════════════════════════
|
||||
|
||||
class DisplayListener(Stub):
|
||||
"""DisplayManager.DisplayListener — 显示监听器"""
|
||||
|
||||
def onDisplayAdded(self, displayId: int):
|
||||
pass
|
||||
|
||||
def onDisplayRemoved(self, displayId: int):
|
||||
pass
|
||||
|
||||
def onDisplayChanged(self, displayId: int):
|
||||
pass
|
||||
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
self._displays: Dict[int, Display] = {}
|
||||
self._listeners: Dict[int, DisplayManager.DisplayListener] = {}
|
||||
self._next_display_id = 1
|
||||
# Create default display
|
||||
self._displays[0] = Display(0, "Built-in Display")
|
||||
|
||||
def getDisplay(self, displayId: int) -> Optional["Display"]:
|
||||
return self._displays.get(displayId)
|
||||
|
||||
def getDisplays(self) -> List["Display"]:
|
||||
if DisplayManager.MATCH_ALL_DISPLAYS:
|
||||
return list(self._displays.values())
|
||||
return []
|
||||
|
||||
def registerDisplayListener(self, listener: DisplayListener, handler: Any = None):
|
||||
lid = id(listener)
|
||||
self._listeners[lid] = listener
|
||||
|
||||
def unregisterDisplayListener(self, listener: DisplayListener):
|
||||
lid = id(listener)
|
||||
self._listeners.pop(lid, None)
|
||||
|
||||
def createVirtualDisplay(self, name: str, width: int, height: int, densityDpi: int,
|
||||
surface: Any, flags: int, callback: Callable = None,
|
||||
handler: Any = None) -> "VirtualDisplay":
|
||||
display_id = self._next_display_id
|
||||
self._next_display_id += 1
|
||||
vd = VirtualDisplay(display_id, name, width, height, densityDpi, surface, flags)
|
||||
return vd
|
||||
|
||||
def getStableDisplay(self) -> Optional["Display"]:
|
||||
return self._displays.get(0)
|
||||
|
||||
|
||||
# ═══════════════════════════════════════════════════════════════
|
||||
# Display
|
||||
# ═══════════════════════════════════════════════════════════════
|
||||
|
||||
class Display(Stub):
|
||||
"""Display — 显示信息"""
|
||||
|
||||
DEFAULT_DISPLAY = 0
|
||||
|
||||
STATE_UNKNOWN = 0
|
||||
STATE_OFF = 1
|
||||
STATE_ON = 2
|
||||
STATE_DOZE = 3
|
||||
STATE_DOZE_SUSPEND = 4
|
||||
|
||||
FLAG_PRESENTATION = 2
|
||||
FLAG_PRIVATE = 4
|
||||
FLAG_ROUND = 8
|
||||
FLAG_CAN_SHOW_WITH_INSETS = 16
|
||||
FLAG_SECURE = 32
|
||||
FLAG_SUPPORTS_HDR = 64
|
||||
|
||||
def __init__(self, displayId: int = 0, name: str = "Display",
|
||||
width: int = 1920, height: int = 1080,
|
||||
densityDpi: int = 420, refreshRate: float = 60.0):
|
||||
super().__init__()
|
||||
self._display_id = displayId
|
||||
self._name = name
|
||||
self._width = width
|
||||
self._height = height
|
||||
self._density_dpi = densityDpi
|
||||
self._refresh_rate = refreshRate
|
||||
self._state = Display.STATE_ON
|
||||
self._flags = 0
|
||||
self._app_width = width
|
||||
self._app_height = height
|
||||
|
||||
def getDisplayId(self) -> int:
|
||||
return self._display_id
|
||||
|
||||
def getName(self) -> str:
|
||||
return self._name
|
||||
|
||||
def getWidth(self) -> int:
|
||||
return self._width
|
||||
|
||||
def getHeight(self) -> int:
|
||||
return self._height
|
||||
|
||||
def getRotation(self) -> int:
|
||||
return 0
|
||||
|
||||
def getState(self) -> int:
|
||||
return self._state
|
||||
|
||||
def getRefreshRate(self) -> float:
|
||||
return self._refresh_rate
|
||||
|
||||
def isHdr(self) -> bool:
|
||||
return bool(self._flags & Display.FLAG_SUPPORTS_HDR)
|
||||
|
||||
def getFlags(self) -> int:
|
||||
return self._flags
|
||||
|
||||
def getMode(self) -> Any:
|
||||
return None
|
||||
|
||||
def getSupportedModes(self) -> List[Any]:
|
||||
return []
|
||||
|
||||
def getSupportedHdrTypes(self) -> List[int]:
|
||||
return []
|
||||
|
||||
def getAppWidth(self) -> int:
|
||||
return self._app_width
|
||||
|
||||
def getAppHeight(self) -> int:
|
||||
return self._app_height
|
||||
|
||||
def getDensityDpi(self) -> int:
|
||||
return self._density_dpi
|
||||
|
||||
def toString(self) -> str:
|
||||
return f"Display(id={self._display_id}, name={self._name}, {self._width}x{self._height}," \
|
||||
f" dpi={self._density_dpi})"
|
||||
|
||||
|
||||
# ═══════════════════════════════════════════════════════════════
|
||||
# VirtualDisplay
|
||||
# ═══════════════════════════════════════════════════════════════
|
||||
|
||||
class VirtualDisplay(Stub):
|
||||
"""VirtualDisplay — 虚拟显示"""
|
||||
|
||||
def __init__(self, displayId: int, name: str, width: int, height: int,
|
||||
densityDpi: int, surface: Any, flags: int):
|
||||
super().__init__()
|
||||
self._display_id = displayId
|
||||
self._name = name
|
||||
self._width = width
|
||||
self._height = height
|
||||
self._density_dpi = densityDpi
|
||||
self._surface = surface
|
||||
self._flags = flags
|
||||
self._display = Display(displayId, name, width, height, densityDpi)
|
||||
self._released = False
|
||||
|
||||
def setSurface(self, surface: Any):
|
||||
self._surface = surface
|
||||
|
||||
def resize(self, width: int, height: int, densityDpi: int):
|
||||
self._width = width
|
||||
self._height = height
|
||||
self._density_dpi = densityDpi
|
||||
|
||||
def release(self):
|
||||
self._released = True
|
||||
|
||||
def getDisplay(self) -> Display:
|
||||
return self._display
|
||||
|
||||
def getSurface(self) -> Any:
|
||||
return self._surface
|
||||
|
||||
def getFlags(self) -> int:
|
||||
return self._flags
|
||||
|
||||
def toString(self) -> str:
|
||||
return f"VirtualDisplay(id={self._display_id}, name={self._name}," \
|
||||
f" {self._width}x{self._height}, released={self._released})"
|
||||
|
||||
|
||||
# ═══════════════════════════════════════════════════════════════
|
||||
# WifiDisplayStatus
|
||||
# ═══════════════════════════════════════════════════════════════
|
||||
|
||||
class WifiDisplayStatus(Stub):
|
||||
"""WifiDisplayStatus — Wi-Fi 显示状态"""
|
||||
|
||||
FEATURE_STATE_DISABLED = 0
|
||||
FEATURE_STATE_ON = 1
|
||||
FEATURE_STATE_OFF = 2
|
||||
FEATURE_STATE_UNAVAILABLE = 3
|
||||
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
self._active_display: Optional[WifiDisplay] = None
|
||||
self._scan_results: List[WifiDisplay] = []
|
||||
self._feature_state = WifiDisplayStatus.FEATURE_STATE_DISABLED
|
||||
|
||||
def getActiveDisplay(self) -> Optional["WifiDisplay"]:
|
||||
return self._active_display
|
||||
|
||||
def getScanResults(self) -> List["WifiDisplay"]:
|
||||
return self._scan_results
|
||||
|
||||
def getFeatureState(self) -> int:
|
||||
return self._feature_state
|
||||
|
||||
def toString(self) -> str:
|
||||
return f"WifiDisplayStatus(featureState={self._feature_state})"
|
||||
|
||||
|
||||
# ═══════════════════════════════════════════════════════════════
|
||||
# WifiDisplay
|
||||
# ═══════════════════════════════════════════════════════════════
|
||||
|
||||
class WifiDisplay(Stub):
|
||||
"""WifiDisplay — Wi-Fi 显示设备"""
|
||||
|
||||
def __init__(self, deviceAddress: str = "", deviceName: str = "",
|
||||
deviceAlias: str = "", available: bool = False,
|
||||
remembered: bool = False):
|
||||
super().__init__()
|
||||
self._device_address = deviceAddress
|
||||
self._device_name = deviceName
|
||||
self._device_alias = deviceAlias
|
||||
self._available = available
|
||||
self._remembered = remembered
|
||||
|
||||
def getDeviceAddress(self) -> str:
|
||||
return self._device_address
|
||||
|
||||
def getDeviceName(self) -> str:
|
||||
return self._device_name
|
||||
|
||||
def getDeviceAlias(self) -> str:
|
||||
return self._device_alias
|
||||
|
||||
def isAvailable(self) -> bool:
|
||||
return self._available
|
||||
|
||||
def isRemembered(self) -> bool:
|
||||
return self._remembered
|
||||
|
||||
def equals(self, other: Any) -> bool:
|
||||
if not isinstance(other, WifiDisplay):
|
||||
return False
|
||||
return self._device_address == other._device_address
|
||||
|
||||
def hashCode(self) -> int:
|
||||
return hash(self._device_address) & 0x7FFFFFFF
|
||||
|
||||
def toString(self) -> str:
|
||||
return f"WifiDisplay(address={self._device_address}, name={self._device_name}," \
|
||||
f" available={self._available})"
|
||||
|
||||
|
||||
# ═══════════════════════════════════════════════════════════════
|
||||
# __all__
|
||||
# ═══════════════════════════════════════════════════════════════
|
||||
|
||||
__all__ = [
|
||||
"DisplayManager",
|
||||
"Display",
|
||||
"VirtualDisplay",
|
||||
"WifiDisplayStatus",
|
||||
"WifiDisplay",
|
||||
]
|
||||
Reference in new issue
Block a user