Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Doze Mode in M Preview

Doze Mode in M Preview

Doze Mode is one of the Power-Saving optimizations introduced in Android M.

This slides describes how it works and how to test the mode with your app.

Reference
- Behavior Changes | Android Developers
https://developer.android.com/preview/behavior-changes.html
- Testing Guide | Android Developers
https://developer.android.com/preview/testing/guide.html#doze-standby
- Diving Into Android 'M' Doze - NewCircle
https://newcircle.com/s/post/1739/2015/06/12/diving-into-android-m-doze

Hiroshi Kurokawa

July 08, 2015
Tweet

More Decks by Hiroshi Kurokawa

Other Decks in Technology

Transcript

  1. Power­Saving Optimizations from https://developer.android.com/preview/behavior-changes.html If a device is unplugged and

    left stationary with the screen off for a period of time, it goes into Doze mode where it attempts to keep the system in a sleep state. In this mode, devices periodically resume normal operations for brief periods of time... Network access is disabled Wake locks are ignored Alarms scheduled with the AlarmManager class are disabled WiFi scans are not performed Syncs and jobs for your sync adapters and JobScheduler are not permitted to run
  2. Exceptions Network access is enabled if the app receives a

    high priority Google Cloud Messaging tickle. Alarms set with setAlarmClock() method and AlarmManager.setAndAllowWhileIdle() are not ignored. The user can explicitly ask for the app to be exempt from optimizations, via Settings.
  3. Source Code and Setting Files com/android/server/DeviceIdleController.java Background service controlling device

    idle state. /data/system/deviceidle.xml Whitelist for user apps. You can add/remove your app to/from the list with Settings > App > [Your App] > Battery > Ignore optimizations. /system/etc/sysconfig/google.xml Whitelist for system apps. <!--?xml version='1.0' encoding='utf-8' standalone='yes' ?--> <config> <wl n="com.gunosy.android"> </wl></config>
  4. Behaviour In Doze mode, the device is in one of

    the following states. ACTIVE Device is currently active. INACTIVE Device is inactive (screen off, no motion) and we are waiting to for idle. IDLE_PENDING Device is past the initial inactive period, and waiting for the next idle period. IDLE Device is in the idle state, trying to stay asleep as much as possible. IDLE_MAINTENANCE Device is in the idle state, but temporarily out of idle to do regular maintenance.
  5. adb shell dumpsys deviceidle $ adb shell dumpsys deviceidle -h

    Device idle controller (deviceidle) dump options: [-h] [CMD] -h: print this help text. Commands: step Immediately step to next state, without waiting for alarm. disable Completely disable device idle mode. enable Re-enable device idle mode after it had previously been disabled. whitelist Add (prefix with +) or remove (prefix with -) packages.
  6. Show Status % adb shell dumpsys deviceidle Whitelist system apps:

    com.android.providers.downloads com.android.vending com.google.android.gms Whitelist user apps: com.gunosy.android Whitelist app uids: UID=10006: true UID=10009: true UID=10018: true UID=10086: true mSigMotionSensor={Sensor name="Significant Motion", vendor="hTC Corp.", version=1, type=17, maxRange= mCurDisplay=Display id 0: DisplayInfo{"Built-in Screen", uniqueId "local:0", app 1536 x 1952, real 1536 mIdleDisabled=false mScreenOn=false mCharging=false mSigMotionActive=true mState=IDLE_MAINTENANCE mInactiveTimeout=+30m0s0ms mNextAlarmTime=+7m9s227ms mNextIdlePendingDelay=+10m0s0ms mNextIdleDelay=+6h0m0s0ms
  7. Simulate Doze state changes % adb shell dumpsys battery unplug

    % adb shell dumpsys deviceidle step Stepped to: ACTIVE % adb shell dumpsys deviceidle step Stepped to: IDLE_PENDING % adb shell dumpsys deviceidle step Stepped to: IDLE % adb shell dumpsys deviceidle step Stepped to: IDLE_MAINTENANCE % adb shell dumpsys deviceidle step Stepped to: IDLE
  8. Add/Remove an app to/from Whitelist Add % adb shell dumpsys

    deviceidle whitelist +com.gunosy.android Added: com.gunosy.android Remove % adb shell dumpsys deviceidle whitelist -com.gunosy.android Removed: com.gunosy.android
  9. Behavior Changes | Android Developers Testing Guide | Android Developers

    Diving Into Android 'M' Doze - NewCircle https://developer.android.com/preview/behavior-changes.html https://developer.android.com/preview/testing/guide.html#doze- standby https://newcircle.com/s/post/1739/2015/06/12/diving-into- android-m-doze