Doze Mode — Android

Abhishek Luthra
Cashify Engineering
4 min readNov 5, 2018

This is the first part of a series of articles on “How does Android optimize battery usage in new releases?”

Starting from Marshmallow, the Android Framework Team introduced two power-saving features that extend battery life for users by managing how apps behave when a device is not connected to a power source: Doze and App Standby.

In this article, I am going to discuss Doze Mode. App Standby will be discussed in a separate article.

Doze

When you leave your phone overnight on the nightstand without plugging it in, and you wake up in the morning next day and realize the phone’s battery juice is totally drained, you’re going to have a bad day. Android wanted to solve this problem, and they came up with what is now called Doze Mode.

There has been some variation in how Doze works in Marshmallow (M-release) and Nougat (N-release)

So let’s take a look at how doze works in above two android releases.

  1. [M-release]

Android OS continuously monitors:

  • Whether the device is stationary (Android uses a motion detection sensor on the device to detect if the device is stationary. Motion detection sensor is a must for Doze mode to work.)
  • Whether the device is on battery (charger is not plugged in)
  • Whether the device screen is off

If the device has been in above three conditions simultaneously for some time, Android OS does a finer motion detection to make sure the device is not in a steadily moving vehicle (or in the pocket of a walking person) and is stationary with earth as a reference point. At some point, when the device actually has been stationary for quite some time, the first phase of Doze kicks in (green horizontal bars in below diagram), and this stays for an order of tens of minutes. At this point, applications lose Wake-locks, Network Access, and there are no more GPS or WiFi scans. Moreover, Jobs and Syncs and Alarms get deferred until the next maintenance window.

Let’s suppose these thin orange bars that you’re seeing (in the diagram below) are some kind of background activity, the thick solid orange vertical bars are maintenance windows and the solid horizontal green bar is the Doze window.

The thin orange bars represent background activity, green horizontal bars are doze windows and solid thick orange vertical bars are maintenance windows (to which background activity is deferred to).

The maintenance window is where all that background activity gets coalesced. It is where all these restrictions are lifted for a brief period for applications to be able to perform any pending background activity to refresh their content.

Developers have the urge of refreshing the content of their app in the background by running some background task (which consumes power). So what Android did is balance battery life with the expectation of content freshness that users have on their devices. Further, if the device continues to be stationary, on battery with the screen off, then the time span of doze windows grows exponentially with maintenance windows in between, and this pattern will continue until the Doze time (green bars) get to about a few hours as shown above.

2. [N-release]

Android OS from Nougat release has bifurcated Doze Mode into two phases: Lighter and Full Doze Mode

[N-release Lighter Doze Mode]

The thin orange bars represent background activity, green bars are doze window and solid thick orange vertical bars are maintenance window(to which background activity is deferred to).

In Nougat release, shortly after the three conditions of Doze are met, the first phase of Doze kicks in. And now, this is a lighter, gentler Doze than what you saw with Marshmallow (Android 6). Here it’s only going to restrict an application’s network access, and any of these jobs and syncs will get deferred to the next maintenance window, sort of the familiar maintenance window we saw in Marshmallow.

In the maintenance window, these restrictions are lifted to allow any pending activity to resume. This Doze window-maintenance window pattern will end when any of the three conditions of Doze are violated by doing any of the following:

  • The screen is turned on
  • The device is not stationary
  • The device is plugged into the charger

[N-release Full Doze Mode]

The red box indicates the initial Lighter Doze Phase with fewer restrictions and after that Lighter Doze phase, full set of Doze restrictions are imposed just as in Marshmallow.

After the device has been in initial Lighter Doze phase for some time and the device still fulfills the three conditions of Doze, then just like it does in Marshmallow, the full set of Doze restrictions will kick in. So at that point, applications will lose wake-locks, their alarms will get deferred, and there will be no more GPS or WiFi scans in addition to jobs/syncs being deferred and no network access. Now, these are the same restrictions that Marshmallow enforced in Doze Mode.

--

--