Skip to content

Instantly share code, notes, and snippets.

@y-polek
Last active May 23, 2024 16:51
Show Gist options
  • Save y-polek/febff143df8dd92f4ed2ce4035c99248 to your computer and use it in GitHub Desktop.
Save y-polek/febff143df8dd92f4ed2ce4035c99248 to your computer and use it in GitHub Desktop.
adb commands to test Doze mode
#! /bin/zsh
# Buttery powered state
adb shell dumpsys battery | grep powered
# Unplug battery
adb shell dumpsys battery unplug
# Reset battery
adb shell dumpsys battery reset
# Dump Doze mode info
adb shell dumpsys deviceidle
# Enable Doze mode (may be required on Android Emulator)
adb shell dumpsys deviceidle enable
# Get status of Light Doze mode
adb shell dumpsys deviceidle get light
# Get status of Deep Doze mode
adb shell dumpsys deviceidle get deep
# Enter Light Doze mode (should be called several times to pass all phases)
adb shell dumpsys deviceidle step light
# Enter Deep Doze mode (should be called several times to pass all phases)
adb shell dumpsys deviceidle step deep
@progmars
Copy link

I found that adb shell dumpsys deviceidle step deep does not cause any real deep sleep side effects.
Only if I enter:
adb shell dumpsys deviceidle force-idle
my app behaves as in real deep sleep - network connections get disrupted and app thinks its offline.

Also, there's a typo in the comment - the last line should be Deep Doze

@Fjnova
Copy link

Fjnova commented Apr 23, 2021

Hello @y-polek @progmars

Does it affect to older Android version? Or it just starts from Android 6.0 (API level 23)?
Thanks

@chaoscreater
Copy link

I found that adb shell dumpsys deviceidle step deep does not cause any real deep sleep side effects. Only if I enter: adb shell dumpsys deviceidle force-idle my app behaves as in real deep sleep - network connections get disrupted and app thinks its offline.

Also, there's a typo in the comment - the last line should be Deep Doze

What's the difference between force-idle and step deep?

@progmars
Copy link

progmars commented Oct 4, 2022

@chaoscreater step deep steps the device closer to the deep doze and is not guaranteed to reach it immediately with the first call. That's why you have to call it multiple times, and with each call, it will step into the next state closer to deep doze, until it finally reaches it.
But when you call force idle, it seems to skip all of the gradual stepping and goes to idle state (not sure if it's light or deep - have to check by calling get) immediately.

@chaoscreater
Copy link

@chaoscreater step deep steps the device closer to the deep doze and is not guaranteed to reach it immediately with the first call. That's why you have to call it multiple times, and with each call, it will step into the next state closer to deep doze, until it finally reaches it. But when you call force idle, it seems to skip all of the gradual stepping and goes to idle state (not sure if it's light or deep - have to check by calling get) immediately.

Thanks. How many times would I need to call step deep to get it to the deep doze state? I'm using MacroDroid / Tasker to call it and I can loop
the command X number of times.

You mentioned that force idle seems to cause issues and I noticed that too, for example the clock in my status bar doesn't update, unless I turn off the screen and turn it back on. Have you noticed any issues with the phone in deep doze mode from using step deep?

@progmars
Copy link

progmars commented Oct 4, 2022

I have found the following information about step commands:

Each of the doze modes will have multiple states.

Light: ACTIVE -> IDLE -> IDLE_MAINTENANCE -> OVERRIDE
Deep: ACTIVE -> IDLE_PENDING -> SENSING -> LOCATING -> IDLE -> IDLE_MAINTENANCE

Regarding the force idle issues - in my case, that was exactly what I expected. I wanted to see what happens with my app when the phone goes to sleep, and it is expected that it will kill some background tasks and interrupt the network. That's very much expected on real devices, so your app should deal with such situations properly.
The behavior differs among devices from different manufacturers. https://dontkillmyapp.com/ this is a very insightful site that tells more about the problems your apps can expect from deep idle states.

@chaoscreater
Copy link

chaoscreater commented Oct 4, 2022

I have found the following information about step commands:

Each of the doze modes will have multiple states.
Light: ACTIVE -> IDLE -> IDLE_MAINTENANCE -> OVERRIDE
Deep: ACTIVE -> IDLE_PENDING -> SENSING -> LOCATING -> IDLE -> IDLE_MAINTENANCE

Regarding the force idle issues - in my case, that was exactly what I expected. I wanted to see what happens with my app when the phone goes to sleep, and it is expected that it will kill some background tasks and interrupt the network. That's very much expected on real devices, so your app should deal with such situations properly. The behavior differs among devices from different manufacturers. dontkillmyapp.com this is a very insightful site that tells more about the problems your apps can expect from deep idle states.

Thanks for the info. Yep I know about dontkillmyapp and don't really have any issues with the apps on my phone, they're all whitelisted and run fine. I'm just trying to force my phone to go into doze mode properly. I know there are apps like ForceDoze and NapTime and some other ones, but I don't the doze profiles that they use and prefer to use my own. I also wanted to use a single app to automate everything (hence using Tasker and MacroDroid) and so the last thing I needed was to force doze mode using either step deep or force idle, but obviously wasn't sure what the difference was between them, until now.

Just to confirm, you mentioned that using step deep that it "does not cause any real deep sleep side effects". So does that mean your phone was in deep sleep and yet it wasn't having any issues? E.g. apps that are whitelisted can still generate notifications, etc?

@progmars
Copy link

progmars commented Oct 4, 2022

I think at that time I did not call step deep enough times. force idle felt more convenient because it worked immediately.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment