-
Notifications
You must be signed in to change notification settings - Fork 564
[xabt] title case ComputeAvailableDevices
#10623
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
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.
There was a problem hiding this 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
FormatDisplayNamemethod 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 |
src/Xamarin.Android.Build.Tasks/Tasks/GetAvailableAndroidDevices.cs
Outdated
Show resolved
Hide resolved
src/Xamarin.Android.Build.Tasks/Tasks/GetAvailableAndroidDevices.cs
Outdated
Show resolved
Hide resolved
src/Xamarin.Android.Build.Tasks/Tasks/GetAvailableAndroidDevices.cs
Outdated
Show resolved
Hide resolved
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Context: dotnet/sdk#51337
Context: dotnet/sdk#51914
In 63f7cba, we added the
ComputeAvailableDevicesMSBuild target, which I was able to test end-to-end:Unfortunately, the AVD name is returned from
adb emu avd name, which simply returns the property: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>.inifile to get thedisplaynameproperty, but it would still require callingadb emu avd nameto get the path to this.inifile. It felt more straightforward to just format the AVD name directly.