Skip to content

Commit

Permalink
Merge pull request quamotion#88 from quamotion/fixes/adb-disconnect
Browse files Browse the repository at this point in the history
Add support for adb disconnect.
  • Loading branch information
qmfrederik authored Jul 18, 2017
2 parents 6d75663 + 5c53d06 commit eb2c557
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 0 deletions.
12 changes: 12 additions & 0 deletions SharpAdbClient.Tests/AdbClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -469,6 +469,18 @@ public void ConnectHostEndpointNullTest()
AdbClient.Instance.Connect((string)null);
}

[TestMethod]
public void DisconnectTest()
{
var requests = new string[] { "host:disconnect:localhost:5555" };

this.RunTest(
OkResponse,
NoResponseMessages,
requests,
() => AdbClient.Instance.Disconnect(new DnsEndPoint("localhost", 5555)));
}

[TestMethod]
[DeploymentItem("logcat.bin")]
public void ReadLogTest()
Expand Down
5 changes: 5 additions & 0 deletions SharpAdbClient.Tests/DummyAdbClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -131,5 +131,10 @@ public void Unroot(DeviceData device)
{
throw new NotImplementedException();
}

public void Disconnect(DnsEndPoint endpoint)
{
throw new NotImplementedException();
}
}
}
14 changes: 14 additions & 0 deletions SharpAdbClient/AdbClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -519,6 +519,20 @@ protected void Root(string request, DeviceData device)
}
}

public void Disconnect(DnsEndPoint endpoint)
{
if (endpoint == null)
{
throw new ArgumentNullException(nameof(endpoint));
}

using (IAdbSocket socket = this.adbSocketFactory(this.EndPoint))
{
socket.SendAdbRequest($"host:disconnect:{endpoint.Host}:{endpoint.Port}");
var response = socket.ReadAdbResponse();
}
}

/// <summary>
/// Throws an <see cref="ArgumentNullException"/> if the <paramref name="device"/>
/// parameter is <see langword="null"/>, and a <see cref="ArgumentOutOfRangeException"/>
Expand Down
8 changes: 8 additions & 0 deletions SharpAdbClient/IAdbClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,14 @@ public interface IAdbClient
/// <include file='IAdbClient.xml' path='/IAdbClient/Connect/*'/>
void Connect(DnsEndPoint endpoint);

/// <summary>
/// Disconnects a remote device from this local ADB server.
/// </summary>
/// <param name="endpoint">
/// The endpoint of the remote device to disconnect.
/// </param>
void Disconnect(DnsEndPoint endpoint);

/// <include file='IAdbClient.xml' path='/IAdbClient/SetDevice/*'/>
void SetDevice(IAdbSocket socket, DeviceData device);

Expand Down
4 changes: 4 additions & 0 deletions appveyor.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
image: Visual Studio 2017

# Temporary workaround. See https://appveyor.statuspage.io/incidents/m2vdvw39kdk8
hosts:
api.nuget.org: 93.184.221.200

version: 2.2.{build}.0

environment:
Expand Down

0 comments on commit eb2c557

Please sign in to comment.