11

I switched off the screen display of my Nexus 5 device running Android M and then issued the following commands.

im17-x0:~ r.j$ adb shell dumpsys battery unplug
im17-x0:~ r.j$ adb shell dumpsys deviceidle step
Stepped to: IDLE_PENDING
im17-x0:~ r.a$ adb shell dumpsys deviceidle step
Stepped to: SENSING
im17-x0:~ r.a$ adb shell dumpsys deviceidle step
Stepped to: IDLE

Now ideally my device should go to idle mode. But i started a CountDownTimer before putting it in idle mode and its still running. Also the network access is still there in my phone ( checked using this function)

Why is the device not going in doze mode? Following the options from here for standby mode also has the same effect. Why?

Also in that timer,if i check for isDeviceIdleMode(), it returns true.

1
  • 1
    Did you get the reason for this behaviour? I also have a similar use case and my timer seems to be running not being affected by Doze mode. But isDeviceIdleMode() returns true in logs. Commented Nov 4, 2015 at 9:45

5 Answers 5

1

I've got a few tips for you here:

Network Access

I'd suggest testing network access by actually attempting a network call and logging it out. There's a documented bug with checking network access programmatically while in idle mode:
https://code.google.com/p/android-developer-preview/issues/detail?id=3164

Checking Idle/Doze Mode

There isn't much documentation out there, but there are some methods which aren't muted by Doze mode. Using CountDownTimer might be one of those. I'd try setting an alarm using setExact(), which has been documented not to work when the app is in idle mode. If you can log something out when that alarm fires, you're definitely not in idle mode.

Let me know how that works for you!

1

As of now, the behavior looks like this

  1. isDeviceIdleMode() will return true.
  2. Network availability check in the app always returns true.( Checked using this function)
  3. There is no change in the network (no network broadcast fired ) when a device enters and comes out of doze mode. However, there is a broadcast fired(doze broadcast) when the device goes into and comes out of doze mode.
  4. However we can’t make a network call in doze mode.( Tried using HttpUrlConnection)

For getNetworkInfo() returning true in doze mode, there is a bug reported in Android (Link)

2
  • late reply, but...the 3rd point: What do you mean by there is no change? I now developing on MM, updated my Huawei Mate 7 to MM and realized that as soon as the device goes to doze mode, the Network changes. I have made some logs on my app and there is a change from Wifi to Mobile connection and back. Is this a bug made by Huawei Implementation or is this a normal MM behaviour? Commented May 19, 2016 at 6:29
  • 1
    @Opiatefuchs I hink he means that any existing tcp connection does not die automatically and continues to report as connected but cannot transmit nor receive data
    – behelit
    Commented Apr 15, 2020 at 22:27
1

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

1
  • I tried the commands adb shell dumpsys deviceidle force-idle and adb shell input keyevent KEYCODE_WAKEUP and thought they had no effect. Turns out the first one does after a minute or two.
    – Giszmo
    Commented Oct 19, 2018 at 1:21
0

I think the network will still come back as connected while in doze ( if you have a network connection) , however if you try to do anything other than GCM it will throw you an error.

0

REWRITE: My original answer hypothesized that your device wasn't actually in Doze mode, hence the link to improved instructions for getting into Doze mode and Diving Into Android 'M' Doze about IDLE_MAINTENANCE state where network activities are allowed to run.

My new hypothesis is (1) when deviceidle step replies Stepped to: IDLE, the device is in Doze mode, and (2) Doze mode is not behaving as we expect.

Google has updated the page Optimizing for Doze and App Standby, but it doesn't jive with your findings. They've provided additional info at Understanding what Doze mode means for your app and A flowchart for background work, alarms, and your Android app. Also see Issue 2225.

I'm afraid this still doesn't explain your results. Doze mode is complicated and under-documented.

Q. Is your app whitelisted? The Optimizing for Doze and App Standby page says:

An app that is whitelisted can use the network and hold partial wake locks during Doze and App Standby.

BTW, the command

adb shell dumpsys deviceidle

displays the current state (e.g. IDLE) and other info including the charging, motion, and screen on/off state that are prerequisites for Dozing, also the whitelist. This is useful for debugging.

4
  • This does not answer my question. You have basically written the same steps that i wrote in my question.
    – Diffy
    Commented Oct 5, 2015 at 16:43
  • @Diffy indeed, I have discarded that hypotheses and rewritten the answer with a new one.
    – Jerry101
    Commented Oct 5, 2015 at 18:02
  • @Diffy is your app whitelisted? That could explain it.
    – Jerry101
    Commented Oct 5, 2015 at 18:20
  • No my app is not whitelisted @Jerry101.
    – Diffy
    Commented Oct 14, 2015 at 6:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.