Skip to content

Conversation

@jonathanpeppers
Copy link
Member

Context: dotnet/sdk#51337
Context: dotnet/sdk#51914

In 63f7cba, we added the ComputeAvailableDevices MSBuild target, which I was able to test end-to-end:

D:\src\helloandroid> D:\src\dotnet\sdk\artifacts\bin\redist\Debug\dotnet\dotnet.exe run -bl
Select a device to run on:

> 0A041FDD400327 - Pixel 5
emulator-5554 - pixel 7 - api 36

Type to search

Unfortunately, the AVD name is returned from adb emu avd name, which simply returns the property:

> adb -s emulator-5554 shell getprop | grep avd_name
[ro.boot.qemu.avd_name]: [pixel_7_-_api_36]

We can call TextInfo.ToTitleCase(), replace underscores with spaces, and replace "Api" with "API" to make the AVD name more user-friendly.

The only other alternative I considered was parsing the ~/.android/avd/<name>.ini file to get the displayname property, but it would still require calling adb emu avd name to get the path to this .ini file. It felt more straightforward to just format the AVD name directly.

Context: dotnet/sdk#51337
Context: dotnet/sdk#51914

In 63f7cba, we added the `ComputeAvailableDevices` MSBuild target,
which I was able to test end-to-end:

    D:\src\helloandroid> D:\src\dotnet\sdk\artifacts\bin\redist\Debug\dotnet\dotnet.exe run -bl
    Select a device to run on:

    > 0A041FDD400327 - Pixel 5
    emulator-5554 - pixel 7 - api 36

    Type to search

Unfortunately, the AVD name is returned from `adb emu avd name`, which
simply returns the property:

    > adb -s emulator-5554 shell getprop | grep avd_name
    [ro.boot.qemu.avd_name]: [pixel_7_-_api_36]

We can call `TextInfo.ToTitleCase()`, replace underscores with spaces,
and replace "Api" with "API" to make the AVD name more user-friendly.

The only other alternative I considered was parsing the
`~/.android/avd/<name>.ini` file to get the `displayname` property,
but it would still require calling `adb emu avd name` to *get* the
path to this `.ini` file. It felt more straightforward to just format
the AVD name directly.
Copy link

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

This pull request enhances the user experience of the ComputeAvailableDevices MSBuild target by improving the display formatting of Android Virtual Device (AVD) names. The AVD names returned by adb emu avd name use underscores and lowercase formatting (e.g., "pixel_7_-_api_36"), which are not user-friendly. This change applies title case formatting, replaces underscores with spaces, and ensures "Api" is displayed as "API" for better readability in device selection prompts.

Key changes:

  • Added FormatDisplayName method to format AVD names with title case and proper spacing
  • Implemented regex-based replacement of "Api" with "API" using word boundaries to avoid incorrect replacements
  • Added comprehensive unit tests covering various formatting scenarios including edge cases

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
src/Xamarin.Android.Build.Tasks/Tasks/GetAvailableAndroidDevices.cs Added FormatDisplayName method to format AVD names; introduced ApiRegex for "Api" → "API" replacement; integrated System.Globalization for culture-invariant title casing
src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/Tasks/GetAvailableAndroidDevicesTests.cs Added 10 comprehensive unit tests for FormatDisplayName covering underscores, title case, API replacement, mixed case, complex names, special characters, empty strings, single words, and embedded "api" text

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants