Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Testing doze and standby mode

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.

like image 385
Diffy Avatar asked Sep 03 '15 10:09

Diffy


People also ask

How do I test doze mode?

Testing your app with Doze Connect the device to your development machine and install your app. Run your app and leave it active. Observe the behavior of your app after you reactivate the device. Make sure the app recovers gracefully when the device exits Doze.

What is doze mode and app standby?

Doze simply keeps your phone from burning through the battery while it's asleep on a desk or table or something. An app that goes into Standby loses all network access and all its background sync jobs are suspended.

What is doze mode?

Doze. Doze extends battery life by deferring app background CPU and network activity when a device is unused for long periods. Idle devices in Doze periodically enter a maintenance window, during which apps can complete pending work (syncs, jobs, etc.).

How do I use doze mode?

On Android 6.0 Marshmallow: Doze mode gets activated after a while the screen is off, the device is stationary and it's running on battery. As you can see in the diagram above, when Doze Mode gets activated, the device doesn't get any wakelocks, network access, jobs/syncs, Alarms, GPS/Wi-fi scans.

What is doze or App Standby mode?

In Doze or App Standby mode, the system delivers the message and gives the app temporary access to network services and partial wakelocks, then returns the device or app to the idle state. For time sensitive, user-visible notifications, consider using high priority messages to enable delivery in Doze mode.

How do I test Doze Mode on Android?

Testing your app with Doze. You can test Doze mode by following these steps: Configure a hardware device or virtual device with an Android 6.0 (API level 23) or higher system image. Connect the device to your development machine and install your app. Run your app and leave it active.

How do I test my Android app in standby mode?

Testing your app with App Standby. To test the App Standby mode with your app: Configure a hardware device or virtual device with an Android 6.0 (API level 23) or higher system image. Connect the device to your development machine and install your app. Run your app and leave it active.

How do I test my Firebase Cloud Messaging app with Doze?

If your app requires a persistent connection to the network to receive messages, you should use Firebase Cloud Messaging (FCM) if possible. To confirm that your app behaves as expected with Doze, you can use adb commands to force the system to enter and exit Doze and observe your app’s behavior.


3 Answers

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!

like image 182
ccpmark Avatar answered Oct 18 '22 18:10

ccpmark


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)

like image 1
Diffy Avatar answered Oct 18 '22 19:10

Diffy


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

like image 1
AivarsDa Avatar answered Oct 18 '22 20:10

AivarsDa