Use shared EmulatorRunner from android-tools for BootAndroidEmulator#10948
Closed
Use shared EmulatorRunner from android-tools for BootAndroidEmulator#10948
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>
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