Skip to content

Add ADB device tracking (host:track-devices) for real-time device monitoring #323

@rmarinho

Description

@rmarinho

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions