Skip to content

fix: compare u2.jar size instead of md5 when setting up the jar - #1205

Merged
codeskyblue merged 1 commit into
masterfrom
agent/issue-1153-r70v48
Nov 14, 2026
Merged

codeskyblue merged 1 commit into
masterfrom
agent/issue-1153-r70v48

Conversation

@codeskyblue-agent

Copy link
Copy Markdown
Collaborator

This is by an automated agent, not a human.

变更

Replaced the md5-based u2.jar check in BasicUiautomatorServer with a file-size comparison over the adb sync channel. _setup_jar now calls _check_device_file_size, which gets the local size with os.path.getsize and the remote size with Device.sync.stat, returning False when the remote file is missing (mtime is None) or sizes differ. Since no adb shell toybox md5sum is executed anymore, the AdbError: closed that aborted connect() on affected machines can no longer break the jar setup step.

改动

  • uiautomator2/core.py: renamed _check_device_file_hash to _check_device_file_size and implemented it with os.path.getsize + Device.sync.stat; removed the now-unused hashlib import and updated the _setup_jar call site.
  • tests/test_core.py: replaced the md5/toybox tests with three size-based cases (same size -> True, size mismatch -> False, missing file -> False) and asserted that no shell command is used.

Closes #1153

提交

5d98b41 fix: compare u2.jar size instead of md5 to avoid adb shell failures

检查

✅ 检查通过(2 项)

  • ✅ poetry install
  • ✅ pytest tests

功能验证

  • poetry install --no-interaction
  • poetry run pytest tests -q (216 passed)
  • Android emulator end-to-end check (Pixel_5_API_34_LARGE, Android 14, emulator-5554), with AdbDevice.shell patched to raise adbutils.AdbError("closed") for any md5/md5sum command: first u2.connect() succeeded and pushed the 3.7 MB u2.jar, second connect reused it (mtime unchanged), truncating the remote jar re-pushed it, and _check_device_file_size returned True/False for existing/missing files with zero md5 shell calls
  • Emulator stopped with adb emu kill afterwards

UI 验证

未涉及 UI 改动,无截图。

tests/test_core.py   | 124 +++++++++++++++------------------------------------
 uiautomator2/core.py |  23 +++++-----
 2 files changed, 47 insertions(+), 100 deletions(-)

Checking the remote jar with `adb shell toybox md5sum` fails with
AdbError: closed on some machines/devices, which aborts connect()
before the jar is pushed. Use the sync channel (sync.stat) and compare
file sizes instead, so no device-side shell is involved.
@codecov

codecov Bot commented Nov 14, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 87.50000% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 45.26%. Comparing base (5d373ad) to head (5d98b41).
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
uiautomator2/core.py 87.50% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1205      +/-   ##
==========================================
- Coverage   45.31%   45.26%   -0.06%     
==========================================
  Files          29       29              
  Lines        4162     4158       -4     
  Branches      813      812       -1     
==========================================
- Hits         1886     1882       -4     
  Misses       2164     2164              
  Partials      112      112              

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

@codeskyblue
codeskyblue merged commit eb1542f into master Nov 14, 2026
5 of 7 checks passed
@codeskyblue
codeskyblue deleted the agent/issue-1153-r70v48 branch November 14, 2026 05:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

adbutils.errors.AdbError: closed when connecting to device via USB in uiautomator2

2 participants