Summary
Add support for real-time device connection/disconnection monitoring via the ADB daemon socket protocol (host:track-devices-l), similar to what the AndroidSdk.Adbd NuGet package provides.
Motivation
The existing AdbRunner.GetDevicesAsync() does a one-shot adb devices -l call. For IDE extensions and developer tools that need to react immediately when devices connect/disconnect (USB plug, emulator boot, WiFi pairing), polling is suboptimal.
The ADB daemon exposes a host:track-devices-l socket command that pushes device list updates in real-time. This is a well-known protocol used by Android Studio and other tooling.
Currently, consumers like MAUI Sherpa depend on the separate AndroidSdk.Adbd NuGet (from redth/android-tools) for this functionality. Consolidating it into Xamarin.Android.Tools.AndroidSdk would reduce the dependency surface.
Proposed API
`csharp
public class AdbDeviceTracker : IDisposable
{
public AdbDeviceTracker(string? sdkPath = null, int port = 5037);
/// Starts tracking. Calls onDevicesChanged whenever the device list changes.
public Task StartAsync(
Action<IReadOnlyList<AdbDeviceInfo>> onDevicesChanged,
CancellationToken cancellationToken = default);
/// Current snapshot of tracked devices.
public IReadOnlyList<AdbDeviceInfo> CurrentDevices { get; }
public void Dispose();
}
`
Implementation Notes
- Connect to
localhost:5037 (ADB daemon)
- Send
host:track-devices-l command
- Parse length-prefixed device list updates as they arrive
- Auto-reconnect on connection drops with backoff
- Reuse existing
AdbDeviceInfo model
Related
- The
AndroidSdk.Adbd NuGet (redth/android-tools) has a working implementation via AdbdClient
- The
maui-labs CLI does not currently have this feature either
Summary
Add support for real-time device connection/disconnection monitoring via the ADB daemon socket protocol (
host:track-devices-l), similar to what theAndroidSdk.AdbdNuGet package provides.Motivation
The existing
AdbRunner.GetDevicesAsync()does a one-shotadb devices -lcall. For IDE extensions and developer tools that need to react immediately when devices connect/disconnect (USB plug, emulator boot, WiFi pairing), polling is suboptimal.The ADB daemon exposes a
host:track-devices-lsocket command that pushes device list updates in real-time. This is a well-known protocol used by Android Studio and other tooling.Currently, consumers like MAUI Sherpa depend on the separate
AndroidSdk.AdbdNuGet (fromredth/android-tools) for this functionality. Consolidating it intoXamarin.Android.Tools.AndroidSdkwould reduce the dependency surface.Proposed API
`csharp
public class AdbDeviceTracker : IDisposable
{
public AdbDeviceTracker(string? sdkPath = null, int port = 5037);
}
`
Implementation Notes
localhost:5037(ADB daemon)host:track-devices-lcommandAdbDeviceInfomodelRelated
AndroidSdk.AdbdNuGet (redth/android-tools) has a working implementation viaAdbdClientmaui-labsCLI does not currently have this feature either