diff --git a/uiautomator2/assets/sync.sh b/uiautomator2/assets/sync.sh index 725d6b2..1129dac 100755 --- a/uiautomator2/assets/sync.sh +++ b/uiautomator2/assets/sync.sh @@ -3,7 +3,7 @@ set -e -APK_VERSION="2.3.8" +APK_VERSION="2.3.9" # AGENT_VERSION="0.10.1" cd "$(dirname $0)" diff --git a/uiautomator2/core.py b/uiautomator2/core.py index 34a2dcb..3749b88 100644 --- a/uiautomator2/core.py +++ b/uiautomator2/core.py @@ -16,7 +16,7 @@ import adbutils import requests -from uiautomator2.exceptions import RPCInvalidError, UiAutomationNotConnectedError, HTTPError, LaunchUiAutomationError, UiObjectNotFoundError, RPCUnknownError, APkSignatureError, AccessibilityServiceAlreadyRegisteredError +from uiautomator2.exceptions import RPCInvalidError, UiAutomationNotConnectedError, HTTPError, LaunchUiAutomationError, UiObjectNotFoundError, RPCUnknownError, APKSignatureError, AccessibilityServiceAlreadyRegisteredError from uiautomator2.abstract import AbstractUiautomatorServer @@ -140,7 +140,6 @@ def _jsonrpc_call(dev: adbutils.AdbDevice, method: str, params: Any, timeout: fl raise UiObjectNotFoundError(code, message, params) raise RPCUnknownError(f"Unknown RPC error: {code} {message}", params, stacktrace) - if "result" not in data: raise RPCInvalidError("Unknown RPC error: no result field") return data["result"] @@ -167,6 +166,15 @@ def debug(self, value: bool): self._debug = bool(value) def start_uiautomator(self): + try: + self._do_start_uiautomator() + except APKSignatureError as e: + logger.debug("APkSignatureError: %s", e) + self._dev.uninstall("com.github.uiautomator") + self._dev.uninstall("com.github.uiautomator.test") + self._do_start_uiautomator() + + def _do_start_uiautomator(self): """ Start uiautomator2 server @@ -228,7 +236,7 @@ def _wait_instrument_ready(self, timeout: float): while time.time() < deadline: output = self._process.output.decode("utf-8", errors="ignore") if "does not have a signature matching the target" in output: - raise APkSignatureError("app-uiautomator.apk does not have a signature matching the target") + raise APKSignatureError("app-uiautomator.apk does not have a signature matching the target") if "INSTRUMENTATION_STATUS: Error=" in output: error_message = output[output.find("INSTRUMENTATION_STATUS: Error="):].splitlines()[0] raise LaunchUiAutomationError(error_message, output) @@ -282,21 +290,9 @@ def jsonrpc_call(self, method: str, params: Any = None, timeout: float = 10) -> """Send jsonrpc call to uiautomator2 server""" try: return _jsonrpc_call(self._dev, method, params, timeout, self._debug) - except APkSignatureError: - logger.debug("APkSignatureError: %s", e) - self._dev.uninstall("com.github.uiautomator") - self._dev.uninstall("com.github.uiautomator.test") - self.start_uiautomator() - return _jsonrpc_call(self._dev, method, params, timeout, self._debug) except (HTTPError, UiAutomationNotConnectedError) as e: logger.debug("uiautomator2 is not ok, error: %s", e) - try: - self.start_uiautomator() - except APkSignatureError as e: - logger.debug("APkSignatureError: %s", e) - self._dev.uninstall("com.github.uiautomator") - self._dev.uninstall("com.github.uiautomator.test") - self.start_uiautomator() + self.start_uiautomator() return _jsonrpc_call(self._dev, method, params, timeout, self._debug) class SimpleUiautomatorServer(BasicUiautomatorServer, AbstractUiautomatorServer): diff --git a/uiautomator2/exceptions.py b/uiautomator2/exceptions.py index fff95fc..2a8c741 100644 --- a/uiautomator2/exceptions.py +++ b/uiautomator2/exceptions.py @@ -18,7 +18,7 @@ class UiAutomationError(DeviceError): class UiAutomationNotConnectedError(UiAutomationError):... class InjectPermissionError(UiAutomationError):... #开发者选项中: 模拟点击没有打开 -class APkSignatureError(UiAutomationError):... +class APKSignatureError(UiAutomationError):... class LaunchUiAutomationError(UiAutomationError):... class AccessibilityServiceAlreadyRegisteredError(UiAutomationError):...