K-man
K-man

Reputation: 364

Ethernet over USB + ADB | Dynamically switch between Host and Peripheral mode in OTG

Problem:

I own an android device in a remote location that I use to run various tests and operations. I need to be able to send ADB commands while also connect the phone to a wired internet connection. For various reasons, I cannot connect the device to WiFi, nor can I root the device. Due to USB Enumeration structure, if I connect a USB hub to the phone with an Ethernet port and a USB connection to a PC, the options are either Phone in Host + Internet but no ADB, or phone in Peripheral mode with ADB but no ethernet connection.

What I have tried:

What I want to do: I'm wondering if I can purchase a Raspberry Pi or some other microcontroller, and implement a solution using Session Request Protocol (SRP) and/or Host negotiation Protocol (HNP) described in On-The-Go (OTG) as follows:

  1. Software in Android/external code detects when adbd is in USB mode, and renegotiates the connection to Android being in device mode. Companion uses USB connection to send adb tcpip 5555.
  2. Once adbd is set to TCP mode, software (using getprop) checks that phone accepts ADB over network, and renegotiates the usb connection such that the Android is now Host, and accepts the companion device as an Ethernet dongle, and internet flows to the device.

This way, the network connection to the device (including sending ADB commands) remains stable even after device reset. There are also power considerations, but they are secondary.

Upvotes: 2

Views: 1860

Answers (1)

RE_Specto
RE_Specto

Reputation: 49

Sounds like quite of a challenge..

Afaik the PI zero is able to act as both usb host as well as usb Ethernet Gadget. you may be able to leverage that to send an 'adb tcpip 5555' from the PI, then switch modes, and share the PI's connection to android. however if you cannot use the wifi on the PI as well, you'll need to provide it with ethernet via GPIO, not sure how it's done on the zero.

As well the ability of the PI to switch modes on the fly without reconnecting the usb cable needs to be verified.

Another way would be using a rooted android, and set the local equivalent of the adb command (at each boot?).

A side note: I have tried your first method of issuing an adb command via usb to my pc, and then switching cables to an otg ethernet adapter, and besides not surviving a reboot, the performance of scrcpy which is my use case for remote debug was less than acceptable.

I have ended up using the usb, and the combination of gnirehtet and scrcpy over usb with some great performance, and no electromagnetic radiation emitted from my phone besides the basic cell service, while the rest of its comms are handled via usb, with the only caveat of having to accept vpn connection once, which is done via scrcpy as well without touching the phone.

Upvotes: 0

Related Questions