Fix emulator readiness check for package manager service#10846
Merged
jonathanpeppers merged 5 commits intomainfrom Feb 20, 2026
Merged
Fix emulator readiness check for package manager service#10846jonathanpeppers merged 5 commits intomainfrom
jonathanpeppers merged 5 commits intomainfrom
Conversation
Copilot stopped work on behalf of
sbomer due to an error
February 19, 2026 23:23
Copilot stopped work on behalf of
sbomer due to an error
February 19, 2026 23:38
sys.boot_completed fires before the Android Package Manager is fully initialized. When CheckAdbTarget runs 'pm path com.android.shell' during this window, it returns a non-zero exit code, causing AcquireAndroidTarget to launch a second emulator on the same port. Two QEMU processes on the same port destabilizes adb — am instrument produces zero output and subsequent PM queries fail with 'Can't find service: package', ultimately causing NUnit2 result file not found errors. Add a Phase 2 poll to WaitForAndroidEmulator that verifies PM readiness via 'adb shell pm path com.android.shell' after sys.boot_completed=1, using ShouldRun lambdas to alternate between the boot check and PM check commands. Fixes #10847
Derive command selection and output parsing from bootCompleted directly, eliminating currentState, BeforeCommand, waitingForPM, and the StateCheck constants. Return false directly after LogError instead of the redundant !Log.HasLoggedErrors idiom.
There was a problem hiding this comment.
Pull request overview
This PR fixes a race condition in emulator initialization where sys.boot_completed can fire before the Package Manager service is fully ready, causing subsequent CheckAdbTarget checks to fail and potentially triggering a second emulator launch on the same port.
Changes:
- Adds a two-phase emulator readiness check: first waiting for boot completion, then waiting for Package Manager availability
- Introduces Package Manager readiness verification using
adb shell pm path com.android.shell - Enhances logging to indicate progress through both initialization phases
....Android.Tools.BootstrapTasks/Xamarin.Android.Tools.BootstrapTasks/WaitForAndroidEmulator.cs
Show resolved
Hide resolved
....Android.Tools.BootstrapTasks/Xamarin.Android.Tools.BootstrapTasks/WaitForAndroidEmulator.cs
Outdated
Show resolved
Hide resolved
…id.Tools.BootstrapTasks/WaitForAndroidEmulator.cs Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Copilot stopped work on behalf of
sbomer due to an error
February 20, 2026 19:02
jonathanpeppers
approved these changes
Feb 20, 2026
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.
@jonathanpeppers I think this fixes #10847. In any case it fixes a race where CheckAdbTarget might run after the emulator is booted but before the package manager service is initialized.
Thanks for asking me to work on this. I will get started on it and keep this PR's description up to date as I form a plan and make progress.
🔒 GitHub Advanced Security automatically protects Copilot coding agent pull requests. You can protect all pull requests by enabling Advanced Security for your repositories. Learn more about Advanced Security.