""" Android view.autofill 组件 — AutofillManager, AutofillValue, AutofillId 等 方法签名完全对齐 Android SDK """ from typing import Any, Callable, Dict, List, Optional from .._core import Stub, AndroidOnlyError # ═══════════════════════════════════════════════════════════════ # AutofillManager # ═══════════════════════════════════════════════════════════════ class AutofillManager(Stub): """AutofillManager — 自动填充管理器""" # ═══════════════════════════════════════════════════════════ # AutofillCallback # ═══════════════════════════════════════════════════════════ class AutofillCallback(Stub): """AutofillManager.AutofillCallback — 自动填充回调""" def onAutofillEvent(self, view: Any, event: int): pass def onAutofillUnavailableEvent(self, event: int): pass def onAuthenticationShowing(self): pass def __init__(self): super().__init__() self._enabled = False self._callbacks: List[AutofillManager.AutofillCallback] = [] def isEnabled(self) -> bool: return self._enabled def hasEnabledAutofillServices(self) -> bool: return False def isAutofillSupported(self) -> bool: return False def disableAutofillServices(self): self._enabled = False def notifyValueChanged(self, view: Any): pass def commit(self): pass def cancel(self): pass def requestAutofill(self, view: Any): pass def getAutofillServiceComponentName(self) -> Any: return None def getAutofillServiceLabel(self) -> str: return "" def getAvailableFieldClassificationAlgorithms(self) -> List[str]: return [] def getDefaultFieldClassificationAlgorithm(self) -> Optional[str]: return None def getFillEventHistory(self) -> Optional["FillEventHistory"]: return None def onAuthenticationResult(self, authenticationResult: Any): pass def onAuthenticationFailed(self): pass # ═══════════════════════════════════════════════════════════════ # AutofillValue # ═══════════════════════════════════════════════════════════════ class AutofillValue(Stub): """AutofillValue — 自动填充值""" def __init__(self): super().__init__() self._text_value: Optional[str] = None self._date_value: Optional[int] = None self._toggle_value: Optional[bool] = None self._list_value: Optional[int] = None self._is_text = False self._is_date = False self._is_toggle = False self._is_list = False @staticmethod def forText(value: str) -> "AutofillValue": v = AutofillValue() v._text_value = value v._is_text = True return v @staticmethod def forDate(value: int) -> "AutofillValue": v = AutofillValue() v._date_value = value v._is_date = True return v @staticmethod def forToggle(value: bool) -> "AutofillValue": v = AutofillValue() v._toggle_value = value v._is_toggle = True return v @staticmethod def forList(value: int) -> "AutofillValue": v = AutofillValue() v._list_value = value v._is_list = True return v def getTextValue(self) -> Optional[str]: return self._text_value def getDateValue(self) -> Optional[int]: return self._date_value def getToggleValue(self) -> Optional[bool]: return self._toggle_value def getListValue(self) -> Optional[int]: return self._list_value def isText(self) -> bool: return self._is_text def isDate(self) -> bool: return self._is_date def isToggle(self) -> bool: return self._is_toggle def isList(self) -> bool: return self._is_list def equals(self, other: Any) -> bool: if not isinstance(other, AutofillValue): return False return (self._text_value == other._text_value and self._date_value == other._date_value and self._toggle_value == other._toggle_value and self._list_value == other._list_value) def hashCode(self) -> int: return hash((self._text_value, self._date_value, self._toggle_value, self._list_value)) & 0x7FFFFFFF def toString(self) -> str: if self._is_text: return f"AutofillValue(text={self._text_value})" if self._is_date: return f"AutofillValue(date={self._date_value})" if self._is_toggle: return f"AutofillValue(toggle={self._toggle_value})" if self._is_list: return f"AutofillValue(list={self._list_value})" return "AutofillValue(empty)" # ═══════════════════════════════════════════════════════════════ # AutofillId # ═══════════════════════════════════════════════════════════════ class AutofillId(Stub): """AutofillId — 自动填充 ID""" FLAG_AUTOFILL_SESSION_SUPPORTS_INDEXING = 1 FLAG_AUTOFILL_SESSION_SUPPORTS_AUGMENTED_AUTOFILL = 2 def __init__(self, viewId: int = 0, sessionId: int = 0, virtualChildId: int = -1, virtualIntId: int = -1): super().__init__() self._view_id = viewId self._session_id = sessionId self._virtual_child_id = virtualChildId self._virtual_int_id = virtualIntId def getViewId(self) -> int: return self._view_id def getSessionId(self) -> int: return self._session_id def getVirtualChildId(self) -> int: return self._virtual_child_id def getVirtualIntId(self) -> int: return self._virtual_int_id def equals(self, other: Any) -> bool: if not isinstance(other, AutofillId): return False return (self._view_id == other._view_id and self._session_id == other._session_id and self._virtual_child_id == other._virtual_child_id) def hashCode(self) -> int: return hash((self._view_id, self._session_id, self._virtual_child_id)) & 0x7FFFFFFF def toString(self) -> str: return f"AutofillId(viewId={self._view_id}, sessionId={self._session_id})" # ═══════════════════════════════════════════════════════════════ # FillEventHistory # ═══════════════════════════════════════════════════════════════ class FillEventHistory(Stub): """FillEventHistory — 填充事件历史""" def __init__(self): super().__init__() self._events: List[Any] = [] self._client_state: Any = None def getEvents(self) -> List[Any]: return self._events def getClientState(self) -> Any: return self._client_state # ═══════════════════════════════════════════════════════════════ # FillContext # ═══════════════════════════════════════════════════════════════ class FillContext(Stub): """FillContext — 填充上下文""" def __init__(self, requestId: int = 0, autofillId: Optional[AutofillId] = None, focusedId: Optional[AutofillId] = None, focusedVirtualId: int = -1, extras: Any = None, autofillValue: Optional[AutofillValue] = None, visibility: Optional[int] = None, options: Optional[List[Any]] = None): super().__init__() self._request_id = requestId self._autofill_id = autofillId self._focused_id = focusedId self._focused_virtual_id = focusedVirtualId self._extras = extras self._autofill_value = autofillValue self._visibility = visibility self._options = options def getRequestId(self) -> int: return self._request_id def getAutofillId(self) -> Optional[AutofillId]: return self._autofill_id def getFocusedId(self) -> Optional[AutofillId]: return self._focused_id def getFocusedVirtualId(self) -> int: return self._focused_virtual_id def getExtras(self) -> Any: return self._extras def getAutofillValue(self) -> Optional[AutofillValue]: return self._autofill_value def getVisibility(self) -> Optional[int]: return self._visibility def getOptions(self) -> Optional[List[Any]]: return self._options # ═══════════════════════════════════════════════════════════════ # AugmentedAutofillManager (stub) # ═══════════════════════════════════════════════════════════════ class AugmentedAutofillManager(Stub): """AugmentedAutofillManager — 增强自动填充管理器""" def __init__(self): super().__init__() # ═══════════════════════════════════════════════════════════════ # __all__ # ═══════════════════════════════════════════════════════════════ __all__ = [ "AutofillManager", "AutofillValue", "AutofillId", "FillEventHistory", "FillContext", "AugmentedAutofillManager", ]