Android device does not wake up (no adb device)


We’re running Appium tests on a CI server early in the morning. We currently have the problem that the android device is not recognized by adb devices when it tries to run the FIRST TEST (of multiple). All following tests run normal (e.g. adb devices recognized the device) (always-on option is enebaled in android dev settings). It seems that appium does some kind of magic after the first test failed. It somehow is able to wake up the android device.

I’ve tried multiple different approaches but none of them has worked reliably.

I’ve tried the following commands to wake up the device:
adb usb
adb shell input keyevent KEYCODE_WAKEUP

My question would be: What command does appium use internally to make sure the Android device is in a state that’s able to launch tests?

For anyone interested. I found that the following sequence of commands will wake up the device reliably:

[‘adb’, ‘get-state’]
[‘adb’, ‘kill-server’]
[‘adb’, ‘start-server’]
[‘adb’, ‘usb’]
[‘adb’, ‘shell’, ‘input’, ‘keyevent’, ‘KEYCODE_WAKEUP’]
[‘adb’, ‘wait-for-usb-device’]