1

original title: check if screen is locked via adb (Android)

I have a phone rooting script. It requires the phones to reboot several times and requires me to press "Enter" each time after they reboot. I want my script to know, via adb, when the lock screen is displayed (and reboot is complete).

I do not want to install additional software on the phone just to remove it when the script completes. I could use adb wait-for-device but the device becomes available before the reboot is complete. And I do not want to add N-second delays.

I want a method letting me to know that the lock screen has been displayed. (I do not configure the phones to use something other than the default lock screen, so it is ok to assume that it will be displayed).

EDIT

The solution https://stackoverflow.com/a/13095523/755804 worked. I leave the question in the original state to let other people willing to check if the lock screen is shown (the first time after reboot) learn about the dev.bootcomplete property.

# works
adb wait-for-device shell 'while [ "$(getprop dev.bootcomplete)" != "1" ] ; do sleep 1; done'

BTW, the broadcast comes a few seconds after the lock screen is shown.

EDIT2

The suggestion to use dumpsys did not work on my phone first (because I did not know what to grep for; @Mattia: you should not have deleted your answer.)

# it did not work for me
adb shell dumpsys power | grep mBootCompleted

but I think dumpsys is still worth mentioning, read: What's the Android ADB shell "dumpsys" tool and what are its benefits? Unlike logcat, dumpsys does not run infinitely, it prints a long output and then stops.

After some research, I could get the flag using the very slow

# very slow
adb shell dumpsys | grep -i mSystemBooted

and reasonably fast

adb shell dumpsys window | grep -i mSystemBooted

(first it displays nothing, then mSystemBooted=false, then mSystemBooted=true among other things on the same line). Probably the phrase can vary across devices and Android versions.

Community
  • 1
  • 1
18446744073709551615
  • 16,368
  • 4
  • 94
  • 127
  • 1
    Another question with an irrelevant title. The need you described should be fulfilled by checking `BOOT_COMPLETE`. The screen being locked is irrelevant. – Alex P. Oct 07 '15 at 15:51

0 Answers0