Skip to content

Commit

Permalink
update apk version 2.3.8
Browse files Browse the repository at this point in the history
  • Loading branch information
codeskyblue committed May 12, 2024
1 parent 400adba commit 4f35965
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 17 deletions.
3 changes: 2 additions & 1 deletion uiautomator2/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ def enable_pretty_logging(level=logging.DEBUG):
formatter = logging.Formatter('[%(levelname)1.1s %(asctime)s %(module)s:%(lineno)d pid:%(process)d] %(message)s')
handler.setFormatter(formatter)
logger.addHandler(handler)

logger.setLevel(level)


Expand Down Expand Up @@ -100,7 +101,7 @@ def _wait_for_device(self, timeout=10) -> adbutils.AdbDevice:
return None

@property
def adb_device(self):
def adb_device(self) -> adbutils.AdbDevice:
return self._dev

@cached_property
Expand Down
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.7"
APK_VERSION="2.3.8"
# AGENT_VERSION="0.10.1"

cd "$(dirname $0)"
Expand Down
38 changes: 23 additions & 15 deletions uiautomator2/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ def __init__(self, dev: adbutils.AdbDevice) -> None:
self._process = None
self._lock = threading.Lock()
self._debug = False
self.start_uiautomator()
atexit.register(self.stop_uiautomator)

@property
Expand All @@ -177,8 +178,9 @@ def start_uiautomator(self):
if self._process:
if self._process.pool() is not None:
self._process = None
self._process = launch_uiautomator(self._dev)
self._wait_ready()
if not self._check_alive():
self._process = launch_uiautomator(self._dev)
self._wait_ready()

def _setup_apks(self):
assets_dir = Path(__file__).parent / "assets"
Expand All @@ -193,17 +195,20 @@ def _setup_apks(self):
if k == "apk_version":
apk_version = v.strip()
break
logger.debug("apk_version: %s", apk_version)
logger.debug("use apk_version: %s", apk_version)
# install apk when not installed or version not match, dev version always keep
main_apk_info = self._dev.app_info("com.github.uiautomator")
if main_apk_info is None:
self._install_apk(main_apk)
elif main_apk_info.version_name != apk_version and "dev" not in main_apk_info.version_name:
logger.debug("apk version not match, reinstall")
self._dev.uninstall("com.github.uiautomator")
self._dev.uninstall("com.github.uiautomator.test")
self._install_apk(main_apk)
self._install_apk(test_apk)
elif main_apk_info.version_name != apk_version:
if "dev" in main_apk_info.version_name or "dirty" in main_apk_info.version_name:
logger.debug("skip version check for %s", main_apk_info.version_name)
else:
logger.debug("apk version not match, reinstall")
self._dev.uninstall("com.github.uiautomator")
self._dev.uninstall("com.github.uiautomator.test")
self._install_apk(main_apk)
self._install_apk(test_apk)

if self._dev.app_info("com.github.uiautomator.test") is None:
self._install_apk(test_apk)
Expand Down Expand Up @@ -246,13 +251,16 @@ def _wait_stub_ready(self, timeout: float):
raise AccessibilityServiceAlreadyRegisteredError("Possibly another UiAutomation service is running, you may find it output by \"adb shell ps -u shell\"",)
if self._process.pool() is not None:
raise LaunchUiAutomationError("uiautomator2 server quit", output)
try:
response = _http_request(self._dev, "GET", "/ping")
if response.content == b"pong":
return
except HTTPError:
time.sleep(.5)
if self._check_alive():
return
raise LaunchUiAutomationError("uiautomator2 server not ready")

def _check_alive(self) -> bool:
try:
response = _http_request(self._dev, "GET", "/ping")
return response.content == b"pong"
except HTTPError:
return False

def _wait_ready(self, launch_timeout=30, service_timeout=30):
"""Wait until uiautomator2 server is ready"""
Expand Down

0 comments on commit 4f35965

Please sign in to comment.