Skip to content

Fix emulator readiness check for package manager service#10846

Merged
jonathanpeppers merged 5 commits intomainfrom
copilot/fix-emulator-package-manager-logic
Feb 20, 2026
Merged

Fix emulator readiness check for package manager service#10846
jonathanpeppers merged 5 commits intomainfrom
copilot/fix-emulator-package-manager-logic

Conversation

Copy link
Contributor

Copilot AI commented Feb 19, 2026

@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.

It seems some ci failures are caused by the emulator package manager service not being ready when CheckAdbTarget runs, resulting in an attempt to start a second emulator using the same port. Fix up the logic that waits for the emulator to be available to also wait until the package manager service is available.


🔒 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.

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.
@sbomer sbomer changed the title [WIP] Fix emulator readiness check for package manager service Fix emulator readiness check for package manager service Feb 20, 2026
@sbomer sbomer marked this pull request as ready for review February 20, 2026 18:20
Copilot AI review requested due to automatic review settings February 20, 2026 18:20
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 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

…id.Tools.BootstrapTasks/WaitForAndroidEmulator.cs

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@jonathanpeppers jonathanpeppers merged commit f6c937a into main Feb 20, 2026
5 of 6 checks passed
@jonathanpeppers jonathanpeppers deleted the copilot/fix-emulator-package-manager-logic branch February 20, 2026 23:14
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.

Intermittent "Could not find NUnit2 results file" test failures

4 participants