Skip to content

Commit 46fdc13

Browse files
committed
Fix flaky android/run-emulator: wait for PackageManager before installing test APK
Summary: The pull / android / run-emulator job intermittently fails while installing the instrumentation test APK: adb: failed to install android-test-debug-androidTest.apk: java.lang.IllegalStateException: Cannot access system provider: 'settings' before system providers are installed! sys.boot_completed flips to 1 when ActivityManager is up, but system_server may still be registering the settings provider and PackageManager. On the CI software-emulated (swiftshader) x86_64 cold boot the window is wide enough that the install races the framework and aborts the script. Because run-emulator is a required check on pull, each flake reds an otherwise-good commit and starves the viable/strict sampled set. Gate the install on PackageManager actually answering (cmd package list packages) instead of only sys.boot_completed, and retry the install a few times to absorb transient adb drops on cold boot. Test Plan: bash -n scripts/run_android_emulator.sh passes. Behavior validated in CI via the android/run-emulator job. Reviewers: Co-authored-with Claude Code (Opus 4.8).
1 parent 4019e4c commit 46fdc13

1 file changed

Lines changed: 23 additions & 1 deletion

File tree

‎scripts/run_android_emulator.sh‎

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,13 @@ echo "Waiting for emulator boot to complete"
3030
$ADB_PATH wait-for-device shell 'while [[ -z $(getprop sys.boot_completed) ]]; do sleep 5; done;'
3131
$ADB_PATH wait-for-device
3232

33+
# sys.boot_completed flips before system_server finishes registering the
34+
# settings provider and PackageManager. Installing before then fails with
35+
# "Cannot access system provider: 'settings' before system providers are
36+
# installed!". Wait until PackageManager actually answers.
37+
echo "Waiting for package manager to become available"
38+
adb_shell_with_retries 60 cmd package list packages >/dev/null
39+
3340
echo "Unlock emulator and disable animations"
3441
adb_shell_with_retries 5 input keyevent 82 || true
3542
adb_shell_with_retries 5 settings put global window_animation_scale 0.0 || true
@@ -41,7 +48,22 @@ echo "List all running emulators"
4148
$ADB_PATH devices
4249

4350
"$ADB_PATH" uninstall org.pytorch.executorch.test || true
44-
"$ADB_PATH" install -t android-test-debug-androidTest.apk
51+
52+
# Retry the install: even after PackageManager answers, a cold software
53+
# boot can transiently drop adb or the framework can still be settling.
54+
install_ok=false
55+
for ((i = 1; i <= 5; i++)); do
56+
if "$ADB_PATH" install -r -t android-test-debug-androidTest.apk; then
57+
install_ok=true
58+
break
59+
fi
60+
sleep 10
61+
"$ADB_PATH" wait-for-device
62+
done
63+
if [ "$install_ok" != "true" ]; then
64+
echo "Failed to install test APK after retries" >&2
65+
exit 1
66+
fi
4567

4668
"$ADB_PATH" logcat -c
4769
"$ADB_PATH" shell am instrument -w -r \

0 commit comments

Comments
 (0)