Testing USB accessory on real device

The test setup consists of an Android phone with an accessory device connected to the USB port. Appium is connected to the phone via WiFi and the test runs fine to the point where the accessory wakes up and connects to the USB port. The state transition on the USB point causes ADB to reset which drops the TCP connection. The Appium session stays up however and unlike UIAutomator, UIAutomator2 appears to keep running, so it seems like it might be possible to reconnect the test to the phone and resume the session without disturbing the current state of the app under test.

To do that however, I need to reverse engineer the connection process. Currently, my test reconnects to the phone successfully and re-establishes the port forwarding to UIAutomator2. The next Appium command starts, but fails with a rather long error message, the gist of which is that the UIAutomator2 is not connected. It’s not clear to me from the logs where the connection is set up.

So -

I would be interested if anyone knows how to prevent adb from resetting whenever the phone’s usb port changes state, or barring that, clues on how to re-establish the connection to UIAutomator2 after a reset, without disrupting the current state of the app on the phone, (ie closing the session and restarting is out).

All of us developing USB accessories would be grateful.


1 Like