make android-emulator's boot wait can be satisfied by an unrelated attached device #162

Open
opened 2026-08-20 18:17:21 +00:00 by logan · 0 comments
Collaborator

scripts/android-emulator.sh start waits for a device to finish
booting, not for the emulator it just launched.

Found while booting the emulator to verify #159, with a phone attached
at the same time.

$ make android-emulator
emulator starting (pid 706390), log: .dev/emulator.log
waiting for boot ok
  android 14
$ adb devices
List of devices attached
LP3LHMA531900746	device        <- the phone; no emulator yet

The emulator appeared in adb devices about ten seconds after the
command returned claiming boot was complete.

Why. The wait calls pick_device, whose last resort is "no AVD of
ours, but exactly one device online — a physical phone, which is the
one target this tier actually wants". At the moment start polls, the
emulator has not registered with adb, so the single online device is
the phone. pick_device returns it, getprop sys.boot_completed
answers 1 (it booted days ago), and start reports success.

That fallback is right for install, launch, logs and smoke
it is what makes those work against a phone — and wrong only here,
because start knows it is waiting for an emulator specifically.

Impact is low. Nothing was harmed in #159's verification: the
emulator was up well before the deploy ran. The failure mode is a
make android-emulator && make android-install sequence racing, where
the install goes to whatever is online — which, with the fix from
#159, at least refuses rather than silently choosing (--target emulator). Without a phone attached it cannot happen at all, since
pick_device returns non-zero with nothing online.

Suggested fix. start should poll for a serial matching
^emulator- (or for the AVD name specifically, which pick_device
already prefers) rather than delegating to pick_device's general
resolution, and should time out saying which AVD it was waiting for.

**`scripts/android-emulator.sh start` waits for *a* device to finish booting, not for the emulator it just launched.** Found while booting the emulator to verify #159, with a phone attached at the same time. ``` $ make android-emulator emulator starting (pid 706390), log: .dev/emulator.log waiting for boot ok android 14 $ adb devices List of devices attached LP3LHMA531900746 device <- the phone; no emulator yet ``` The emulator appeared in `adb devices` about ten seconds *after* the command returned claiming boot was complete. **Why.** The wait calls `pick_device`, whose last resort is "no AVD of ours, but exactly one device online — a physical phone, which is the one target this tier actually wants". At the moment `start` polls, the emulator has not registered with adb, so the single online device is the phone. `pick_device` returns it, `getprop sys.boot_completed` answers 1 (it booted days ago), and `start` reports success. That fallback is right for `install`, `launch`, `logs` and `smoke` — it is what makes those work against a phone — and wrong only here, because `start` knows it is waiting for an emulator specifically. **Impact is low.** Nothing was harmed in #159's verification: the emulator was up well before the deploy ran. The failure mode is a `make android-emulator && make android-install` sequence racing, where the install goes to whatever is online — which, with the fix from #159, at least refuses rather than silently choosing (`--target emulator`). Without a phone attached it cannot happen at all, since `pick_device` returns non-zero with nothing online. **Suggested fix.** `start` should poll for a serial matching `^emulator-` (or for the AVD name specifically, which `pick_device` already prefers) rather than delegating to `pick_device`'s general resolution, and should time out saying which AVD it was waiting for.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: yonlu/yellowjacket#162