Repository navigation
Support adb reverse through the TcpUsb bridge - #550
Merged
Merged
Conversation
The bridge only relays client-initiated streams. With `adb reverse`, the device's adbd connects the reverse stream to the adb server it is attached to, i.e. the bridge's host, so the client never sees it. Android Studio's Device Mirroring and scrcpy's default tunnel rely on adb reverse, and fail through the bridge (Studio's agent exits with code 0; scrcpy needs --force-adb-forward). reverse:forward:<remote>;<local> is now rewritten to point <remote> at a listener on the bridge host. Each connection to it is relayed to the client as a device-initiated A_OPEN <local>, which is what a USB-attached device's adbd sends. reverse:killforward and killforward-all close the listeners, and they close with the socket. The rewrite is skipped when the adb server is not on the bridge's host, since that server has to be able to reach the listener. Signed-off-by: Arthur Yazhevich <[email protected]>
koral--
approved these changes
Oct 5, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
adb reversedoesn't work through the TcpUsb bridge (createTcpUsbBridge, used by STF for remote debugging). The bridge only relays streams the client opens. A reverse stream is opened by the device's adbd towards the adb server it's attached to, which is the bridge's host, so it never reaches the client. Android Studio's Device Mirroring and scrcpy's default tunnel both depend on it: Studio's mirroring agent exits with code 0, and scrcpy only works with--force-adb-forward.Change
reverse:forward:reverse:forward:[norebind:]<remote>;<local>now points<remote>at a listener on the bridge host (127.0.0.1:<ephemeral>).A_OPEN <local>, the same packet a USB-attached device's adbd sends. The newReverseStreamcarries the A_OKAY/A_WRTE/A_CLSE exchange.A_OKAYis flushed first, then closed.reverse:killforwardandreverse:killforward-allclose the matching listeners, and all listeners close when the bridge socket ends.Known limitation:
adb reverse --listshows the bridge's listener port as the local side, not the original<local>.Testing
test/adb/tcpusb/socket.ts(rewrite, pass-through, killforward, relay with a half-close).npm test: 203 passing.npm run lintfails onmasterbefore this change..eslintrcextendsprettier/@typescript-eslint, which eslint-config-prettier 8 removed. Prettier passes on the changed files.adb reverse tcp:9123 tcp:9123plusncon the device reaches a listener on the client host and gets its reply.--force-adb-forward.