feat: add optional Windows virtual USB ADB device

This commit is contained in:
tongtong committed 2026-11-12 17:34:23 +08:00
1 parent 2abfb63da9
commit 08d60de364
23 files changed
+802 -26

No files matched your search

+8 -2
View File
@@ -23,7 +23,7 @@ internal static class Program
Exception? failure = null;
Dispatcher.UIThread.Post(async () =>
{
try { await RunAsync(args.Contains("--live"), args.Contains("--screen")); }
try { await RunAsync(args.Contains("--live"), args.Contains("--screen"), args.Contains("--usb")); }
catch (Exception error) { failure = error; }
finally { finished.Cancel(); }
});
@@ -47,7 +47,7 @@ internal static class Program
}
}
private static async Task RunAsync(bool live, bool screen)
private static async Task RunAsync(bool live, bool screen, bool usb)
{
var root = DesktopPaths.ProjectRoot() ?? throw new InvalidOperationException("Project root not found");
var folder = Path.Combine(root, "work", "desktop-smoke", Guid.NewGuid().ToString("N"));
@@ -55,6 +55,11 @@ internal static class Program
// Avoid collisions with the interactive application or another local ADB device.
var temporary = new System.Net.Sockets.TcpListener(System.Net.IPAddress.Loopback, 0);
temporary.Start(); vm.Port = ((System.Net.IPEndPoint)temporary.LocalEndpoint).Port; temporary.Stop();
vm.UsbMode = usb;
if (usb) {
var usbProbe = new System.Net.Sockets.TcpListener(System.Net.IPAddress.Loopback, 0);
usbProbe.Start(); vm.UsbPort = ((System.Net.IPEndPoint)usbProbe.LocalEndpoint).Port; usbProbe.Stop();
}
var window = new MainWindow { DataContext = vm };
window.Show();
await Task.Delay(60);
@@ -105,6 +110,7 @@ internal static class Program
await UntilAsync(() => vm.Ready && vm.Model != "—", "Device did not become ready: " + vm.Notice);
await UntilAsync(() => vm.TransportStatus.Contains("P2P") || vm.TransportStatus.Contains("中继连接"), "Transport status was not updated");
Require(window.FindControl<TextBlock>("TransportStatusText")?.Text == vm.TransportStatus, "Actual route binding failed");
if (usb) Require(vm.Endpoint?.StartsWith("ADS-") == true, "USB mode did not select the USB serial");
Console.WriteLine("PASS: two healthy nodes and actual transport shown: " + vm.TransportStatus);
Require(window.FindControl<TextBlock>("ModelText")?.Text == vm.Model, "Model UI binding failed");
Require(window.FindControl<Button>("ReconnectButton")?.IsEffectivelyEnabled == true, "Reconnect button not enabled");