summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDimitrios Apostolou <jimis@qt.io>2022-01-05 12:01:50 +0100
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2022-01-06 19:25:15 +0000
commit3b9e3f976a6d0f3290473ead5ba68551e3fc0df8 (patch)
tree20770aa68eea9c5bd8a45e4d586f5feb42a19064
parent6250f2f0061568867ba6ec418b64e7723fdbf469 (diff)
Wait for boot to be fully complete with all packages installed
It happens that the android emulator supposedly "finishes" booting and getprop shows bootanim=stopped and boot_completed=1. But sometimes not all packages have been installed (`pm list packages` shows only 16 packages installed). After around half a minute the boot animation starts spinning (bootanim=running) again despite boot_completed=1 all the time. After some minutes the boot animation stops again and the list of packages contains 80 packages, among which is also the "development" package. Only then is the device ready for `adb install` of custom packages. This should be the last time we see the message: Error: Could not access the Package Manager. Is the system running? Just for completeness, we also properly disown the emulator process and its file descriptors, since the parent shell dies but the process stays. Fixes: QTQAINFRA-4681 Change-Id: I2b9d4bdc3dac0f10d09d4f09c83b4028ebc31f48 Reviewed-by: Daniel Smith <Daniel.Smith@qt.io> (cherry picked from commit c8e0a742fb316cf266ec6d56b9b702f07557e2e4) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
-rwxr-xr-xutil/android/android_emulator_launcher.sh35
1 files changed, 32 insertions, 3 deletions
diff --git a/util/android/android_emulator_launcher.sh b/util/android/android_emulator_launcher.sh
index 85308cacba..df334c3255 100755
--- a/util/android/android_emulator_launcher.sh
+++ b/util/android/android_emulator_launcher.sh
@@ -55,6 +55,27 @@ function check_if_fully_booted
[ "$bootanim" = stopped ] && [ "$boot_completed" = 1 ]
}
+function check_for_package_manager
+{
+( set +e
+ pm_output=`$ADB_EXEC shell pm get-install-location`
+ pm_retval=$?
+ [ $pm_retval = 0 ] && [[ ! "$pm_output" =~ ^Error: ]]
+)}
+
+# NOTE: It happens that the device "finishes" booting and getprop shows
+# bootanim=stopped and boot_completed=1. But sometimes not all packages have
+# been installed (`pm list packages` shows only 16 packages installed), and
+# after around half a minute the boot animation starts spinning
+# (bootanim=running) again despite boot_completed=1 all the time. After some
+# minutes the boot animation stops again and the list of packages contains 80
+# packages, among which is also the "development" package.
+function check_for_development_installed
+{
+ package_list=`$ADB_EXEC shell pm list packages`
+ echo "$package_list" | grep -q package:com.android.development
+}
+
for counter in `seq 1 ${EMULATOR_MAX_RETRIES}`; do
$ADB_EXEC start-server
@@ -69,17 +90,24 @@ for counter in `seq 1 ${EMULATOR_MAX_RETRIES}`; do
$EMULATOR_EXEC $EMULATOR_NAME \
-gpu swiftshader_indirect -no-audio -partition-size 4096 \
-cores 4 -memory 3500 -no-snapshot-load -no-snapshot-save \
- >$HOME/emulator.log 2>&1 &
+ </dev/null >$HOME/emulator.log 2>&1 &
emulator_pid=$!
+ disown $emulator_pid
$ADB_EXEC wait-for-device
# Wait about one minute for the emulator to come up
emulator_status=down
- for i in `seq 60`
+ for i in `seq 300`
do
sleep 1
- if check_for_android_device && check_if_fully_booted
+ echo $i
+ # Yes, you need to check continuously for all these heuristics,
+ # see comment above
+ if check_for_android_device \
+ && check_if_fully_booted \
+ && check_for_package_manager \
+ && check_for_development_installed
then
emulator_status=up
break
@@ -104,4 +132,5 @@ for counter in `seq 1 ${EMULATOR_MAX_RETRIES}`; do
fi
done
+
exit 0