Skip to content

Add AdbRunner for adb CLI operations#283

Open
rmarinho wants to merge 7 commits intomainfrom
feature/adb-runner
Open

Add AdbRunner for adb CLI operations#283
rmarinho wants to merge 7 commits intomainfrom
feature/adb-runner

Conversation

@rmarinho
Copy link
Member

@rmarinho rmarinho commented Feb 23, 2026

Summary

Wraps adb CLI operations for device management. Addresses #279.

Changes

New: ConfigureEnvironment

Sets ANDROID_HOME on all child process ProcessStartInfo.

New: WaitForDeviceAsync

public async Task WaitForDeviceAsync (string? serial = null, TimeSpan? timeout = null, CancellationToken ct = default)
  • Optional serial filter (waits for any device when null)
  • Configurable timeout (default 60s), throws TimeoutException
  • Uses CancellationTokenSource.CreateLinkedTokenSource for clean timeout handling

Updated: ListDevicesAsync / StopEmulatorAsync

Now call ConfigureEnvironment(psi) to set ANDROID_HOME.

API

public class AdbRunner
{
    public AdbRunner (Func<string?> getSdkPath);
    public string? AdbPath { get; }
    public bool IsAvailable { get; }
    
    Task<List<AdbDeviceInfo>> ListDevicesAsync (CancellationToken ct = default);
    Task WaitForDeviceAsync (string? serial = null, TimeSpan? timeout = null, CancellationToken ct = default);
    Task StopEmulatorAsync (string serial, CancellationToken ct = default);
}

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds new “runner” infrastructure and an AdbRunner wrapper intended to simplify invoking Android SDK command-line tools (notably adb) from Xamarin.Android.Tools.AndroidSdk.

Changes:

  • Introduces AndroidToolRunner + ToolRunnerResult models for executing tools with captured output, timeouts, and cancellation.
  • Adds AndroidEnvironmentHelper utilities for env var setup and some Android mapping helpers.
  • Adds AdbRunner for listing devices, waiting for boot completion, emulator control, and property enrichment.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 10 comments.

Show a summary per file
File Description
src/Xamarin.Android.Tools.AndroidSdk/Runners/AndroidToolRunner.cs New process execution helper (sync/async/timeout/background).
src/Xamarin.Android.Tools.AndroidSdk/Runners/AndroidEnvironmentHelper.cs New helper for tool env vars and mapping helpers.
src/Xamarin.Android.Tools.AndroidSdk/Runners/AdbRunner.cs New adb wrapper for device/emulator operations and parsing.
src/Xamarin.Android.Tools.AndroidSdk/Models/ToolRunnerResult.cs New execution result model (+ generic variant).
src/Xamarin.Android.Tools.AndroidSdk/Models/AndroidDeviceInfo.cs New device model + enums used by AdbRunner.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@rmarinho rmarinho added the copilot `copilot-cli` or other AIs were used to author this label Feb 23, 2026
@jonathanpeppers
Copy link
Member

I'd like to get the System.Diagnostics.Process code unified like mentioned here:

rmarinho added a commit that referenced this pull request Feb 24, 2026
Addresses PR #283 feedback to use existing ProcessUtils instead of
the removed AndroidToolRunner. Simplifies API:

- Methods now throw InvalidOperationException on failure
- Uses ProcessUtils.RunToolAsync() for all tool invocations
- Added AndroidDeviceInfo model
- Removed complex ToolRunnerResult wrapper types

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
rmarinho added a commit that referenced this pull request Feb 24, 2026
Addresses PR #283/#284 feedback to use existing ProcessUtils.
Simplifies API by throwing exceptions on failure instead of
returning result types with error states.

Changes:
- AdbRunner: Simplified using ProcessUtils.RunToolAsync()
- EmulatorRunner: Uses ProcessUtils.StartToolBackground()
- Removed duplicate AndroidDeviceInfo from Models directory

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@rmarinho rmarinho force-pushed the feature/adb-runner branch 2 times, most recently from 124c3c9 to f0ebb8d Compare February 24, 2026 19:09
rmarinho and others added 6 commits February 26, 2026 17:31
- ListDevicesAsync(): List connected devices
- StopEmulatorAsync(): Stop a running emulator

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
- Add XML documentation to all public members
- Split AdbDeviceInfo into its own file (one type per file)
- Use 'is not null' instead of '!= null'
- Improve code formatting

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
- ConfigureEnvironment() sets ANDROID_HOME on all ProcessStartInfo
- Add WaitForDeviceAsync with optional serial filter, timeout, and TimeoutException
- Uses CancellationTokenSource.CreateLinkedTokenSource for timeout handling

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…ation, reduce duplication

- Extract RequireAdb() to centralize availability check
- Extract CreateAdbProcess() to eliminate PSI creation duplication
- Add whitespace validation on serial parameter in StopEmulatorAsync
- Use params string[] args pattern for cleaner argument passing
- Remove redundant XML doc comments

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

copilot `copilot-cli` or other AIs were used to author this

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants