Skip to content

Commit

Permalink
Add support for adb connect.
Browse files Browse the repository at this point in the history
Minimum .NET version is now 4.0
  • Loading branch information
qmfrederik committed May 31, 2015
1 parent dee91de commit ba186b2
Show file tree
Hide file tree
Showing 6 changed files with 139 additions and 11 deletions.
5 changes: 2 additions & 3 deletions Managed.Adb.Console/Managed.Adb.Console.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,8 @@
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>MadBee.Console</RootNamespace>
<AssemblyName>Managed.Adb.Console</AssemblyName>
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
<TargetFrameworkProfile>
</TargetFrameworkProfile>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<TargetFrameworkProfile>Client</TargetFrameworkProfile>
<FileAlignment>512</FileAlignment>
</PropertyGroup>
<PropertyGroup Condition=" '$(CCNetLabel)' == '' ">
Expand Down
2 changes: 1 addition & 1 deletion Managed.Adb.Console/app.config
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<?xml version="1.0"?>
<configuration>
<startup><supportedRuntime version="v2.0.50727"/></startup></configuration>
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0,Profile=Client"/></startup></configuration>
7 changes: 4 additions & 3 deletions Managed.Adb.Tests/Managed.Adb.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Managed.Adb.Tests</RootNamespace>
<AssemblyName>Managed.Adb.Tests</AssemblyName>
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<TargetFrameworkProfile />
<TargetFrameworkProfile>
</TargetFrameworkProfile>
<SccProjectName>%24/madb/trunk/Managed.AndroidDebugBridge/Managed.Adb.Tests</SccProjectName>
<SccLocalPath>.</SccLocalPath>
<SccAuxPath>https://tfs.codeplex.com/tfs/tfs02</SccAuxPath>
Expand All @@ -39,7 +40,7 @@
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
<ItemGroup>
<Reference Include="Microsoft.VisualStudio.QualityTools.UnitTestFramework, Version=10.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" />
<Reference Include="Microsoft.VisualStudio.QualityTools.UnitTestFramework, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" />
<Reference Include="MoreLinq">
<HintPath>..\packages\morelinq.1.1.1\lib\net35\MoreLinq.dll</HintPath>
</Reference>
Expand Down
4 changes: 2 additions & 2 deletions Managed.Adb.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
</dependencies>
</metadata>
<files>
<file src="bin\x86\Release\Managed.Adb.dll" target="lib\net35" />
<file src="bin\x86\Release\Managed.Adb.pdb" target="lib\net35" />
<file src="bin\x86\Release\Managed.Adb.dll" target="lib\net40" />
<file src="bin\x86\Release\Managed.Adb.pdb" target="lib\net40" />
</files>
</package>
129 changes: 128 additions & 1 deletion Managed.Adb/AdbHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,12 @@ public class AdbHelper {
/// <summary>
/// The default encoding
/// </summary>
public static String DEFAULT_ENCODING = "ISO-8859-1";
public static String DEFAULT_ENCODING = "ISO-8859-1";

/// <summary>
/// The default port to use when connecting to a device over TCP/IP.
/// </summary>
private const int DEFAULT_PORT = 5555;

/// <summary>
/// Prevents a default instance of the <see cref="AdbHelper"/> class from being created.
Expand Down Expand Up @@ -978,6 +983,128 @@ public void Reboot(String into, IPEndPoint adbSockAddr, Device device) {
}
}

/// <summary>
/// Connect to a device via TCP/IP.
/// </summary>
/// <param name="helper">
/// An instance of the <see cref="AdbHelper"/> class.
/// </param>
/// <param name="adbEndpoint">
/// The socket where the <c>adb</c> server is listening.
/// </param>
/// <param name="address">
/// The IP address of the remote device.
/// </param>
/// <returns>
/// <c>0</c> if the operation completed successfully; otherwise,
/// <c>-1</c>.
/// </returns>
public int Connect(IPEndPoint adbEndpoint, IPAddress address)
{
if(address == null)
{
throw new ArgumentNullException("address");
}

return Connect(adbEndpoint, new IPEndPoint(address, DEFAULT_PORT));
}

/// <summary>
/// Connect to a device via TCP/IP.
/// </summary>
/// <param name="helper">
/// An instance of the <see cref="AdbHelper"/> class.
/// </param>
/// <param name="adbEndpoint">
/// The socket where the <c>adb</c> server is listening.
/// </param>
/// <param name="host">
/// The host address of the remote device.
/// </param>
/// <returns>
/// <c>0</c> if the operation completed successfully; otherwise,
/// <c>-1</c>.
/// </returns>
public int Connect(IPEndPoint adbEndpoint, string host)
{
if(string.IsNullOrEmpty(host))
{
throw new ArgumentNullException("host");
}

return this.Connect(adbEndpoint, new DnsEndPoint(host, DEFAULT_PORT));
}

/// <summary>
/// Connect to a device via TCP/IP.
/// </summary>
/// <param name="helper">
/// An instance of the <see cref="AdbHelper"/> class.
/// </param>
/// <param name="adbEndpoint">
/// The socket where the <c>adb</c> server is listening.
/// </param>
/// <param name="endpoint">
/// The IP endpoint at which the <c>adb</c> server on the device is running.
/// </param>
/// <returns>
/// <c>0</c> if the operation completed successfully; otherwise,
/// <c>-1</c>.
/// </returns>
public int Connect(IPEndPoint adbEndpoint, IPEndPoint endpoint)
{
if(endpoint == null)
{
throw new ArgumentNullException("endpoint");
}

return this.Connect(adbEndpoint, new DnsEndPoint(endpoint.Address.ToString(), endpoint.Port));
}

/// <summary>
/// Connect to a device via TCP/IP.
/// </summary>
/// <param name="helper">
/// An instance of the <see cref="AdbHelper"/> class.
/// </param>
/// <param name="adbEndpoint">
/// The socket where the <c>adb</c> server is listening.
/// </param>
/// <param name="endpoint">
/// The DNS endpoint at which the <c>adb</c> server on the device is running.
/// </param>
/// <returns>
/// <c>0</c> if the operation completed successfully; otherwise,
/// <c>-1</c>.
/// </returns>
public int Connect(IPEndPoint adbEndpoint, DnsEndPoint endpoint)
{
if (endpoint == null)
{
throw new ArgumentNullException("endpoint");
}

byte[] request = this.FormAdbRequest(string.Format("host:connect:{0}:{1}", endpoint.Host, endpoint.Port));

using (var socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp))
{
socket.Connect(adbEndpoint);
socket.Blocking = true;
if (!this.Write(socket, request))
{
throw new IOException("failed submitting request to adb");
}
var resp = this.ReadAdbResponse(socket, false);
if (!resp.IOSuccess || !resp.Okay)
{
Log.e(TAG, "Got timeout or unhappy response from ADB req: " + resp.Message);
socket.Close();
return -1;
}
return 0;
}
}

/// <summary>
/// Executes a raw socket command.
/// </summary>
Expand Down
3 changes: 2 additions & 1 deletion Managed.Adb/Managed.Adb.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Managed.Adb</RootNamespace>
<AssemblyName>Managed.Adb</AssemblyName>
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<FileUpgradeFlags>
</FileUpgradeFlags>
Expand Down Expand Up @@ -41,6 +41,7 @@
<SccProvider>SAK</SccProvider>
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\</SolutionDir>
<RestorePackages>true</RestorePackages>
<TargetFrameworkProfile>Client</TargetFrameworkProfile>
</PropertyGroup>
<PropertyGroup Condition=" '$(CCNetLabel)' == '' ">
<DefineConstants>TRACE;DEBUG</DefineConstants>
Expand Down

0 comments on commit ba186b2

Please sign in to comment.