Skip to content

Commit eafd563

Browse files
committed
manual merge of change submitted in PR #19
1 parent d1791a5 commit eafd563

File tree

4 files changed

+76
-4
lines changed

4 files changed

+76
-4
lines changed

.appveyor/appveyor.before-build.ps1

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,11 @@ try {
77
Import-Module "$env:APPVEYOR_BUILD_FOLDER\.appveyor\modules\Import-PfxCertificate.psm1";
88
Import-Module "$env:APPVEYOR_BUILD_FOLDER\.appveyor\modules\Set-BuildVersion.psm1";
99

10-
11-
Import-PfxCertificate -pfx "$env:APPVEYOR_BUILD_FOLDER\Shared\madb.pfx" -password ((Get-Item Env:\MADB_PFX_KEY).Value) -containerName ((Get-Item Env:\VS_PFX_KEY).Value);
12-
10+
if( (Test-Path -Path 'Env:\VS_PFX_KEY') -and (Test-Path -Path Env:\MADB_PFX_KEY) ) {
11+
Import-PfxCertificate -pfx "$env:APPVEYOR_BUILD_FOLDER\Shared\madb.pfx" -password ((Get-Item Env:\MADB_PFX_KEY).Value) -containerName ((Get-Item Env:\VS_PFX_KEY).Value);
12+
} else {
13+
"VS_PFX_KEY and MAD_PFX_KEY are missing; skipping PFX Certificate import." | Write-Warning;
14+
}
1315
$env:CI_BUILD_DATE = ((Get-Date).ToUniversalTime().ToString("MM-dd-yyyy"));
1416
$env:CI_BUILD_TIME = ((Get-Date).ToUniversalTime().ToString("hh:mm:ss"));
1517

Managed.AndroidDebugBridge/AdbHelper.cs

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -547,6 +547,51 @@ public bool CreateForward ( IPEndPoint adbSockAddr, Device device, int localPort
547547
return true;
548548
}
549549

550+
/// <summary>
551+
/// Creates the reverse forward.
552+
/// </summary>
553+
/// <param name="adbSockAddr">The adb sock addr.</param>
554+
/// <param name="device">The device.</param>
555+
/// <param name="remotePort">The remote port.</param>
556+
/// <param name="localPort">The local port.</param>
557+
/// <returns></returns>
558+
/// <exception cref="Managed.Adb.Exceptions.AdbException">
559+
/// failed to submit the forward command.
560+
/// or
561+
/// Device rejected command: + resp.Message
562+
/// </exception>
563+
public bool CreateReverseForward ( IPEndPoint adbSockAddr, Device device, int remotePort, int localPort ) {
564+
565+
Socket adbChan = new Socket ( AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp );
566+
try {
567+
adbChan.Connect ( adbSockAddr );
568+
adbChan.Blocking = true;
569+
570+
// if the device is not -1, then we first tell adb we're looking to talk
571+
// to a specific device
572+
SetDevice ( adbChan, device );
573+
574+
byte[] request = FormAdbRequest ( String.Format ( "reverse:forward:tcp:{0};tcp:{1}", //$NON-NLS-1$
575+
remotePort, localPort ) );
576+
577+
if ( !Write ( adbChan, request ) ) {
578+
throw new AdbException ( "failed to submit the reverse forward command." );
579+
}
580+
581+
AdbResponse resp = ReadAdbResponse ( adbChan, false /* readDiagString */);
582+
if ( !resp.IOSuccess || !resp.Okay ) {
583+
throw new AdbException ( "Device rejected command: " + resp.Message );
584+
}
585+
} finally {
586+
if ( adbChan != null ) {
587+
adbChan.Close ( );
588+
}
589+
}
590+
591+
return true;
592+
}
593+
594+
550595
/// <summary>
551596
/// Lists the forward.
552597
/// </summary>

Managed.AndroidDebugBridge/Device.cs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -720,7 +720,24 @@ public bool CreateForward ( int localPort, int remotePort ) {
720720
return false;
721721
}
722722
}
723-
723+
724+
725+
/// <summary>
726+
/// Creates a reverse port forwarding between a local and a remote port.
727+
/// </summary>
728+
/// <param name="remotePort">the remote port to forward</param>
729+
/// <param name="localPort">the local port.</param>
730+
/// <returns><code>true</code> if success.</returns>
731+
public bool CreateReverseForward ( int remotePort, int localPort )
732+
{
733+
try {
734+
return AdbHelper.Instance.CreateReverseForward(AndroidDebugBridge.SocketAddress, this, remotePort, localPort);
735+
} catch(IOException e) {
736+
Log.w("ddms", e);
737+
return false;
738+
}
739+
}
740+
724741
/// <summary>
725742
/// Removes a port forwarding between a local and a remote port.
726743
/// </summary>

Managed.AndroidDebugBridge/IDevice.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,14 @@ public interface IDevice {
280280
/// <returns><code>true</code> if success.</returns>
281281
bool CreateForward(int localPort, int remotePort);
282282

283+
/// <summary>
284+
/// Creates a reverse port forwarding between a local and a remote port.
285+
/// </summary>
286+
/// <param name="remotePort">the remote port to forward</param>
287+
/// <param name="localPort">the local port.</param>
288+
/// <returns><code>true</code> if success.</returns>
289+
bool CreateReverseForward ( int remotePort, int localPort );
290+
283291
/// <summary>
284292
/// Removes a port forwarding between a local and a remote port.
285293
/// </summary>

0 commit comments

Comments
 (0)