Skip to content

Commit 70e63b9

Browse files
committed
Harden framework readiness check before APK installs
1 parent e900a0d commit 70e63b9

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

scripts/build-android-app.sh

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -940,25 +940,30 @@ 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
943+
local boot_ok system_pid pm_ok activity_ok service_ok service_status
944944
boot_ok="$($ADB_BIN -s "$serial" shell getprop sys.boot_completed 2>/dev/null | tr -d '\r')"
945945
system_pid="$(run_with_timeout "$per_try" "$ADB_BIN" -s "$serial" shell pidof system_server 2>/dev/null | tr -d '\r' || true)"
946946
pm_ok=0
947947
activity_ok=0
948+
service_ok=0
948949
if run_with_timeout "$per_try" "$ADB_BIN" -s "$serial" shell pm path android >/dev/null 2>&1; then
949950
pm_ok=1
950951
fi
951952
if run_with_timeout "$per_try" "$ADB_BIN" -s "$serial" shell cmd activity get-standby-bucket >/dev/null 2>&1; then
952953
activity_ok=1
953954
fi
955+
service_status="$(run_with_timeout "$per_try" "$ADB_BIN" -s "$serial" shell service check package 2>/dev/null | tr -d '\r' || true)"
956+
if [ -n "$service_status" ] && printf '%s' "$service_status" | grep -q "found"; then
957+
service_ok=1
958+
fi
954959

955-
if [ "$boot_ok" = "1" ] && [ -n "$system_pid" ] && [ $pm_ok -eq 1 ] && [ $activity_ok -eq 1 ]; then
960+
if [ "$boot_ok" = "1" ] && [ -n "$system_pid" ] && [ $pm_ok -eq 1 ] && [ $activity_ok -eq 1 ] && [ $service_ok -eq 1 ]; then
956961
ba_log "Android framework ready on $serial (system_server=$system_pid)"
957962
return 0
958963
fi
959964

960965
if [ $((SECONDS - last_log)) -ge $log_interval ]; then
961-
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)"
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)"
962967
last_log=$SECONDS
963968
fi
964969
sleep 2

0 commit comments

Comments
 (0)