Skip to content

Commit 9af50e7

Browse files
authored
Merge branch 'main' into main
2 parents d233bf4 + 6ece9be commit 9af50e7

File tree

108 files changed

+406
-7804
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

108 files changed

+406
-7804
lines changed

.github/ISSUE_TEMPLATE/bug_report.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ body:
3232
description: Specify the version of AdvancedSharpAdbClient you're using.
3333
options:
3434
- "Latest Source"
35+
- "2.5.5"
3536
- "2.5.4"
3637
- "2.5.3"
3738
- "2.5.2"

.github/workflows/build-and-test.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@ jobs:
2222
dotnet-version: ${{env.DOTNET_VERSION}}
2323

2424
- name: Install dependencies
25-
run: dotnet restore
25+
run: dotnet restore -p:FullTargets=false
2626

2727
- name: Build
28-
run: dotnet build --no-restore
28+
run: dotnet build --no-restore -p:FullTargets=false
2929

3030
- name: Test
31-
run: dotnet test --no-restore
31+
run: dotnet test --no-restore -p:FullTargets=false

AdvancedSharpAdbClient.Tests/AdvancedSharpAdbClient.Tests.csproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4+
<NoWarn>CS1591</NoWarn>
45
<LangVersion>latest</LangVersion>
56
<NoWarn>CS1591</NoWarn>
67
<TargetFramework>net6.0</TargetFramework>
78
</PropertyGroup>
89

910
<ItemGroup>
11+
<PackageReference Include="coverlet.msbuild" Version="3.2.0" PrivateAssets="all">
12+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
13+
</PackageReference>
1014
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.4.1" />
1115
<PackageReference Include="Moq" Version="4.18.4" />
1216
<PackageReference Include="xunit" Version="2.4.2" />

AdvancedSharpAdbClient.Tests/DeviceMonitorTests.cs

Lines changed: 55 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ public void StartInitialDeviceListTest()
157157
}
158158

159159
[Fact]
160-
public void DeviceChangedTest()
160+
public void DeviceChanged_TriggeredWhenStatusChanged()
161161
{
162162
Socket.WaitForNewData = true;
163163

@@ -186,6 +186,8 @@ public void DeviceChangedTest()
186186
Socket.Responses.Clear();
187187
Socket.Requests.Clear();
188188

189+
sink.ResetSignals();
190+
189191
// Device disconnects
190192
ManualResetEvent eventWaiter = sink.CreateEventSignal();
191193

@@ -199,13 +201,64 @@ public void DeviceChangedTest()
199201

200202
Assert.Equal(1, monitor.Devices.Count);
201203
Assert.Equal(DeviceState.Online, monitor.Devices.ElementAt(0).State);
202-
Assert.Single(sink.ConnectedEvents);
204+
Assert.Empty(sink.ConnectedEvents);
203205
Assert.Single(sink.ChangedEvents);
204206
Assert.Empty(sink.DisconnectedEvents);
205207
Assert.Equal("169.254.109.177:5555", sink.ChangedEvents[0].Device.Serial);
206208
});
207209
}
208210

211+
[Fact]
212+
public void DeviceChanged_NoTriggerIfStatusIsSame()
213+
{
214+
Socket.WaitForNewData = true;
215+
216+
using DeviceMonitor monitor = new(Socket);
217+
DeviceMonitorSink sink = new(monitor);
218+
219+
Assert.Equal(0, monitor.Devices.Count);
220+
221+
// Start the monitor, detect the initial device.
222+
RunTest(
223+
OkResponse,
224+
ResponseMessages("169.254.109.177:5555\toffline\n"),
225+
Requests("host:track-devices"),
226+
() =>
227+
{
228+
monitor.Start();
229+
230+
Assert.Equal(1, monitor.Devices.Count);
231+
Assert.Equal(DeviceState.Offline, monitor.Devices.ElementAt(0).State);
232+
Assert.Single(sink.ConnectedEvents);
233+
Assert.Empty(sink.ChangedEvents);
234+
Assert.Empty(sink.DisconnectedEvents);
235+
});
236+
237+
Socket.ResponseMessages.Clear();
238+
Socket.Responses.Clear();
239+
Socket.Requests.Clear();
240+
241+
sink.ResetSignals();
242+
243+
// Something happens but device does not change
244+
ManualResetEvent eventWaiter = sink.CreateEventSignal();
245+
246+
RunTest(
247+
NoResponses,
248+
ResponseMessages("169.254.109.177:5555\toffline\n"),
249+
Requests(),
250+
() =>
251+
{
252+
eventWaiter.WaitOne(1000);
253+
254+
Assert.Equal(1, monitor.Devices.Count);
255+
Assert.Equal(DeviceState.Offline, monitor.Devices.ElementAt(0).State);
256+
Assert.Empty(sink.ConnectedEvents);
257+
Assert.Empty(sink.ChangedEvents);
258+
Assert.Empty(sink.DisconnectedEvents);
259+
});
260+
}
261+
209262
/// <summary>
210263
/// Tests the <see cref="DeviceMonitor"/> in a case where the adb server dies in the middle of the monitor
211264
/// loop. The <see cref="DeviceMonitor"/> should detect this condition and restart the adb server.

AdvancedSharpAdbClient.Tests/Dummys/DeviceMonitorSink.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,13 @@ public DeviceMonitorSink(DeviceMonitor monitor)
1818
ConnectedEvents = new Collection<DeviceDataEventArgs>();
1919
}
2020

21+
public void ResetSignals()
22+
{
23+
ChangedEvents.Clear();
24+
DisconnectedEvents.Clear();
25+
ConnectedEvents.Clear();
26+
}
27+
2128
public Collection<DeviceDataEventArgs> DisconnectedEvents { get; private set; }
2229

2330
public Collection<DeviceDataEventArgs> ConnectedEvents { get; private set; }

AdvancedSharpAdbClient.Tests/Dummys/DummyAdbClient.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
using System;
33
using System.Collections.Generic;
44
using System.Collections.ObjectModel;
5-
using System.Drawing;
65
using System.IO;
76
using System.Net;
87
using System.Text;
@@ -144,7 +143,7 @@ public Task ExecuteRemoteCommandAsync(string command, DeviceData device, IShellO
144143

145144
public Task<List<string>> GetFeatureSetAsync(DeviceData device, CancellationToken cancellationToken) => throw new NotImplementedException();
146145

147-
public Task<Image> GetFrameBufferAsync(DeviceData device, CancellationToken cancellationToken) => throw new NotImplementedException();
146+
public Task<Framebuffer> GetFrameBufferAsync(DeviceData device, CancellationToken cancellationToken) => throw new NotImplementedException();
148147

149148
public void HomeBtn(DeviceData device) => throw new NotImplementedException();
150149

AdvancedSharpAdbClient/AdbClient.Async.cs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
using System;
88
using System.Collections.Generic;
99
using System.Diagnostics;
10-
using System.Drawing;
1110
using System.Globalization;
1211
using System.IO;
1312
using System.Linq;
@@ -229,18 +228,15 @@ public async Task ExecuteRemoteCommandAsync(string command, DeviceData device, I
229228
}
230229

231230
/// <inheritdoc/>
232-
#if NET
233-
[SupportedOSPlatform("windows")]
234-
#endif
235-
public async Task<Image> GetFrameBufferAsync(DeviceData device, CancellationToken cancellationToken = default)
231+
public async Task<Framebuffer> GetFrameBufferAsync(DeviceData device, CancellationToken cancellationToken = default)
236232
{
237233
EnsureDevice(device);
238234

239235
using Framebuffer framebuffer = CreateRefreshableFramebuffer(device);
240236
await framebuffer.RefreshAsync(cancellationToken).ConfigureAwait(false);
241237

242238
// Convert the framebuffer to an image, and return that.
243-
return framebuffer.ToImage();
239+
return framebuffer;
244240
}
245241

246242
/// <inheritdoc/>

AdvancedSharpAdbClient/AdvancedSharpAdbClient.csproj

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,14 @@
1717

1818
<ItemGroup Condition="'$(TargetFramework)' == 'net3.5-client'">
1919
<PackageReference Include="AsyncBridge" Version="0.3.1" />
20-
<PackageReference Include="Polyfill.System.Buffers.NET35" Version="0.0.4" />
21-
<PackageReference Include="Polyfill.System.Runtime.InteropServices.RuntimeInformation.NET35" Version="0.0.4" />
20+
<PackageReference Include="Polyfill.System.Buffers.NET35" Version="0.0.5" />
21+
<PackageReference Include="Polyfill.System.Runtime.InteropServices.RuntimeInformation.NET35" Version="0.0.5" />
2222
</ItemGroup>
2323

2424
<ItemGroup Condition="'$(TargetFramework)' == 'net4.0-client'">
2525
<PackageReference Include="Microsoft.Bcl.Async" Version="1.0.168" />
26-
<PackageReference Include="Polyfill.System.Buffers.NET40" Version="0.0.3" />
27-
<PackageReference Include="Polyfill.System.Runtime.InteropServices.RuntimeInformation.NET40" Version="0.0.3" />
26+
<PackageReference Include="Polyfill.System.Buffers.NET40" Version="0.0.4" />
27+
<PackageReference Include="Polyfill.System.Runtime.InteropServices.RuntimeInformation.NET40" Version="0.0.4" />
2828
</ItemGroup>
2929

3030
<ItemGroup Condition="'$(TargetFramework)' == 'net4.5.2'">
@@ -38,9 +38,7 @@
3838
<ItemGroup Condition="'$(TargetFramework)' == 'netcore50'
3939
or '$(TargetFramework)' == 'netstandard1.3'">
4040
<PackageReference Include="System.Buffers" Version="4.5.1" />
41-
<PackageReference Include="System.Drawing-dotnet-core" Version="1.2.3" />
4241
<PackageReference Include="System.Net.Sockets" Version="4.3.0" />
43-
<PackageReference Include="System.Runtime.Serialization.Formatters" Version="4.3.0" />
4442
<PackageReference Include="System.Xml.XPath.XmlDocument" Version="4.3.0" />
4543
</ItemGroup>
4644

@@ -80,7 +78,7 @@
8078

8179
<PropertyGroup Condition="'$(TargetFramework)' != 'netcore50'
8280
and '$(TargetFramework)' != 'netstandard1.3'">
83-
<DefineConstants>$(DefineConstants);HAS_Process</DefineConstants>
81+
<DefineConstants>$(DefineConstants);HAS_Process;HAS_Drawing;HAS_Serialization</DefineConstants>
8482
</PropertyGroup>
8583

8684
</Project>

AdvancedSharpAdbClient/DeviceMonitor.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,7 @@ private void UpdateDevices(List<DeviceData> devices)
324324
this.devices.Add(device);
325325
OnDeviceConnected(new DeviceDataEventArgs(device));
326326
}
327-
else
327+
else if (existingDevice.State != device.State)
328328
{
329329
existingDevice.State = device.State;
330330
OnDeviceChanged(new DeviceDataEventArgs(existingDevice));

AdvancedSharpAdbClient/Exceptions/AdbException.cs

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@
44

55
using System;
66
using System.Net.Sockets;
7+
8+
#if HAS_Serialization
79
using System.Runtime.Serialization;
10+
#endif
811

912
namespace AdvancedSharpAdbClient.Exceptions
1013
{
@@ -46,24 +49,16 @@ public AdbException(string message, AdbResponse response) : base(message)
4649
Response = response;
4750
}
4851

52+
#if HAS_Serialization
4953
/// <summary>
5054
/// Initializes a new instance of the <see cref="AdbException"/> class.
5155
/// </summary>
5256
/// <param name="serializationInfo">The serialization info.</param>
5357
/// <param name="context">The context.</param>
54-
public AdbException(SerializationInfo serializationInfo, StreamingContext context) :
55-
#if HAS_Process
56-
base(serializationInfo, context)
57-
#else
58-
base(serializationInfo.GetString("Message"))
59-
#endif
58+
public AdbException(SerializationInfo serializationInfo, StreamingContext context) : base(serializationInfo, context)
6059
{
61-
#if !HAS_Process
62-
HelpLink = serializationInfo.GetString("HelpURL"); // Do not rename (binary serialization)
63-
HResult = serializationInfo.GetInt32("HResult"); // Do not rename (binary serialization)
64-
Source = serializationInfo.GetString("Source"); // Do not rename (binary serialization)
65-
#endif
6660
}
61+
#endif
6762

6863
/// <summary>
6964
/// Initializes a new instance of the <see cref="AdbException"/> class.

0 commit comments

Comments
 (0)