I'm writing an android application that depends on network activity and the alarm manager sometimes waking the phone up from a sleeping state.
My question is how can I reliably test this on device? Ideally, how can I force the phone into a full-on sleeping state. Failing that, how can I know for sure when the phone has fully gone to sleep?
How do you test your Alarm Manager / Wake Lock / Sleep handling code?
Turn off the screen of the device/emulator and then run the following commands:
adb shell dumpsys battery unplug
adb shell dumpsys deviceidle step
Re-run the second one until you get the message "IDLE". This works on devices running Android 6.0 or newer.