openatx / uiautomator2

Android Uiautomator2 Python Wrapper
MIT License
6.41k stars 1.38k forks source link

手机恢复出厂设置第一次测试大概率有部分机器第一次初始化失败 #836

Closed sofialoveeef closed 1 month ago

sofialoveeef commented 1 year ago

代码:

import time
import uiautomator2 as u2
import adbutils
import threading
from logzero import logger

def list_test(d: u2.Device):
    try:
        print(d.info)
        print("done")
    except Exception as e:
        print(str(e))

for dev in adbutils.adb.device_list():
    d = u2.connect(dev.serial)
    t = threading.Thread(target=list_test, args=(d,))
    t.start()

报错信息:

/home/huchengbo/anaconda3/bin/python3.8 /home/huchengbo/SAM_PRESSURE/thread.py
[W 221013 17:12:03 __init__:218] [pid:809] atx-agent has something wrong, auto recovering
[D 221013 17:12:03 __init__:317] [pid:809] [BS98215AA1262800137] device BS98121AA1232500453 is online
[W 221013 17:12:03 __init__:218] [pid:809] atx-agent has something wrong, auto recovering
[D 221013 17:12:03 __init__:317] [pid:809] [BS98215AA1262800137] device BS98215AA1262800078 is online
[W 221013 17:12:03 __init__:218] [pid:809] atx-agent has something wrong, auto recovering
[D 221013 17:12:03 __init__:317] [pid:809] [BS98215AA1262800137] device BS98215AA1262800137 is online
[I 221013 17:12:04 init:156] uiautomator2 version: 2.16.17
[D 221013 17:12:04 init:167] Shell: ('/data/local/tmp/atx-agent', 'server', '--stop')
[I 221013 17:12:04 init:346] Install atx-agent 0.10.0
[D 221013 17:12:04 init:59] Use cached assets: /home/huchengbo/.uiautomator2/cache/atx-agent_0.10.0_linux_armv7.tar.gz-cf3333ae7b/atx-agent_0.10.0_linux_armv7.tar.gz
[I 221013 17:12:04 init:156] uiautomator2 version: 2.16.17
[D 221013 17:12:04 init:167] Shell: ('/data/local/tmp/atx-agent', 'server', '--stop')
[I 221013 17:12:04 init:346] Install atx-agent 0.10.0
[D 221013 17:12:04 init:59] Use cached assets: /home/huchengbo/.uiautomator2/cache/atx-agent_0.10.0_linux_armv7.tar.gz-cf3333ae7b/atx-agent_0.10.0_linux_armv7.tar.gz
[I 221013 17:12:04 init:156] uiautomator2 version: 2.16.17
[D 221013 17:12:04 init:167] Shell: ('/data/local/tmp/atx-agent', 'server', '--stop')
[I 221013 17:12:04 init:346] Install atx-agent 0.10.0
[D 221013 17:12:04 init:59] Use cached assets: /home/huchengbo/.uiautomator2/cache/atx-agent_0.10.0_linux_armv7.tar.gz-cf3333ae7b/atx-agent_0.10.0_linux_armv7.tar.gz
[D 221013 17:12:04 init:238] Push to /data/local/tmp/atx-agent:0755
[D 221013 17:12:04 init:167] Shell: ('/data/local/tmp/atx-agent', 'server', '--nouia', '-d', '--addr', '127.0.0.1:7912')
[D 221013 17:12:04 init:238] Push to /data/local/tmp/atx-agent:0755
[I 221013 17:12:04 init:350] Check atx-agent version
[D 221013 17:12:04 init:359] Forward: local:tcp:56855 -> remote:tcp:7912
[D 221013 17:12:04 init:238] Push to /data/local/tmp/atx-agent:0755
[D 221013 17:12:04 init:167] Shell: ('/data/local/tmp/atx-agent', 'server', '--nouia', '-d', '--addr', '127.0.0.1:7912')
[D 221013 17:12:04 init:167] Shell: ('/data/local/tmp/atx-agent', 'server', '--nouia', '-d', '--addr', '127.0.0.1:7912')
[D 221013 17:12:05 init:359] Forward: local:tcp:56855 -> remote:tcp:7912
[I 221013 17:12:05 init:350] Check atx-agent version
[D 221013 17:12:05 init:359] Forward: local:tcp:41189 -> remote:tcp:7912
[I 221013 17:12:05 init:350] Check atx-agent version
[D 221013 17:12:05 init:359] Forward: local:tcp:60427 -> remote:tcp:7912
[D 221013 17:12:05 init:359] Forward: local:tcp:56855 -> remote:tcp:7912
[D 221013 17:12:05 init:359] Forward: local:tcp:41189 -> remote:tcp:7912
[D 221013 17:12:05 init:362] atx-agent version 0.10.0
[D 221013 17:12:05 init:365] device wlan ip: wlan0 have no ip address
[D 221013 17:12:05 init:359] Forward: local:tcp:60427 -> remote:tcp:7912
[D 221013 17:12:05 init:362] atx-agent version 0.10.0
[D 221013 17:12:05 init:365] device wlan ip: wlan0 have no ip address
[D 221013 17:12:05 __init__:656] [pid:809] [BS98215AA1262800137] kill process(ps): uiautomator
[D 221013 17:12:05 __init__:656] [pid:809] [BS98215AA1262800137] kill process(ps): uiautomator
[D 221013 17:12:06 init:359] Forward: local:tcp:56855 -> remote:tcp:7912
[D 221013 17:12:06 __init__:387] [pid:809] [BS98215AA1262800137] Install app-uiautomator.apk
[D 221013 17:12:06 __init__:387] [pid:809] [BS98215AA1262800137] Install app-uiautomator.apk
[D 221013 17:12:06 init:359] Forward: local:tcp:56855 -> remote:tcp:7912
[D 221013 17:12:06 __init__:387] [pid:809] [BS98215AA1262800137] Install app-uiautomator-test.apk
[D 221013 17:12:06 __init__:387] [pid:809] [BS98215AA1262800137] Install app-uiautomator-test.apk
[D 221013 17:12:07 init:359] Forward: local:tcp:56855 -> remote:tcp:7912
[D 221013 17:12:07 init:359] Forward: local:tcp:56855 -> remote:tcp:7912
[D 221013 17:12:07 __init__:677] [pid:809] [BS98215AA1262800137] uiautomator-v2 is starting ... left: 40.0s
[D 221013 17:12:07 __init__:677] [pid:809] [BS98215AA1262800137] uiautomator-v2 is starting ... left: 40.0s
[D 221013 17:12:08 init:359] Forward: local:tcp:56855 -> remote:tcp:7912
[D 221013 17:12:08 init:359] Forward: local:tcp:56855 -> remote:tcp:7912
[D 221013 17:12:08 __init__:677] [pid:809] [BS98215AA1262800137] uiautomator-v2 is starting ... left: 39.0s
[D 221013 17:12:08 __init__:677] [pid:809] [BS98215AA1262800137] uiautomator-v2 is starting ... left: 39.0s
[D 221013 17:12:09 init:359] Forward: local:tcp:56855 -> remote:tcp:7912
('Connection aborted.', RemoteDisconnected('Remote end closed connection without response'))
[D 221013 17:12:09 __init__:677] [pid:809] [BS98215AA1262800137] uiautomator-v2 is starting ... left: 37.9s
[D 221013 17:12:09 __init__:677] [pid:809] [BS98215AA1262800137] uiautomator-v2 is starting ... left: 37.9s
[D 221013 17:12:09 __init__:691] [pid:809] [BS98215AA1262800137] show float window
[D 221013 17:12:10 __init__:677] [pid:809] [BS98215AA1262800137] uiautomator-v2 is starting ... left: 36.9s
[D 221013 17:12:10 __init__:677] [pid:809] [BS98215AA1262800137] uiautomator-v2 is starting ... left: 36.7s
[D 221013 17:12:11 __init__:677] [pid:809] [BS98215AA1262800137] uiautomator-v2 is starting ... left: 35.7s
[D 221013 17:12:12 __init__:677] [pid:809] [BS98215AA1262800137] uiautomator-v2 is starting ... left: 35.8s
[D 221013 17:12:12 __init__:677] [pid:809] [BS98215AA1262800137] uiautomator-v2 is starting ... left: 34.7s
[I 221013 17:12:13 __init__:638] [pid:809] [BS98215AA1262800137] uiautomator back to normal
[D 221013 17:12:13 __init__:677] [pid:809] [BS98215AA1262800137] uiautomator-v2 is starting ... left: 34.8s
{'currentPackageName': 'com.android.launcher3', 'displayHeight': 1503, 'displayRotation': 0, 'displaySizeDpX': 411, 'displaySizeDpY': 937, 'displayWidth': 720, 'productName': 'Lion_EEA', 'screenOn': True, 'sdkInt': 31, 'naturalOrientation': True}
done
[D 221013 17:12:14 __init__:677] [pid:809] [BS98215AA1262800137] uiautomator-v2 is starting ... left: 33.7s
[D 221013 17:12:14 __init__:691] [pid:809] [BS98215AA1262800137] show float window
[D 221013 17:12:15 __init__:677] [pid:809] [BS98215AA1262800137] uiautomator-v2 is starting ... left: 32.5s
[D 221013 17:12:16 __init__:677] [pid:809] [BS98215AA1262800137] uiautomator-v2 is starting ... left: 31.5s
[D 221013 17:12:17 __init__:677] [pid:809] [BS98215AA1262800137] uiautomator-v2 is starting ... left: 30.5s
[D 221013 17:12:18 __init__:677] [pid:809] [BS98215AA1262800137] uiautomator-v2 is starting ... left: 29.5s
[D 221013 17:12:19 __init__:677] [pid:809] [BS98215AA1262800137] uiautomator-v2 is starting ... left: 28.5s
[D 221013 17:12:20 __init__:677] [pid:809] [BS98215AA1262800137] uiautomator-v2 is starting ... left: 27.4s
[D 221013 17:12:21 __init__:677] [pid:809] [BS98215AA1262800137] uiautomator-v2 is starting ... left: 26.4s
[D 221013 17:12:22 __init__:677] [pid:809] [BS98215AA1262800137] uiautomator-v2 is starting ... left: 25.4s
[I 221013 17:12:22 __init__:638] [pid:809] [BS98215AA1262800137] uiautomator back to normal
{'currentPackageName': 'com.android.settings', 'displayHeight': 1503, 'displayRotation': 0, 'displaySizeDpX': 411, 'displaySizeDpY': 937, 'displayWidth': 720, 'productName': 'Lion', 'screenOn': True, 'sdkInt': 31, 'naturalOrientation': True}
done

进程已结束,退出代码为 0

2022-10-13 17-27-57 的屏幕截图 问题描述: 上面的log中,挂测了了三台机器,sn号分别为:BS98121AA1232500453,BS98215AA1262800078,BS98215AA1262800137,其中一台报错('Connection aborted.', RemoteDisconnected('Remote end closed connection without response')),之后就无法获取d.info信息,查看手机任何apk都没有安装。并且atx-agent上传不完整,如上图所示。 测试机器:LENOVO平板,Tmobile 系统:android 12 其他尝试过的代码: 多进程并行:

import time
import uiautomator2 as u2
import adbutils
import multiprocessing
from logzero import logger

def list_test(dev: str):
    try:
        print(dev)
        d = u2.connect(dev)
        print(d.info)
        print("done")
    except Exception as e:
        print(str(e))

pool = multiprocessing.Pool(processes=3)
for dev in adbutils.adb.device_list():
    sn = dev.serial
    pool.apply_async(list_test, args=(sn, ))

pool.close()
pool.join()
print("all done")

和多线程一样的报错。 尝试过的解决办法: 循环连接,直到能打印d.info为止,大概率会一台一台连接。