Skip to content

Commit cd24441

Browse files
committed
Harden emulator readiness for x86_64 UI tests
1 parent 9a4b7fb commit cd24441

File tree

1 file changed

+19
-21
lines changed

1 file changed

+19
-21
lines changed

scripts/build-android-app.sh

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -937,47 +937,42 @@ adb_framework_ready_once() {
937937
local last_log=$SECONDS
938938

939939
while [ $SECONDS -lt $deadline ]; do
940-
local boot_ok dev_boot system_pid pm_ok activity_ok service_ok user_ready service_status cmd_ok resolve_ok
940+
local boot_ok dev_boot system_pid pm_ok service_ok cmd_ok resolve_ok service_status
941941
boot_ok="$($ADB_BIN -s "$serial" shell getprop sys.boot_completed 2>/dev/null | tr -d '\r')"
942942
dev_boot="$($ADB_BIN -s "$serial" shell getprop dev.bootcomplete 2>/dev/null | tr -d '\r')"
943943
system_pid="$(run_with_timeout "$per_try" "$ADB_BIN" -s "$serial" shell pidof system_server 2>/dev/null | tr -d '\r' || true)"
944+
944945
pm_ok=0
945-
activity_ok=0
946-
service_ok=0
947-
user_ready=0
948-
cmd_ok=0
949946
if run_with_timeout "$per_try" "$ADB_BIN" -s "$serial" shell pm path android >/dev/null 2>&1; then
950947
pm_ok=1
951948
fi
952-
if run_with_timeout "$per_try" "$ADB_BIN" -s "$serial" shell cmd activity get-standby-bucket >/dev/null 2>&1; then
953-
activity_ok=1
954-
fi
955-
if run_with_timeout "$per_try" "$ADB_BIN" -s "$serial" shell am get-current-user >/dev/null 2>&1; then
956-
user_ready=1
957-
fi
949+
950+
cmd_ok=0
958951
if run_with_timeout "$per_try" "$ADB_BIN" -s "$serial" shell cmd -l >/dev/null 2>&1; then
959952
cmd_ok=1
960953
fi
954+
961955
resolve_ok=0
962956
if run_with_timeout "$per_try" "$ADB_BIN" -s "$serial" shell \
963957
"cmd package resolve-activity --brief android.intent.action.MAIN -c android.intent.category.HOME" >/dev/null 2>&1; then
964958
resolve_ok=1
965959
fi
960+
961+
service_ok=0
966962
service_status="$(run_with_timeout "$per_try" "$ADB_BIN" -s "$serial" shell service check package 2>/dev/null | tr -d '\r' || true)"
967963
if [ -n "$service_status" ] && printf '%s' "$service_status" | grep -q "found"; then
968964
service_ok=1
969965
fi
970966

971967
if [ "$boot_ok" = "1" ] && [ "$dev_boot" = "1" ] && [ -n "$system_pid" ] \
972-
&& [ $pm_ok -eq 1 ] && [ $activity_ok -eq 1 ] && [ $service_ok -eq 1 ] \
973-
&& [ $resolve_ok -eq 1 ] \
974-
&& [ $cmd_ok -eq 1 ] && [ $user_ready -eq 1 ]; then
968+
&& [ $pm_ok -eq 1 ] && [ $cmd_ok -eq 1 ] && [ $resolve_ok -eq 1 ] \
969+
&& [ $service_ok -eq 1 ]; then
975970
ba_log "Android framework ready on $serial (system_server=$system_pid)"
976971
return 0
977972
fi
978973

979974
if [ $((SECONDS - last_log)) -ge $log_interval ]; then
980-
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 cmd_ready=$cmd_ok package_service_ready=$service_ok resolve_ready=$resolve_ok user_ready=$user_ready)"
975+
ba_log "Waiting for Android framework on $serial (system_server=${system_pid:-down} boot_ok=${boot_ok:-?}/${dev_boot:-?} pm_ready=$pm_ok cmd_ready=$cmd_ok package_service_ready=$service_ok resolve_ready=$resolve_ok)"
981976
last_log=$SECONDS
982977
fi
983978
sleep 2
@@ -1161,7 +1156,7 @@ ANDROID_AVD_HOME="$AVD_HOME" "$EMULATOR_BIN" -avd "$AVD_NAME" -port "$EMULATOR_P
11611156
-gpu swiftshader_indirect -no-audio -no-boot-anim \
11621157
-accel off -no-metrics -camera-back none -camera-front none -skip-adb-auth \
11631158
-feature -Vulkan -netfast -skin 1080x1920 -memory 2048 -cores 2 \
1164-
-writable-system -selinux permissive -partition-size 2048 >"$EMULATOR_LOG" 2>&1 &
1159+
-partition-size 4096 >"$EMULATOR_LOG" 2>&1 &
11651160
EMULATOR_PID=$!
11661161
trap stop_emulator EXIT
11671162

@@ -1221,6 +1216,13 @@ if ! wait_for_emulator "$EMULATOR_SERIAL"; then
12211216
exit 1
12221217
fi
12231218

1219+
# Provision and wake the device before framework readiness checks
1220+
"$ADB_BIN" -s "$EMULATOR_SERIAL" shell svc power stayon true >/dev/null 2>&1 || true
1221+
"$ADB_BIN" -s "$EMULATOR_SERIAL" shell settings put global device_provisioned 1 >/dev/null 2>&1 || true
1222+
"$ADB_BIN" -s "$EMULATOR_SERIAL" shell settings put secure user_setup_complete 1 >/dev/null 2>&1 || true
1223+
"$ADB_BIN" -s "$EMULATOR_SERIAL" shell input keyevent 82 >/dev/null 2>&1 || true
1224+
"$ADB_BIN" -s "$EMULATOR_SERIAL" shell am start -a android.intent.action.MAIN -c android.intent.category.HOME >/dev/null 2>&1 || true
1225+
12241226
if ! "$ADB_BIN" -s "$EMULATOR_SERIAL" shell pidof system_server >/dev/null 2>&1; then
12251227
ba_log "system_server not running after boot; restarting framework"
12261228
"$ADB_BIN" -s "$EMULATOR_SERIAL" shell stop >/dev/null 2>&1 || true
@@ -1250,12 +1252,8 @@ if ! wait_for_package_service "$EMULATOR_SERIAL"; then
12501252
fi
12511253

12521254
"$ADB_BIN" -s "$EMULATOR_SERIAL" shell locksettings set-disabled true >/dev/null 2>&1 || true
1253-
"$ADB_BIN" -s "$EMULATOR_SERIAL" shell settings put global device_provisioned 1 >/dev/null 2>&1 || true
1254-
"$ADB_BIN" -s "$EMULATOR_SERIAL" shell settings put secure user_setup_complete 1 >/dev/null 2>&1 || true
1255-
"$ADB_BIN" -s "$EMULATOR_SERIAL" shell svc power stayon usb >/dev/null 2>&1 || true
1256-
"$ADB_BIN" -s "$EMULATOR_SERIAL" shell input keyevent 82 >/dev/null 2>&1 || true
1255+
"$ADB_BIN" -s "$EMULATOR_SERIAL" shell svc power stayon true >/dev/null 2>&1 || true
12571256
"$ADB_BIN" -s "$EMULATOR_SERIAL" shell wm dismiss-keyguard >/dev/null 2>&1 || true
1258-
"$ADB_BIN" -s "$EMULATOR_SERIAL" shell am start -a android.intent.action.MAIN -c android.intent.category.HOME >/dev/null 2>&1 || true
12591257
"$ADB_BIN" -s "$EMULATOR_SERIAL" shell settings put global window_animation_scale 0 >/dev/null 2>&1 || true
12601258
"$ADB_BIN" -s "$EMULATOR_SERIAL" shell settings put global transition_animation_scale 0 >/dev/null 2>&1 || true
12611259
"$ADB_BIN" -s "$EMULATOR_SERIAL" shell settings put global animator_duration_scale 0 >/dev/null 2>&1 || true

0 commit comments

Comments
 (0)