Skip to content

Commit

Permalink
update atx-agent to 0.10.1 in order to fix d.app_start, localize atx-…
Browse files Browse the repository at this point in the history
…agent to make uiautomator2 totally offline (#951)
  • Loading branch information
codeskyblue authored Apr 7, 2024
1 parent d3f3640 commit 9ed61ee
Show file tree
Hide file tree
Showing 25 changed files with 59 additions and 27 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -113,5 +113,4 @@ vendor/
docs/*.rst

.DS_Store
apk_version.txt
*.lock
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ format:
poetry run isort . -m HANGING_INDENT -l 120

test:
poetry run pytest -v tests
poetry run pytest -v mobile_tests/

cov:
poetry run pytest -v tests/unittests \
poetry run pytest -v tests/ \
--cov-config=.coveragerc \
--cov uiautomator2 \
--cov-report xml \
Expand Down
25 changes: 16 additions & 9 deletions docs/2to3.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,9 @@
- 版本管理从pbr改为poetry,同时降低依赖库的数量
- Python依赖调整为最低3.8
- 增加更多的单测
- 日志使用标准库logging, 默认不输出任何内容,除非手动开启
- minicap,minitouch不再默认安装

# 增加
开启库的详细日志的方法

```python
from uiautomator2 import enable_pretty_logging
enable_pretty_logging()
```
- atx-agent[armeabi]直接打包到lib里面去,避免外网下载依赖

## 移除的功能
- current_app函数移除
Expand All @@ -30,4 +24,17 @@ enable_pretty_logging()
- 移除 module uiautomator2.ext.xpath
- 移除 connect_usb函数中的init参数移除,这个参数目前没什么用了

TODO: atx-agent不在依赖外网下载,直接打包到内部
# 手动开启日志方法
开启Lib库日志的方法

```python
from uiautomator2 import enable_pretty_logging
enable_pretty_logging()
```

或者

```
logger = logging.getLogger("uiautomator2")
# 修改logger
```
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ homepage = "https://github.com/openatx/uiautomator2"
authors = ["codeskyblue <codeskyblue@gmail.com>"]
license = "MIT"
readme = "README.md"
include = ["*/assets/*.apk"]
include = ["*/assets/*"]

[tool.poetry.dependencies]
python = "^3.8"
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
6 changes: 4 additions & 2 deletions uiautomator2/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@

import uiautomator2 as u2

from .init import Initer
from .version import __version__
from uiautomator2.init import Initer
from uiautomator2.version import __version__
from uiautomator2 import enable_pretty_logging


logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -138,6 +139,7 @@ def cmd_version(args):
def cmd_console(args):
import code
import platform
enable_pretty_logging()

d = u2.connect(args.serial)
model = d.shell("getprop ro.product.model").output.strip()
Expand Down
3 changes: 3 additions & 0 deletions uiautomator2/assets/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
*.apk
atx-agent
version.txt
30 changes: 21 additions & 9 deletions uiautomator2/assets/sync.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,37 @@
set -e

APK_VERSION="2.3.3"
AGENT_VERSION="0.10.1"

echo "Created at $(date +"%Y-%m-%d %H:%M:%S %Z")" > version.txt

cd "$(dirname $0)"

#if test -f apk_version.txt -a "$APK_VERSION" = "$(cat apk_version.txt)"
#then
# echo "apk version $APK_VERSION, already downloaded, exit"
# exit
#fi
function download_atx_agent() {
VERSION=$1
NAME="tmp-atx-agent.tar.gz"
URL="https://github.com/openatx/atx-agent/releases/download/$VERSION/atx-agent_${VERSION}_linux_armv6.tar.gz"
echo "$URL"
curl -L "$URL" --output "$NAME"
tar -xzvf "$NAME" atx-agent
rm -f "$NAME"
}

function download(){
function download_apk(){
VERSION=$1
NAME=$2
URL="https://github.com/openatx/android-uiautomator-server/releases/download/$VERSION/$NAME"
echo "$URL"
curl -L "$URL" --output "$NAME"
unzip -tq "$NAME"
}

download "$APK_VERSION" "app-uiautomator.apk"
download "$APK_VERSION" "app-uiautomator-test.apk"
download_atx_agent "$AGENT_VERSION"
echo "atx_agent_version: $AGENT_VERSION" >> version.txt

download_apk "$APK_VERSION" "app-uiautomator.apk"
download_apk "$APK_VERSION" "app-uiautomator-test.apk"

echo "apk_version: $APK_VERSION" >> version.txt


unzip -tq app-uiautomator.apk && echo "$APK_VERSION" > apk_version.txt
12 changes: 10 additions & 2 deletions uiautomator2/init.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import hashlib
import logging
import os
from pathlib import Path
import shutil
import tarfile

Expand All @@ -22,6 +23,7 @@


logger = logging.getLogger(__name__)
assets_dir = Path(__file__).absolute().parent.joinpath("assets")

class DownloadBar(progress.bar.PixelBar):
message = "Downloading"
Expand Down Expand Up @@ -333,14 +335,20 @@ def _install_jars(self):

def _install_atx_agent(self):
logger.info("Install atx-agent %s", __atx_agent_version__)
if 'armeabi' in self.abis:
local_atx_agent_path = assets_dir.joinpath("atx-agent")
if local_atx_agent_path.exists():
logger.info("Use local atx-agent[armeabi]: %s", local_atx_agent_path)
dest = '/data/local/tmp/atx-agent'
self._device.sync.push(local_atx_agent_path, dest, mode=0o755)
return
self.push_url(self.atx_agent_url, tgz=True, extract_name="atx-agent")

def setup_atx_agent(self):
# stop atx-agent first
self.shell(self.atx_agent_path, "server", "--stop")
if self.is_atx_agent_outdated():
logger.info("Install atx-agent %s", __atx_agent_version__)
self.push_url(self.atx_agent_url, tgz=True, extract_name="atx-agent")
self._install_atx_agent()

self.shell(self.atx_agent_path, 'server', '--nouia', '-d', "--addr", self.__atx_listen_addr)
logger.info("Check atx-agent version")
Expand Down
3 changes: 2 additions & 1 deletion uiautomator2/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@
__jar_version__ = 'v0.1.6' # no useless for now.
# v0.1.6 first release version

__atx_agent_version__ = '0.10.0'
__atx_agent_version__ = '0.10.1' # sync.sh verison should also be updated
# 0.10.1 update androidbinary version, https://github.com/openatx/atx-agent/issues/115
# 0.10.0 remove tunnel code, use androidx.test.runner
# 0.9.6 fix security reason for remote control device
# 0.9.5 log support rotate, prevent log too large
Expand Down

0 comments on commit 9ed61ee

Please sign in to comment.