[AdbRunner] Add ADB forward port management (follow-up to #305)#351
Draft
rmarinho wants to merge 1 commit intodotnet:mainfrom
Draft
[AdbRunner] Add ADB forward port management (follow-up to #305)#351rmarinho wants to merge 1 commit intodotnet:mainfrom
rmarinho wants to merge 1 commit intodotnet:mainfrom
Conversation
Adds the symmetric forward-port pair to the reverse-port methods that landed in dotnet#305. Same `AdbPortSpec` / `AdbPortRule` / `AdbProtocol` types — just four new methods. | Method | adb command | |-------------------------------------------------|--------------------------------------------| | ForwardPortAsync(serial, local, remote) | adb -s <serial> forward <local> <remote> | | RemoveForwardPortAsync(serial, local) | adb -s <serial> forward --remove <local> | | RemoveAllForwardPortsAsync(serial) | adb -s <serial> forward --remove-all | | ListForwardPortsAsync(serial) | adb forward --list (filtered by serial) | `adb forward` and `adb reverse` are not interchangeable — they connect opposite directions. `forward` is host->device (the IDE/harness reaches a service running on the device) and is the path used for JDWP debugger attach (`forward tcp:N jdwp:<pid>`), perf-tracing endpoints exposed by the runtime, and host-side DevFlow agent connect when the agent listens on a device port. Output-format note for `--list`: `adb forward --list` emits one line per rule across all devices in the form `<serial> <local> <remote>` (different from `(reverse) <remote> <local>`). `ListForwardPortsAsync` uses the unscoped `adb forward --list` and filters to the requested serial in `ParseForwardListOutput`. Serial match is case-sensitive (matches adb). ### Tests - 12 new parser tests in `ParseForwardListOutput_*` mirroring the reverse parser tests (single rule, multiple rules, serial filtering, empty output, malformed lines, non-tcp specs, Windows line endings, tab separation, case sensitivity). - 7 new parameter-validation tests covering empty serial / null spec for the four new public methods. ### Consumers - VS Code MAUI extension ServiceHub->CLI migration (`forwardPort` in `MauiAndroidPlatform.ts` — debugger configurations, perf tooling). - MAUI DevTools CLI (dotnet/maui-labs#197) — `maui android port forward` group, sibling of the existing `reverse` surface. - Visual Studio `ClientTools.Platform` — same paths that drive reverse today. Discussed in dotnet#305 (comment) Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This was referenced Apr 30, 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.
Summary
Adds the symmetric forward-port pair to the reverse-port methods that landed in #305. Same
AdbPortSpec/AdbPortRule/AdbProtocoltypes — just four new methods. Discussed in #305 (comment).ForwardPortAsync(serial, local, remote)adb -s <serial> forward <local> <remote>RemoveForwardPortAsync(serial, local)adb -s <serial> forward --remove <local>RemoveAllForwardPortsAsync(serial)adb -s <serial> forward --remove-allListForwardPortsAsync(serial)adb forward --list(filtered by serial)Why we need this in addition to reverse
adb forwardandadb reverseare not interchangeable — they connect opposite directions:reverse <remote-on-device> <local-on-host>— device-side socket forwards to host-side. Used by hot reload (the device app connects to a "device" port that's actually tunnelled to the IDE host).forward <local-on-host> <remote-on-device>— host-side socket forwards to device-side. Used when the IDE / harness needs to connect to a service running on the device:forward tcp:N jdwp:<pid>--listoutput format noteadb forward --listemits one line per rule across all devices in the form<serial> <local> <remote>(different from(reverse) <remote> <local>).ListForwardPortsAsyncuses the unscopedadb forward --listand filters to the requested serial inParseForwardListOutput. Serial match is case-sensitive to match adb's behaviour.Tests
ParseForwardListOutput_*) mirroring the reverse parser tests:All
Forward+Reversetests pass locally (36/36). Full suite has one pre-existing unrelatedJdkDirectory_JavaHomefailure onmainthat's not touched by this PR.Consumers
forwardPortinMauiAndroidPlatform.ts(debugger configurations, perf tooling).maui android port forward …group, sibling of the existingreversesurface.ClientTools.Platform— same paths that drive reverse today have parallel forward call-sites.Public API additions