Using the adb shell I can input text on the phone. But that does not work, if the phone's display is off. I have to press the home button first and unlock the screen for this to work. How can I automate this with the adb shell without adding additional code on the device?
adb shell input keyevent KEYCODE_HOME
Unfortunately, that does not work at all.
Use adb shell input keyevent 26
to wake up the device. (Source) Now do the text input or whatsoever you want to do. And, unlocking can also be done using input
command but different locks requires different technique, so you'll have to Google a bit, or provide the info here so that I/others can answer it.
The same command can put the device to sleep as well.