how to adb wait-for-device until the home screen shows up? 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
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:


wait-for-device
long as getprop sys.boot_completed != 1 sleep some seconds
check getprop sys.boot_completed again
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