Skip to content

GetEmulatorAvdNameAsync should fallback to getprop when adb emu avd name returns empty #310

@rmarinho

Description

@rmarinho

Problem

AdbRunner.GetEmulatorAvdNameAsync() uses adb -s <serial> emu avd name to resolve the AVD name of a running emulator. On ADB v36.0.0, this command returns empty output (exit code 0) — causing MergeDevicesAndEmulators() to fail deduplication, resulting in duplicate device entries (one running without AVD name + one "Not Running" from emulator -list-avds).

Root Cause

adb emu avd name returns empty on adb v36.0.0:

$ adb -s emulator-5554 emu avd name
(empty output, exit code 0)

But the correct name is available via shell property:

$ adb -s emulator-5554 shell getprop ro.boot.qemu.avd_name
MAUI_Emulator_API_36

Proposed Fix

In GetEmulatorAvdNameAsync(), add a fallback:

  1. Try adb emu avd name (existing behavior)
  2. If result is null/empty, try adb shell getprop ro.boot.qemu.avd_name
  3. Return the first non-empty result

Impact

This is a pre-existing bug on main — confirmed by testing dotnet run on dotnet/android main branch with an emulator running: same duplicate listing occurs. Not caused by the EmulatorRunner feature branch.

The same fix is also needed in dotnet/android's GetAvailableAndroidDevices.GetEmulatorAvdName() which has identical logic.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions