Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Detect when Android emulator is fully booted

I want to create a script where I start an emulator and after the system is fully booted, I want to install an .apk.

How can I know when the emulator is fully booted so I can run the install command? Here http://developer.android.com/guide/developing/tools/adb.html it is said that adb wait-for-device install <app>.apk is not correct.

So how can I achieve this? Is it possible? Is my only option to sleep for a few minutes until I can be sure that the emulator is started?

like image 922
Catalin Morosan Avatar asked Sep 03 '10 08:09

Catalin Morosan


People also ask

What is cold boot in Android emulator?

The first time you start an Android Virtual Device (AVD) with the Android Emulator, it must perform a cold boot (just like powering on a device), but subsequent starts are fast and the system is restored to the state at which you closed the emulator last (similar to waking a device).18-Dec-2017.

What is adb wait for device?

wait-for-device can be specified after adb to ensure that the command will run once the device is connected. -s can be used to send the commands to a specific device when multiple are connected.

Does Android emulator have device ID?

For me, the Android emulator device id, you can run the command adb devices , which will return you a list of the running emulators. The device id seems to be emulator- plus the port number the emulator is running on. For me, it's always running on port 5554, so my device id is always emulator-5554 .


3 Answers

adb shell getprop init.svc.bootanim

This will tell you whether or not the boot animation is running. It's what we use on our headless build server to check if the emulator is up. The sys.boot_completed from dac2009 is what lead me to find that flag. We use init.svc.bootanim instead because boot_completed has a tendency of triggering too early.

like image 101
neuron Avatar answered Sep 20 '22 05:09

neuron


while [ "`adb shell getprop sys.boot_completed | tr -d '\r' `" != "1" ] ; do sleep 1; done

This code gets the information from sys.boot_completed if the system boot is complete, removes a newline and compares the resulting value to 1. If its unequal 1/ not booted completly/ it will just sleep 1 second and tries again.

Just put your adb install... after this line of code.

like image 37
Sebo Avatar answered Sep 22 '22 05:09

Sebo


Im not sure if this works on all devices, but it works on the ones I have tested.

If you go into the shell, you can type getprop, and get a list of phone properties. There should be one called "sys.boot_completed".

If you type "getprop sys.boot_completed" it will respond "1" if the system is booted, and an empty string if the system is not booted.

like image 44
dac2009 Avatar answered Sep 24 '22 05:09

dac2009