25

I need to unlock my screen using adb, and wait-for-device exits way too early(when the device is booting up), and screen unlock fails. Is there a way to detect that the home screen, so I can fire screen unlock then?

This is the command I am using to unlock screen -

adb wait-for-device shell input keyevent 82
Umang
  • 351
  • 1
  • 3
  • 3

3 Answers3

30

well wait-for-device, as you already realized only waits until the adb daemon properly started. This is already at init time. In order to check for a complete boot you cann ad to your script something like:

in pseudo:

  1. wait-for-device
  2. long as getprop sys.boot_completed != 1 sleep some seconds check getprop sys.boot_completed again
  3. shell input keyevent 82

This should work.

Something like this:

#!/bin/bash

adb wait-for-device

A=$(adb shell getprop sys.boot_completed | tr -d '\r')

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

adb shell input keyevent 82

This is not tested so be aware of potential mistakes

divided-by-zero
  • 982
  • 6
  • 16
18

This is an old question and borderline off-topic but here is how to do it in a single line:

adb wait-for-device shell 'while [[ -z $(getprop sys.boot_completed) ]]; do sleep 1; done; input keyevent 82'
1

Here's what I came up with:

adb wait-for-device shell <<ENDSCRIPT
echo -n "Waiting for device to boot "
echo "" > /data/local/tmp/zero
getprop dev.bootcomplete > /data/local/tmp/bootcomplete
while cmp /data/local/tmp/zero /data/local/tmp/bootcomplete; do 
{
    echo -n "."
    sleep 1
    getprop dev.bootcomplete > /data/local/tmp/bootcomplete
}; done
echo "Booted."
exit
ENDSCRIPT

echo "Waiting 30 secs for us to be really booted"
sleep 30

echo "Unlocking screen"
adb shell "input keyevent 82"
Andy Balaam
  • 111
  • 1