Skip to content

Commit

Permalink
update apk version to 2.3.9 to fix dumpHierarchy sometimes invalid ch…
Browse files Browse the repository at this point in the history
…ar error
  • Loading branch information
codeskyblue committed May 13, 2024
1 parent a0b852e commit 9e642a1
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 18 deletions.
2 changes: 1 addition & 1 deletion uiautomator2/assets/sync.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

set -e

APK_VERSION="2.3.8"
APK_VERSION="2.3.9"
# AGENT_VERSION="0.10.1"

cd "$(dirname $0)"
Expand Down
28 changes: 12 additions & 16 deletions uiautomator2/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -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"]
Expand All @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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):
Expand Down
2 changes: 1 addition & 1 deletion uiautomator2/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):...

Expand Down

0 comments on commit 9e642a1

Please sign in to comment.