@@ -244,99 +244,48 @@ public async Task StopEmulatorAsync (string serial, CancellationToken cancellati
244244 return null ;
245245 }
246246
247- #pragma warning disable RS0026 , RS0027 // Multiple overloads with optional parameters are intentional for API convenience
248247 /// <summary>
249- /// Sets up reverse port forwarding from the device to the host via
250- /// 'adb -s <serial> reverse <remote> <local>'.
251- /// Supports any socket spec accepted by adb (tcp:PORT, localabstract:NAME, etc.).
252- /// This is the core overload; the typed and int convenience overloads delegate here.
248+ /// Sets up reverse port forwarding via 'adb -s <serial> reverse <remote> <local>'.
253249 /// </summary>
254250 /// <param name="serial">Device serial number.</param>
255- /// <param name="remote">Remote (device-side) socket spec, e.g. "tcp:5000" or "localabstract:foo" .</param>
256- /// <param name="local">Local (host-side) socket spec, e.g. "tcp:5000" .</param>
251+ /// <param name="remote">Remote (device-side) port spec.</param>
252+ /// <param name="local">Local (host-side) port spec.</param>
257253 /// <param name="cancellationToken">Cancellation token.</param>
258- public virtual async Task ReversePortAsync ( string serial , string remote , string local , CancellationToken cancellationToken = default )
254+ public virtual async Task ReversePortAsync ( string serial , AdbPortSpec remote , AdbPortSpec local , CancellationToken cancellationToken = default )
259255 {
260256 if ( string . IsNullOrWhiteSpace ( serial ) )
261257 throw new ArgumentException ( "Serial must not be empty." , nameof ( serial ) ) ;
262- if ( string . IsNullOrWhiteSpace ( remote ) )
263- throw new ArgumentException ( "Remote socket spec must not be empty." , nameof ( remote ) ) ;
264- if ( string . IsNullOrWhiteSpace ( local ) )
265- throw new ArgumentException ( "Local socket spec must not be empty." , nameof ( local ) ) ;
266-
267- var psi = ProcessUtils . CreateProcessStartInfo ( adbPath , "-s" , serial , "reverse" , remote , local ) ;
268- using var stderr = new StringWriter ( ) ;
269- var exitCode = await ProcessUtils . StartProcess ( psi , null , stderr , cancellationToken , environmentVariables ) . ConfigureAwait ( false ) ;
270- ProcessUtils . ThrowIfFailed ( exitCode , $ "adb -s { serial } reverse { remote } { local } ", stderr ) ;
271- }
272-
273- /// <summary>
274- /// Typed overload: sets up reverse port forwarding using <see cref="AdbPortSpec"/> values.
275- /// </summary>
276- public virtual Task ReversePortAsync ( string serial , AdbPortSpec remote , AdbPortSpec local , CancellationToken cancellationToken = default )
277- {
278258 if ( remote is null )
279259 throw new ArgumentNullException ( nameof ( remote ) ) ;
280260 if ( local is null )
281261 throw new ArgumentNullException ( nameof ( local ) ) ;
282- return ReversePortAsync ( serial , remote . ToSocketSpec ( ) , local . ToSocketSpec ( ) , cancellationToken ) ;
283- }
284262
285- /// <summary>
286- /// TCP convenience overload: sets up reverse port forwarding via
287- /// 'adb -s <serial> reverse tcp:<remotePort> tcp:<localPort>'.
288- /// </summary>
289- public virtual Task ReversePortAsync ( string serial , int remotePort , int localPort , CancellationToken cancellationToken = default )
290- {
291- ValidatePort ( remotePort , nameof ( remotePort ) ) ;
292- ValidatePort ( localPort , nameof ( localPort ) ) ;
293- return ReversePortAsync ( serial , new AdbPortSpec ( AdbProtocol . Tcp , remotePort ) , new AdbPortSpec ( AdbProtocol . Tcp , localPort ) , cancellationToken ) ;
263+ var psi = ProcessUtils . CreateProcessStartInfo ( adbPath , "-s" , serial , "reverse" , remote . ToSocketSpec ( ) , local . ToSocketSpec ( ) ) ;
264+ using var stderr = new StringWriter ( ) ;
265+ var exitCode = await ProcessUtils . StartProcess ( psi , null , stderr , cancellationToken , environmentVariables ) . ConfigureAwait ( false ) ;
266+ ProcessUtils . ThrowIfFailed ( exitCode , $ "adb -s { serial } reverse { remote } { local } ", stderr ) ;
294267 }
295- #pragma warning restore RS0026 , RS0027
296268
297- #pragma warning disable RS0026 , RS0027 // Multiple overloads with optional parameters are intentional for API convenience
298269 /// <summary>
299270 /// Removes a specific reverse port forwarding rule via
300271 /// 'adb -s <serial> reverse --remove <remote>'.
301- /// Supports any socket spec accepted by adb.
302272 /// </summary>
303273 /// <param name="serial">Device serial number.</param>
304- /// <param name="remote">Remote (device-side) socket spec to remove, e.g. "tcp:5000" .</param>
274+ /// <param name="remote">Remote (device-side) port spec to remove.</param>
305275 /// <param name="cancellationToken">Cancellation token.</param>
306- public virtual async Task RemoveReversePortAsync ( string serial , string remote , CancellationToken cancellationToken = default )
276+ public virtual async Task RemoveReversePortAsync ( string serial , AdbPortSpec remote , CancellationToken cancellationToken = default )
307277 {
308278 if ( string . IsNullOrWhiteSpace ( serial ) )
309279 throw new ArgumentException ( "Serial must not be empty." , nameof ( serial ) ) ;
310- if ( string . IsNullOrWhiteSpace ( remote ) )
311- throw new ArgumentException ( "Remote socket spec must not be empty." , nameof ( remote ) ) ;
280+ if ( remote is null )
281+ throw new ArgumentNullException ( nameof ( remote ) ) ;
312282
313- var psi = ProcessUtils . CreateProcessStartInfo ( adbPath , "-s" , serial , "reverse" , "--remove" , remote ) ;
283+ var psi = ProcessUtils . CreateProcessStartInfo ( adbPath , "-s" , serial , "reverse" , "--remove" , remote . ToSocketSpec ( ) ) ;
314284 using var stderr = new StringWriter ( ) ;
315285 var exitCode = await ProcessUtils . StartProcess ( psi , null , stderr , cancellationToken , environmentVariables ) . ConfigureAwait ( false ) ;
316286 ProcessUtils . ThrowIfFailed ( exitCode , $ "adb -s { serial } reverse --remove { remote } ", stderr ) ;
317287 }
318288
319- /// <summary>
320- /// Typed overload: removes a specific reverse port forwarding rule using <see cref="AdbPortSpec"/>.
321- /// </summary>
322- public virtual Task RemoveReversePortAsync ( string serial , AdbPortSpec remote , CancellationToken cancellationToken = default )
323- {
324- if ( remote is null )
325- throw new ArgumentNullException ( nameof ( remote ) ) ;
326- return RemoveReversePortAsync ( serial , remote . ToSocketSpec ( ) , cancellationToken ) ;
327- }
328-
329- /// <summary>
330- /// TCP convenience overload: removes a specific reverse port forwarding rule via
331- /// 'adb -s <serial> reverse --remove tcp:<remotePort>'.
332- /// </summary>
333- public virtual Task RemoveReversePortAsync ( string serial , int remotePort , CancellationToken cancellationToken = default )
334- {
335- ValidatePort ( remotePort , nameof ( remotePort ) ) ;
336- return RemoveReversePortAsync ( serial , new AdbPortSpec ( AdbProtocol . Tcp , remotePort ) , cancellationToken ) ;
337- }
338- #pragma warning restore RS0026 , RS0027
339-
340289 /// <summary>
341290 /// Removes all reverse port forwarding rules via
342291 /// 'adb -s <serial> reverse --remove-all'.
@@ -400,12 +349,6 @@ internal static IReadOnlyList<AdbPortRule> ParseReverseListOutput (IEnumerable<s
400349 return rules ;
401350 }
402351
403- static void ValidatePort ( int port , string paramName )
404- {
405- if ( port <= 0 || port > 65535 )
406- throw new ArgumentOutOfRangeException ( paramName , port , "Port must be between 1 and 65535." ) ;
407- }
408-
409352 /// <summary>
410353 /// Parses the output lines from 'adb devices -l'.
411354 /// Accepts an <see cref="IEnumerable{T}"/> to avoid allocating a joined string.
0 commit comments