Use shared EmulatorRunner from android-tools for BootAndroidEmulator#10949
Open
Use shared EmulatorRunner from android-tools for BootAndroidEmulator#10949
Conversation
Replace the 454-line BootAndroidEmulator implementation with a thin ~180-line wrapper that delegates to EmulatorRunner.BootEmulatorAsync() from Xamarin.Android.Tools.AndroidSdk. Key changes: - Remove all process management, polling, and boot detection logic - Delegate to EmulatorRunner.BootEmulatorAsync() for the full 3-phase boot: check online → check AVD running → launch + poll + wait - Map EmulatorBootResult errors to existing XA0143/XA0145 error codes - Virtual ExecuteBoot() method for clean test mocking - Update submodule to feature/emulator-runner (d8ee2d5) Tests updated from 9 to 10 (added ExtraArguments and UnknownError tests) using simplified mock pattern — MockBootAndroidEmulator overrides ExecuteBoot() to return canned EmulatorBootResult values. Depends on: dotnet/android-tools#284 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
Pull request overview
Replaces the BootAndroidEmulator MSBuild task's inline process management with a thin wrapper around EmulatorRunner.BootEmulatorAsync() from the shared xamarin-android-tools library.
Changes:
- Replaced ~270 lines of process/polling logic with delegation to
EmulatorRunner/AdbRunner - Simplified test mock to override a single
ExecuteBoot()method returning cannedEmulatorBootResult - Updated
external/xamarin-android-toolssubmodule to thefeature/emulator-runnerbranch
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
BootAndroidEmulator.cs |
Replaced inline boot logic with EmulatorRunner.BootEmulatorAsync() delegation |
BootAndroidEmulatorTests.cs |
Simplified mock and updated tests for new pattern |
external/xamarin-android-tools |
Submodule update to include EmulatorRunner API |
You can also share your feedback on Copilot code review. Take the survey.
Comment on lines
+120
to
+121
| } else if (errorMessage.Contains ("Timed out")) { | ||
| Log.LogCodedError ("XA0145", Properties.Resources.XA0145, Device, BootTimeoutSeconds); |
Comment on lines
+118
to
+120
| if (errorMessage.Contains ("Failed to launch")) { | ||
| Log.LogCodedError ("XA0143", Properties.Resources.XA0143, Device, errorMessage); | ||
| } else if (errorMessage.Contains ("Timed out")) { |
Comment on lines
+183
to
+185
| public void ExtraArguments_PassedToOptions () | ||
| { | ||
| string[]? capturedArgs = null; |
Comment on lines
+142
to
+143
| return emulatorRunner.BootEmulatorAsync (device, adbRunner, options) | ||
| .GetAwaiter ().GetResult (); |
Member
There was a problem hiding this comment.
This should be async/await. We can:
- Change base class to
AndroidAsyncTask - Override
RunTaskAsyncinstead - Everything in this file becomes async
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Replaces the 454-line
BootAndroidEmulatorMSBuild task with a ~180-line thin wrapper that delegates boot logic toEmulatorRunner.BootEmulatorAsync()fromXamarin.Android.Tools.AndroidSdk(shared via theexternal/xamarin-android-toolssubmodule).This is the consumer PR that @jonathanpeppers requested on android-tools#284:
What Changed
BootAndroidEmulator.cs(454 → ~180 lines)Removed:
Process.Start, async output capture,CancelOutputRead/CancelErrorRead)WaitForEmulatorOnline,WaitForFullBoot,Thread.Sleeploops)IsOnlineAdbDevice,FindRunningEmulatorForAvd,GetRunningAvdName,GetShellProperty,RunShellCommand)MonoAndroidHelper.RunProcesscalls (6 occurrences)Added:
ExecuteBoot()virtual method that createsAdbRunner+EmulatorRunnerand callsBootEmulatorAsync()ParseExtraArguments()to splitEmulatorExtraArgumentsstring →string[]EmulatorBootResult.ErrorMessage→ XA0143 (launch fail) / XA0145 (timeout/other)Preserved:
ResolveAdbPath()/ResolveEmulatorPath()logic unchangedthis.CreateTaskLogger()for MSBuild logging integrationBootAndroidEmulatorTests.cs(244 → ~250 lines, 9 → 10 tests)New mock pattern:
MockBootAndroidEmulatoroverridesExecuteBoot()to return a cannedEmulatorBootResult— much simpler than the previous approach of overriding 6 individual virtual methods.Tests:
AlreadyOnlineDevice_PassesThroughAlreadyOnlinePhysicalDevice_PassesThroughAvdAlreadyRunning_WaitsForFullBootBootEmulator_AppearsAfterPollingLaunchFailure_ReturnsErrorBootTimeout_ReturnsErrorMultipleEmulators_FindsCorrectAvdToolPaths_ResolvedFromAndroidSdkDirectoryExtraArguments_PassedToOptionsUnknownError_MapsToXA0145Submodule Update
external/xamarin-android-toolsupdated frommain(1a26c0c) →feature/emulator-runner(d8ee2d5)API Used
From
Xamarin.Android.Tools.AndroidSdk:Dependencies
external/xamarin-android-toolstomainHow dotnet/android Benefits
This establishes
EmulatorRunneras the shared emulator management API. The same API is also consumed by:mauicommand) — formaui android emulator bootHaving a single shared implementation means bug fixes and improvements benefit all consumers automatically.
cc @jonathanpeppers