How to wait until Android Studio virtual machine is fully loaded

30 Views Asked by At

After running my virtual machine with this command in Python:

os.system('emulator -avd Galaxy_Note9_API_27 -writable-system -no-snapshot-update-time')

I try to wait with another command (command below) until the device is fully loaded

os.system("adb -s emulator-5554 wait-for-device shell 'while [[ -z $(getprop dev.bootcomplete) ]] ; do sleep 1; done'")

But my problem with the above code is that it is a while loop but I want it to be in such a way that if after 120 seconds of waiting for the device to load it will return an error to me because I encounter this problem a lot that my device would crash when running and I would get stuck in an infinite loop

1

There are 1 best solutions below

0
Diego Torres Milano On

It's not clear why you are using python to invoke adb command, however if there's a reason, you can use subprocess, for many other reasons but because it supports timeout too, instead of os.system:

subprocess.run(["adb", "-s", "emulator-5554", "wait-for-device"], timeout=120)