Skip to content

Commit 09098c1

Browse files
committed
Harden emulator readiness gating before installs
1 parent 70e63b9 commit 09098c1

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

scripts/build-android-app.sh

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -940,30 +940,36 @@ adb_framework_ready_once() {
940940
local last_log=$SECONDS
941941

942942
while [ $SECONDS -lt $deadline ]; do
943-
local boot_ok system_pid pm_ok activity_ok service_ok service_status
943+
local boot_ok dev_boot system_pid pm_ok activity_ok service_ok user_ready service_status
944944
boot_ok="$($ADB_BIN -s "$serial" shell getprop sys.boot_completed 2>/dev/null | tr -d '\r')"
945+
dev_boot="$($ADB_BIN -s "$serial" shell getprop dev.bootcomplete 2>/dev/null | tr -d '\r')"
945946
system_pid="$(run_with_timeout "$per_try" "$ADB_BIN" -s "$serial" shell pidof system_server 2>/dev/null | tr -d '\r' || true)"
946947
pm_ok=0
947948
activity_ok=0
948949
service_ok=0
950+
user_ready=0
949951
if run_with_timeout "$per_try" "$ADB_BIN" -s "$serial" shell pm path android >/dev/null 2>&1; then
950952
pm_ok=1
951953
fi
952954
if run_with_timeout "$per_try" "$ADB_BIN" -s "$serial" shell cmd activity get-standby-bucket >/dev/null 2>&1; then
953955
activity_ok=1
954956
fi
957+
if run_with_timeout "$per_try" "$ADB_BIN" -s "$serial" shell am get-current-user >/dev/null 2>&1; then
958+
user_ready=1
959+
fi
955960
service_status="$(run_with_timeout "$per_try" "$ADB_BIN" -s "$serial" shell service check package 2>/dev/null | tr -d '\r' || true)"
956961
if [ -n "$service_status" ] && printf '%s' "$service_status" | grep -q "found"; then
957962
service_ok=1
958963
fi
959964

960-
if [ "$boot_ok" = "1" ] && [ -n "$system_pid" ] && [ $pm_ok -eq 1 ] && [ $activity_ok -eq 1 ] && [ $service_ok -eq 1 ]; then
965+
if [ "$boot_ok" = "1" ] && [ "$dev_boot" = "1" ] && [ -n "$system_pid" ] \
966+
&& [ $pm_ok -eq 1 ] && [ $activity_ok -eq 1 ] && [ $service_ok -eq 1 ] && [ $user_ready -eq 1 ]; then
961967
ba_log "Android framework ready on $serial (system_server=$system_pid)"
962968
return 0
963969
fi
964970

965971
if [ $((SECONDS - last_log)) -ge $log_interval ]; then
966-
ba_log "Waiting for Android framework on $serial (system_server=${system_pid:-down} boot_ok=${boot_ok:-?} pm_ready=$pm_ok activity_ready=$activity_ok package_service_ready=$service_ok)"
972+
ba_log "Waiting for Android framework on $serial (system_server=${system_pid:-down} boot_ok=${boot_ok:-?}/${dev_boot:-?} pm_ready=$pm_ok activity_ready=$activity_ok package_service_ready=$service_ok user_ready=$user_ready)"
967973
last_log=$SECONDS
968974
fi
969975
sleep 2
@@ -1229,10 +1235,15 @@ if ! wait_for_package_service "$EMULATOR_SERIAL"; then
12291235
exit 1
12301236
fi
12311237

1238+
"$ADB_BIN" -s "$EMULATOR_SERIAL" shell locksettings set-disabled true >/dev/null 2>&1 || true
12321239
"$ADB_BIN" -s "$EMULATOR_SERIAL" shell settings put global device_provisioned 1 >/dev/null 2>&1 || true
12331240
"$ADB_BIN" -s "$EMULATOR_SERIAL" shell settings put secure user_setup_complete 1 >/dev/null 2>&1 || true
12341241
"$ADB_BIN" -s "$EMULATOR_SERIAL" shell input keyevent 82 >/dev/null 2>&1 || true
12351242
"$ADB_BIN" -s "$EMULATOR_SERIAL" shell wm dismiss-keyguard >/dev/null 2>&1 || true
1243+
"$ADB_BIN" -s "$EMULATOR_SERIAL" shell settings put global window_animation_scale 0 >/dev/null 2>&1 || true
1244+
"$ADB_BIN" -s "$EMULATOR_SERIAL" shell settings put global transition_animation_scale 0 >/dev/null 2>&1 || true
1245+
"$ADB_BIN" -s "$EMULATOR_SERIAL" shell settings put global animator_duration_scale 0 >/dev/null 2>&1 || true
1246+
"$ADB_BIN" -s "$EMULATOR_SERIAL" shell am get-current-user >/dev/null 2>&1 || true
12361247

12371248
if ! wait_for_api_level "$EMULATOR_SERIAL"; then
12381249
dump_emulator_diagnostics
@@ -1242,6 +1253,7 @@ fi
12421253

12431254
"$ADB_BIN" -s "$EMULATOR_SERIAL" shell pm path android | sed 's/^/[build-android-app] pm path android: /' || true
12441255

1256+
"$ADB_BIN" start-server >/dev/null 2>&1 || true
12451257
"$ADB_BIN" kill-server >/dev/null 2>&1 || true
12461258
"$ADB_BIN" start-server >/dev/null 2>&1 || true
12471259
"$ADB_BIN" -s "$EMULATOR_SERIAL" wait-for-device

0 commit comments

Comments
 (0)