diff --git a/.github/workflows/scripts/android/android-emulator-tests.sh b/.github/workflows/scripts/android/android-emulator-tests.sh index 85531684..1cd32a30 100755 --- a/.github/workflows/scripts/android/android-emulator-tests.sh +++ b/.github/workflows/scripts/android/android-emulator-tests.sh @@ -95,10 +95,25 @@ log "Starting Android emulator" # launch the emulator in the background nohup emulator -no-metrics -partition-size 1024 -memory 4096 -wipe-data -no-window -no-snapshot -noaudio -no-boot-anim -avd "${ANDROID_EMULATOR_NAME}" & -log "Waiting for Android emulator startup" -adb start-server -sleep 5 -timeout "${ANDROID_EMULATOR_TIMEOUT}" adb wait-for-any-device +EMULATOR_CHECK_SECONDS_ELAPSED=0 +EMULATOR_CHECK_INTERVAL=5 # Seconds between status checks +while true; do + sleep "$EMULATOR_CHECK_INTERVAL" + ((EMULATOR_CHECK_SECONDS_ELAPSED+=EMULATOR_CHECK_INTERVAL)) + log "Waiting for Android emulator startup ($EMULATOR_CHECK_SECONDS_ELAPSED)" + + # Check if the boot is completed + # 'adb shell getprop sys.boot_completed' returns 1 when done + # Ignore failure status since it will fail with "adb: device offline" + BOOT_STATUS=$(adb shell getprop sys.boot_completed || true 2>/dev/null | tr -d '\r') + + if [ "$BOOT_STATUS" == "1" ]; then + log "Emulator is ready" + break; + elif [ "$EMULATOR_CHECK_SECONDS_ELAPSED" -ge "$ANDROID_EMULATOR_TIMEOUT" ]; then + fatal "Timeout reached ($ANDROID_EMULATOR_TIMEOUT seconds). Aborting." + fi +done log "Prepare Swift test package" # create a staging folder where we copy the test executable