Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Oct 28, 2025

During initialization, uiautomator2 unnecessarily re-pushes u2.jar to devices even when the file already exists with the correct hash. This occurs on devices lacking the toybox utility, causing MD5 verification to fail.

Changes

Core Logic (uiautomator2/core.py)

  • Added fallback from toybox md5sum to md5 command when toybox is unavailable
  • Checks for both "toybox" and "not found" in output to avoid false positives
def _check_device_file_hash(self, local_file: Union[str, Path], remote_file: str) -> bool:
    output = self._dev.shell(["toybox", "md5sum", remote_file])
    if "toybox" in output and "not found" in output:
        output = self._dev.shell(["md5", remote_file])
    return local_md5 in output

Tests (tests/test_core.py)

  • New test suite covering toybox success, fallback behavior, hash mismatch, and command failures
  • Uses pytest fixture to reduce test code duplication
Original prompt

This section details on the original issue you should resolve

<issue_title>uiautomator2 在初始化时,尽管目标设备已有相同的u2.jar,还是会重新再次push u2.jar</issue_title>
<issue_description>版本号
uiautodev 0.10.0
uiautomator2 3.4.0

现象
uiautomator2 在初始化时,尽管目标设备已有相同的u2.jar,还是会重新再次push u2.jar

原因

  1. BasicUiautomatorServer 在初始化时会start_uiautomator()
  2. _setup_jar()的过程中会对本地和设备的 jar 包的 md5 值进行对比
  3. 部分设备里面其实是没有toybox这个工具的,导致获取不到 md5 值(见下图)
    Image

建议优化
先尝试用toybox md5sum 获取,获取不到则同 md5 直接获取。

    def _check_device_file_hash(self, local_file: Union[str, Path], remote_file: str) -> bool:
        """ check if remote file hash is correct """
        ...
        output = self._dev.shell(["toybox", "md5sum", remote_file])
        if "not found" in output:
            output = self._dev.shell(["md5", remote_file])
        return local_md5 in output
```</issue_description>

## Comments on the Issue (you are @copilot in this section)

<comments>
</comments>


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

@sonarqubecloud
Copy link

Quality Gate Failed Quality Gate failed

Failed conditions
3 Security Hotspots

See analysis details on SonarQube Cloud

Copilot AI changed the title [WIP] Optimize uiautomator2 jar file push process Fix MD5 hash check fallback for devices without toybox Oct 28, 2025
Copilot AI requested a review from codeskyblue October 28, 2025 13:50
Copilot finished work on behalf of codeskyblue October 28, 2025 13:50
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.

uiautomator2 在初始化时,尽管目标设备已有相同的u2.jar,还是会重新再次push u2.jar

2 participants