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,117 @@
|
||||
"""
|
||||
Android Role API — RoleManager
|
||||
方法签名完全对齐 Android SDK
|
||||
"""
|
||||
|
||||
import sys
|
||||
from typing import Any, Dict, List, Optional, Set, Tuple, Callable
|
||||
|
||||
from .._core import Stub, AndroidOnlyError
|
||||
from ..java.lang import RuntimeException
|
||||
|
||||
|
||||
IllegalArgumentException = type("IllegalArgumentException", (RuntimeException,), {})
|
||||
|
||||
__all__ = [
|
||||
"RoleManager",
|
||||
]
|
||||
|
||||
|
||||
# ═══════════════════════════════════════════════════════════════
|
||||
# RoleManager
|
||||
# ═══════════════════════════════════════════════════════════════
|
||||
|
||||
class RoleManager(Stub):
|
||||
"""RoleManager — 角色管理器 (桌面存根)"""
|
||||
|
||||
ACTION_REQUEST_ROLE = "android.app.role.action.REQUEST_ROLE"
|
||||
|
||||
# --- 角色常量 ---
|
||||
ROLE_ASSISTANT = "android.app.role.ASSISTANT"
|
||||
ROLE_BROWSER = "android.app.role.BROWSER"
|
||||
ROLE_DIALER = "android.app.role.DIALER"
|
||||
ROLE_SMS = "android.app.role.SMS"
|
||||
ROLE_HOME = "android.app.role.HOME"
|
||||
ROLE_EMERGENCY = "android.app.role.EMERGENCY"
|
||||
ROLE_CALL_REDIRECTION = "android.app.role.CALL_REDIRECTION"
|
||||
ROLE_SYSTEM_EXCLUSIVE = "android.app.role.SYSTEM_EXCLUSIVE"
|
||||
ROLE_WALLPAPER = "android.app.role.WALLPAPER"
|
||||
ROLE_NOTIFICATION_ACCESS = "android.app.role.NOTIFICATION_ACCESS"
|
||||
ROLE_FOREGROUND_SERVICE = "android.app.role.FOREGROUND_SERVICE"
|
||||
|
||||
def __init__(self, context: Any = None):
|
||||
super().__init__()
|
||||
self._context = context
|
||||
# 模拟桌面角色持有者 (key=角色名, value=持有者包名列表)
|
||||
self._role_holders: Dict[str, List[str]] = {
|
||||
self.ROLE_HOME: ["com.example.launcher"],
|
||||
self.ROLE_BROWSER: ["org.mozilla.firefox"],
|
||||
self.ROLE_DIALER: ["com.google.android.dialer"],
|
||||
self.ROLE_SMS: ["com.google.android.messaging"],
|
||||
}
|
||||
self._listeners: List[Callable] = []
|
||||
|
||||
def isRoleAvailable(self, roleName: str) -> bool:
|
||||
"""检查角色是否可用"""
|
||||
available_roles = [
|
||||
self.ROLE_ASSISTANT, self.ROLE_BROWSER, self.ROLE_DIALER,
|
||||
self.ROLE_SMS, self.ROLE_HOME, self.ROLE_EMERGENCY,
|
||||
self.ROLE_CALL_REDIRECTION, self.ROLE_SYSTEM_EXCLUSIVE,
|
||||
self.ROLE_WALLPAPER, self.ROLE_NOTIFICATION_ACCESS,
|
||||
self.ROLE_FOREGROUND_SERVICE,
|
||||
]
|
||||
return roleName in available_roles
|
||||
|
||||
def isRoleHeld(self, roleName: str) -> bool:
|
||||
"""检查当前应用是否持有指定角色"""
|
||||
if not self._context:
|
||||
return False
|
||||
pkg = self._context.getPackageName() if hasattr(self._context, "getPackageName") else ""
|
||||
holders = self._role_holders.get(roleName, [])
|
||||
return pkg in holders
|
||||
|
||||
def createRequestRoleIntent(self, roleName: str) -> Any:
|
||||
"""创建请求角色的 Intent"""
|
||||
from .app import Intent
|
||||
intent = Intent(self.ACTION_REQUEST_ROLE)
|
||||
intent.putExtra("android.app.role.extra.ROLE_NAME", roleName)
|
||||
return intent
|
||||
|
||||
def getRoleHolders(self, roleName: str) -> List[str]:
|
||||
"""获取角色持有者列表"""
|
||||
return list(self._role_holders.get(roleName, []))
|
||||
|
||||
def addOnRoleHoldersChangedListener(
|
||||
self, executor: Any, listener: Callable
|
||||
):
|
||||
"""添加角色持有者变更监听器"""
|
||||
if listener not in self._listeners:
|
||||
self._listeners.append(listener)
|
||||
|
||||
def removeOnRoleHoldersChangedListener(self, listener: Callable):
|
||||
"""移除角色持有者变更监听器"""
|
||||
if listener in self._listeners:
|
||||
self._listeners.remove(listener)
|
||||
|
||||
def getRoleNamesFromController(self) -> List[str]:
|
||||
"""获取控制器管理的角色名列表"""
|
||||
return [
|
||||
self.ROLE_ASSISTANT, self.ROLE_BROWSER, self.ROLE_DIALER,
|
||||
self.ROLE_SMS, self.ROLE_HOME, self.ROLE_EMERGENCY,
|
||||
self.ROLE_CALL_REDIRECTION, self.ROLE_SYSTEM_EXCLUSIVE,
|
||||
self.ROLE_WALLPAPER, self.ROLE_NOTIFICATION_ACCESS,
|
||||
self.ROLE_FOREGROUND_SERVICE,
|
||||
]
|
||||
|
||||
def getApplicationVisibleRoleNames(self) -> List[str]:
|
||||
"""获取应用可见的角色名列表"""
|
||||
return self.getRoleNamesFromController()
|
||||
|
||||
def toString(self) -> str:
|
||||
return f"RoleManager@{hex(id(self))}"
|
||||
|
||||
def equals(self, other) -> bool:
|
||||
return self is other
|
||||
|
||||
def hashCode(self) -> int:
|
||||
return id(self) & 0x7FFFFFFF
|
||||
Reference in new issue
Block a user