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?
Navigate to and open Settings, and then tap Battery and device care. Tap Battery, and then tap Background usage limits. The following settings will be available: Put unused apps to sleep: If you haven't used an app in a while, it will automatically be put to sleep.
With Bedtime mode, formerly known as Wind Down in the Digital Wellbeing settings, your Android phone can stay dark and quiet while you sleep. While Bedtime mode is on, it uses Do Not Disturb to silence calls, texts and other notifications that might disturb your sleep.
Open the dialer app of your phone. Two codes can be used to open up the secret tools: *#0*# and *#*#4636#*#* . The first code will launch tools to run standalone tests to check the performance of various hardware of your device, such as phone's screen display, volumes/power button, cameras, and sensor.
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.
Step 1
a. Put the device to "discharging" in settings (follow instructions in the red boxes).
b. Turn off the device screen by pressing the "power" button (blue box).
Step 2
a. To directly put the device to sleep mode, run:
adb shell dumpsys deviceidle force-idle
b. Or slowly step into sleep mode, run:
adb shell dumpsys deviceidle step
multiple times.
Step 3
To confirm device idle status, run:
adb shell dumpsys deviceidle get deep
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With