Skip to main content

Marshmallow, DOZE , Android DOZE

Marshmallow DOZE feature : What is this !!! 


Every major Android version brings lots of good stuff ( Let me focus only on positive energies in this article -;) ) and this time in Marshmallow DOZE feature. Google finally serious about battery performance. 

 DOZE = Saving your device battery performance when device is not active or in other words when it meets certain criteria. 

Is this the first we have feature like this in Android phones ? Nope not at all, almost every OEM spent lots of time and resources improving battery performance. 

Sony Mobile XPERIA : "Stamina Mode" has been around for couple of years and i think they need to retire that feature as DOZE and Stamina Mode conflicts and achieves similar goals.  This frustrates OEMs given they spend time and resource and google delivers it later stage of the game. 

In a nutshell, Android M includes new functions, Doze and App Standby, to improve battery life.

What does it means to Applications:  You need to verify your application while battery saving mode is active and when device resumes from this mode. 

For 3rd party Apps : For 99% of the time you just need to abide Android laws. If you have a strong reason to deviate request to register your app to whitelist to exempt from Doze/App Standby 


    Let me cover some basics of DOZE mode and App standby before dwelling into "How to verify your app"


Information presented in this blog is based on  my understanding of  Android developer page, Source code and Other sources.  

Overview of DOZE: 

Starting from Android 6.0 (API level 23), Android introduces 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

If a user leaves a device unplugged and stationary for a period of time, with the screen off, the device enters Doze mode. In Doze mode, the system attempts to conserve battery by restricting apps' access to network and CPU-intensive services. It also prevents apps from accessing the network and defers their jobs, syncs, and standard alarms.



Enter Doze mode when the following conditions are met

  • Screen is Off    
  • Not charging
  • Idle  (65 mins at least)
 >>>>  Periodically resuming normal operation – during maintenance window 

What is restricted in Doze idle mode?

  •        Alarm deferred. Excludes alarm clock alarms and alarms set using setAndAllowWhileIdle()
  •       WiFi scans not performed
  •       Apps not allowed network access (Mobile data, WiFi)
  •       App wakelocks ignored
  •       SyncAdapter syncs and Jobshceduler jobs deferred
  •       Location with GPS not performed

Figure 1. Doze provides a recurring maintenance window for apps to use the network and handle pending activities.

Little more detailed way : 


Fig 2: Life cycle of DOZE


Active or Charging:    

If( Screen == ON || Charging == YES || ( Idle == N/A || BatteryLevel == N/A  || Wakelock == N/A  || true )) 
          printf(" Device is in Active OR Charging mode );


Transition mode: 

if ( Screen == OFF && Charging == NO && Idle == YES && ( BatteryLevel == N/A ||  Wakelock == N/A || true ) 
       printf("Device is in transitioning to DOZE mode"); 

  
Entering DOZE mode ( Further details on Transition to DOZE mode ): 

It should be crystal clear from below diagram 

Fig 3 :  Entering IDLE mode.



Google did lot of tweaks to existing DeviceIdleController and IDLE transaction logic be found form below  ( It is not simple straight forward so you need to go different files if you want to understand entire logic ). 

https://android.googlesource.com/platform/frameworks/base/+/a750a63/services/core/java/com/android/server/DeviceIdleController.java

What is exempted and what is NOT: 

       #1 Apps NOT allowed N/W access bit Cellular Data and WiFi ) :

       What happens to those services like VoIP / SIP / Skype ...etc ????

  1.       Use Google Cloud Messaging(GCM) high priority message to see a notification right away - GCM is optimized to work with DOZE mode so Google recommends everyone to use GCM if possible. 
  2.     Not all so excited about GCM. If you don't want to change your app just register the app to whitelist . It is process, you need to fill in document and send it to Google explaining why you need to whitelisted :D. 


 #2 Alarm deferred: 
 Use setAndAllowWhileIdle() and setExactAndAllowWhileIdle() 
   Note: can’t fire alarm more than once per 15 mins per app. 
       #3 App wakelocks ignored 
 If you want wakelocks not to be ignored then register the app to whitelist. It is process, you need to fill in document and send it to Google explaining why you need to whitelisted :D. 
      #4 WiFi scans not performed
 No exemptions to be provided. 
     #5 SyncAdapter syncs and Jobshceduler jobs deferred
 No exemptions to be provided. 
     #6 : Location with GPS not performe
 No exemptions to be provided. 


How to test your App for Doze mode: 

It is as easy as 1 - 2 - 3 
 1. Put your into DOZE mode forcibly by following steps: 
1. Connect device to your PC
2. Run your app and leave it active
3. Turn screen off
4. Make the device unplugged state by the following command
$ adb shell dumpsys battery unplug
Move the device to Doze idle mode step by step(IDLE_PENDING->SENSING->LOCATING->IDLE) by repeating the following command
$ adb shell dumpsys deviceidle step
2.  Observe the behavior of your app during IDLE mode
Make sure the effect of the restriction is acceptable for user
3. Observe the behavior of your app after you reactivate the device
Make sure the app recovers gracefully when the device exits Doze. 


App standby top ... to be continued ..... ( I am tired of typing -:) ) : 






Comments

Popular posts from this blog

WinCE / PocketPC / Windows Mobile Power Battery Timeout - Solution

Hello Folks, I am back with yet another WinCE / Windows Mobile Solution this time it is something exciting and it is on Power Batter Suspend timeout related stuff. It is really challenging task to optimize battery life of any embedded device. Sometimes we want to control back light and battery suspend related activities through our program. OK .. here is simple question how do you control Back light, suspend timeout .. etc event through program ? To answer this question one has to understand "How WinCE operates w.r.t Power driver and what exactly happens behind the scenes". To simplify things ... i am going to divide whole things in three parts 1. WinCE OS Part whihc include Power / Battery drivers. 2. Application 3. Registry Registry : It is the place where all values gets stored i.e it acts as media for storing and retrieving values. I hope it is clear that Registry is nothing but global storage media and it has NO power to trigger anything. So that means it is of new us

What is the Current Directory in Windows CE & Windows Mobile ?

Lately i encountered  a situation where i had to find the current directory from where my application is running and all my config files reside. Question is "How do I find the current directory?" on Windows CE/Mobile devices. Desktop / PC it is just piece of cake but Windows CE / Mobile devices don't have a concept of a current directory.  Which means all pats are absolute and there is no concept called relative path. Due to lack of relative paths most of the files are loaded to the "Windows" directory and that is how Windows directory is crowded. Alternatively you can hard code directory path and insist user to load files always there. But i hate to hard code values or copy files to Windows directory.  So this has triggered to find a solution to identify my current directory. Since there is no concept of a current directory on a Windows CE / Windows Mobile device how would one locate a resource for which only a relative path is known?  That is what following c

Android Bluedroid debugging

Android Bluedroid Debugging  i.e New BT Stack from Android Community: Wow ... its been more than 2 years i updated my blog ... Am i too lazy or too busy or combination of both. Combination of both -:).  Anyways today i see a need to update my blog with some important info regarding Bluedroid debugging. Bluedroid is the latest and greatest Bluetooth stack from Android developed by Google & Broadcom jointly. So obviously Google does not have interest or resources to maintain two stacks hence they are going to drop famous BlueZ stack for good reasons.  BlueZ stack comes with lot of good tools like hcidump for debugging and i see all those tools no more work starting with Android JB MR2 a.k.a 4.3 which has Bluedroid integrated full-fledged.  So Bluedroid got to have new tools or some tools to debug but as usual Google is very poor at documenting the things and they leave finding puzzles to developers out there. SO today's quest is fining the debugging tools for Bluedroid.