How to test Doze Mode on Android?

10,173

Here is some useful information on Idle Mode:

deviceidle - Is a new android service, that will always run and listen for the several system events, which can trigger it in/out of the idle mode (also known as a Doze mode):

1.Screen on/off
2.Charging status
3.Significant motion detect

DeviceIdleController - When the device is awake and in-use, the controller is in the ACTIVE state. External events like inactivity time-out, user powering off the screen, motion detection ... will drive the state machine into INACTIVE. This state machine contains seven states:

1.ACTIVE - Device is in use, or connected to a charge source.
2.INACTIVE - Device has recently come out of the active state, meaning that user turned off the display or unplugged it.
3.IDLE_PENDING - Hold on, we are about to enter idle mode.
4.SENSING
5.LOCATING
6.IDLE - Device is idle.
7.IDLE_MAINTENANCE - Window is open for applications to do processing. Then will back to IDLE.

Idle State - In order to put the device into an Idle state you can use the following adb commands:

>adb shell dumpsys battery unplug
>adb shell dumpsys deviceidle force-idle

Active State - In order to put the device back into the Active state you may simulate the following key event:

> adb shell input keyevent KEYCODE_WAKEUP

I also needed a quick option to toggle between Active and Idle states so I wrote a batch script adbIdleModeSwitch.bat for these purposes, you may download and use it: https://drive.google.com/file/d/0B81qFnPX_eUUYTMxOTd1UG94NVk/view

Share:
10,173

Related videos on Youtube

abbath0767
Author by

abbath0767

Updated on June 04, 2022

Comments

  • abbath0767
    abbath0767 about 2 years

    There is an old Android app which work background 2 service (Service).

    It took to update the app with the possibility of sending data and logging while working is not a new DozeMode. Before you amend the current code I decided to check how everything will work now. To run the application, in the logs I see that both services are running (the basic meaning of the service to read the position of the device, the second service sends the data to the server). Turn off the screen with the command

    adb shell dumpsys deviceidle step
    

    translate the system to DozeMode:

    Nikita:app NG$ adb shell dumpsys deviceidle step
    Stepped to: ACTIVE
    Nikita:app NG$ adb shell dumpsys deviceidle step
    Stepped to: IDLE_PENDING
    Nikita:app NG$ adb shell dumpsys deviceidle step
    Stepped to: SENSING
    Nikita:app NG$ adb shell dumpsys deviceidle step
    Stepped to: LOCATING
    Nikita:app NG$ adb shell dumpsys deviceidle step
    Stepped to: IDLE
    

    If I understand everything correctly - IDLE just the same mode in which according to the documentation all services, jobsheduler's, alarm managers, and other background components should be turned off. But this is not happening. Judging by the logs, the app works as intended and DozeMode either I'm doing something wrong.

    Tell me, maybe are there any best practics for testing DozeMode and (late) rewriting with Services to a more modern, if there ways any action in the background (i.e. when you closed the app).

    Android 6, BlackView BV6000S, Application is missing in the list permitted for non-optimal battery life (whitelist)

    UPD: Nikita:app NG$ adb shell dumpsys deviceidle force-idle Now forced in to idle mode app works currently

  • abbath0767
    abbath0767 almost 7 years
    thx for answer! I have already found a solution but not found the time to post it. Nevertheless, thank you for your answer!
  • sebasira
    sebasira over 3 years
    I have a problem with doze Mode... I wanted to test it because I needed to wait about 15min to naturally enter this state.... Now whenver the screen goes off, it inmediately enters Doze, and I don't want that anymore. How can I revert it? Please look at: stackoverflow.com/q/66593485/2597775
  • AlexS
    AlexS about 3 years
    file is unavailable.