From a0e9612641671ab63fa1084c98ac0c4dbd886c3f Mon Sep 17 00:00:00 2001 From: codeskyblue Date: Sun, 28 Apr 2024 22:35:53 +0800 Subject: [PATCH] add device_info back, fix screenshot error --- README.md | 3 ++- docs/2to3.md | 48 ++++++++++++++++++++++++++++++++++++- pyproject.toml | 2 +- uiautomator2/__init__.py | 17 +++++++++++++ uiautomator2/assets/sync.sh | 4 +--- 5 files changed, 68 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 62d14aa..e46ea83 100644 --- a/README.md +++ b/README.md @@ -64,6 +64,8 @@ print(d.info) screenOn': True, 'sdkInt': 27, 'naturalOrientation': True} ``` +另外为了保持稳定,还需要开启`小黄车`的悬浮窗权限。参考文章 [py-uiautomator2通过悬浮窗让服务长时间可用](https://zhuanlan.zhihu.com/p/688009468) + 一般情况下都会成功,不过也可能会有意外。可以加QQ群反馈问题(群号在最上面),群里有很多大佬可以帮你解决问题。 ## Sponsors @@ -77,7 +79,6 @@ Thank you to all our sponsors! ✨🍰✨ # Article Recommended 优秀文章推荐 (欢迎QQ群里at我反馈) -- [py-uiautomator2通过悬浮窗让服务长时间可用](https://zhuanlan.zhihu.com/p/688009468) 这个**强烈推荐**看一下 - [termux里如何部署uiautomator2简介](https://www.cnblogs.com/ze-yan/p/12242383.html) by `成都-测试只会一点点` ## 相关项目 diff --git a/docs/2to3.md b/docs/2to3.md index 345c038..45133b4 100644 --- a/docs/2to3.md +++ b/docs/2to3.md @@ -55,7 +55,6 @@ - Remove function connect_wifi() -> Device, 该函数依赖atx-agent - Remove function connect_adb_wifi(str) -> Device, 直接用connect就行了 - Remove function set_new_command_timeout(timeout: int), 用不着了 -- Remove function device_info(), 函数依赖atx-agent - Remove function open_identify(), 打开一个比较明显的界面,这个函数出了点毛病,先下掉了 ### Command remove @@ -114,3 +113,50 @@ It seems the strict is useless, so I delete it. ### push - 2.x push(src, dst, mode, show_process:bool=False) - 3.x push(src, dst, mode) + +### device_info +print(d.device_info) + +2.x prints + +``` +{'udid': '08a3d291-26:17:84:b6:cb:a0-DT1901A', + 'version': '10', + 'serial': '08a3d291', + 'brand': 'SMARTISAN', + 'model': 'DT1901A', + 'hwaddr': '26:17:84:b6:cb:a0', + 'sdk': 29, + 'agentVersion': '0.10.0', + 'display': {'width': 1080, 'height': 2340}, + 'battery': {'acPowered': False, + 'usbPowered': True, + 'wirelessPowered': False, + 'status': 5, + 'health': 2, + 'present': True, + 'level': 100, + 'scale': 100, + 'voltage': 4356, + 'temperature': 292, + 'technology': 'Li-poly'}, + 'memory': {'total': 7665272, 'around': '7 GB'}, + 'cpu': {'cores': 8, 'hardware': 'Qualcomm Technologies, Inc SM8150'}, + 'arch': '', + 'owner': None, + 'presenceChangedAt': '0001-01-01T00:00:00Z', + 'usingBeganAt': '0001-01-01T00:00:00Z', + 'product': None, + 'provider': None} + ``` + + 3.x prints + + ``` + {'serial': 'VVY0223208008426', + 'sdk': 31, + 'brand': 'HUAWEI', + 'model': 'JAD-AL80', + 'arch': 'arm64-v8a', + 'version': 12} + ``` \ No newline at end of file diff --git a/pyproject.toml b/pyproject.toml index 4427bff..12c7a81 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -12,7 +12,7 @@ include = ["*/assets/*"] python = "^3.8" requests = "*" lxml = "*" -adbutils = "^2.2.3,!=2.3.0" +adbutils = "^2.5.0" retry = ">=0,<1" Deprecated = "*" Pillow = "*" diff --git a/uiautomator2/__init__.py b/uiautomator2/__init__.py index 575410a..af6d69f 100644 --- a/uiautomator2/__init__.py +++ b/uiautomator2/__init__.py @@ -135,6 +135,23 @@ def shell(self, cmdargs: Union[str, List[str]], timeout=60) -> ShellResponse: @property def info(self): return self.jsonrpc.deviceInfo(http_timeout=10) + + @property + def device_info(self) -> Dict[str, Any]: + serial = self._dev.getprop("ro.serialno") + sdk = self._dev.getprop("ro.build.version.sdk") + version = self._dev.getprop("ro.build.version.release") + brand = self._dev.getprop("ro.product.brand") + model = self._dev.getprop("ro.product.model") + arch = self._dev.getprop("ro.product.cpu.abi") + return { + "serial": serial, + "sdk": int(sdk) if sdk.isdigit() else None, + "brand": brand, + "model": model, + "arch": arch, + "version": int(version) if version.isdigit() else None, + } @property def wlan_ip(self) -> Optional[str]: diff --git a/uiautomator2/assets/sync.sh b/uiautomator2/assets/sync.sh index 462878e..c345ca2 100755 --- a/uiautomator2/assets/sync.sh +++ b/uiautomator2/assets/sync.sh @@ -33,6 +33,4 @@ function download_apk(){ download_apk "$APK_VERSION" "app-uiautomator.apk" download_apk "$APK_VERSION" "app-uiautomator-test.apk" -echo "apk_version: $APK_VERSION" >> version.txt - - +echo "apk_version: $APK_VERSION" > version.txt \ No newline at end of file