Home | History | Annotate | Download | only in power
      1 page.title=Power Management
      2 @jd:body
      3 
      4 <!--
      5     Copyright 2015 The Android Open Source Project
      6 
      7     Licensed under the Apache License, Version 2.0 (the "License");
      8     you may not use this file except in compliance with the License.
      9     You may obtain a copy of the License at
     10 
     11         http://www.apache.org/licenses/LICENSE-2.0
     12 
     13     Unless required by applicable law or agreed to in writing, software
     14     distributed under the License is distributed on an "AS IS" BASIS,
     15     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     16     See the License for the specific language governing permissions and
     17     limitations under the License.
     18 -->
     19 <div id="qv-wrapper">
     20   <div id="qv">
     21     <h2>In this document</h2>
     22     <ol id="auto-toc"></ol>
     23   </div>
     24 </div>
     25 
     26 <p>Battery life is a perennial user concern. To extend battery life, Android
     27 continually adds new features and optimizations to help the platform optimize
     28 the off-charger behavior of applications and devices.</p>
     29 <p>Android includes the following battery life enhancements:</p>
     30 
     31 <ul>
     32 <li><b><a href="#app-standby">App Standby</b></a>. The platform can place
     33 unused applications in App Standby mode, temporarily restricting network access
     34 and deferring syncs and jobs for those applications.</li>
     35 <li><b><a href="#doze">Doze</b></a>. The platform can enter a state of deep
     36 sleep (periodically resuming normal operations) if users have not actively used
     37 their device (screen off and stationary) for extended periods of time. Android N
     38 also enables Doze to trigger a lighter set of optimizations when users turn
     39 off the device screen yet continue to move around.</li>
     40 <li><b><a href="#exempt-apps">Exemptions</b></a>. System apps and cloud
     41 messaging services preloaded on a device are typically exempted from App Standby
     42 and Doze by default (although app developers can intent their applications into
     43 this setting). Users can exempt applications via the Settings menu.</li>
     44 </ul>
     45 <p>The following sections describe these enhancements.</p>
     46 
     47 <h2 id="app-standby">App Standby</h2>
     48 <p>App Standby extends battery life by deferring background network activity
     49 and jobs for applications the user is not actively using.</p>
     50 
     51 <h3 id="app-standby-life">App Standby lifecycle</h3>
     52 <p>The platform detects inactive applications and places them in App Standby
     53 until the user begins actively engaging with the application.</p>
     54 
     55 <table>
     56 <tbody>
     57 <tr>
     58 <th width=46%>Detection</th>
     59 <th width=23%>During App Standby</th>
     60 <th width=31%>Exit</th>
     61 </tr>
     62 
     63 <tr>
     64 <td><p>The platform detects an application is inactive when the device is not
     65 charging <strong>and</strong> the user has not launched the application directly
     66 or indirectly for a specific amount of clock time as well as a specific amount
     67 of screen-on time. (Indirect launches occur when a foreground app accesses a
     68 service in a second app.)</p></td>
     69 <td><p>The platform prevents applications from accessing the network more than
     70 once a day, deferring application syncs and other jobs.</p></td>
     71 <td><p>The platform exits the app from App Standby when:</p>
     72 <ul>
     73 <li>Application becomes active.</li>
     74 <li>Device is plugged in and charging.</li>
     75 </ul>
     76 </td>
     77 </tr>
     78 </tbody>
     79 </table>
     80 
     81 <p>Active applications are unaffected by App Standby. An application is active
     82 when it has:</p>
     83 <ul>
     84 <li>A process currently in the foreground (either as an activity or foreground
     85 service, or in use by another activity or foreground service), such as
     86 notification listener, accessibility services, live wallpaper, etc.</li>
     87 <li>A notification viewed by the user, such as in the lock screen or
     88 notification tray.</li>
     89 <li>Explicitly been launched by the user.</li>
     90 </ul>
     91 <p>An application is inactive if none of the above activities has occurred for
     92 a period of time.
     93 </p>
     94 
     95 <h3>Testing App Standby</h3>
     96 <p>You can manually test App Standby using the following ADB commands:</p>
     97 
     98 <pre>
     99 $ adb shell dumpsys battery unplug
    100 $ adb shell am set-idle packageName true
    101 $ adb shell am set-idle packageName false
    102 $ adb shell am get-idle packageName
    103 </pre>
    104 
    105 <h2 id="doze">Doze</h2>
    106 
    107 <p>Doze extends battery life by deferring application background CPU and
    108 network activity when a device is unused for long periods.</p>
    109 
    110 <p>Idle devices in Doze periodically enter a maintenance window, during which
    111 apps can complete pending activities (syncs, jobs, etc.). Doze then resumes sleep
    112 for a longer period of time, followed by another maintenance window. The
    113 platform continues the Doze sleep/maintenance sequence, increasing the length of
    114 idle each time, until a maximum of a few hours of sleep time is reached. At all
    115 times, a device in Doze remains aware of motion and immediately leaves Doze
    116 if motion is detected.</p>
    117 
    118 <p>Android N extends Doze to trigger a lighter set of optimizations every time
    119 a user turns off the device screen, even when the user continues to move around,
    120 enabling longer lasting battery life.</p>
    121 
    122 <p>System services (such as telephony) may be preloaded and exempted from Doze
    123 by default. Users can also exempt specific applications from Doze in the
    124 Settings menu. By default, Doze is <b>disabled</b> in the Android Open Source
    125 Project (AOSP). For details on enabling Doze, see
    126 <a href="#integrate-doze">Integrating Doze</a>.</p>
    127 
    128 <h3 id="doze-reqs">Doze requirements</h3>
    129 <p>Doze support requires the device has a cloud messaging service, such as
    130 <a href="https://developers.google.com/cloud-messaging/">Google Cloud Messaging
    131 (GCM)</a>. This enables the device to know when to wake from Doze.</p>
    132 <p>Full Doze support also requires a
    133 <a href="{@docRoot}devices/sensors/sensor-types.html#significant_motion">Significant
    134 Motion Detector (SMD)</a> on the device; however, the lightweight Doze mode in
    135 Android N does not require an SMD. If Doze is enabled on a device that:</p>
    136 <ul>
    137 <li>Has an SMD, full Doze optimizations occur (includes lightweight
    138 optimizations).</li>
    139 <li>Does not have an SMD, only the lightweight Doze optimizations occur.</li>
    140 </ul>
    141 
    142 
    143 <h3 id="doze-life">Doze lifecycle</h3>
    144 
    145 <p>Doze begins when the platform detects the device is idle and
    146 ends when one or more exit criteria activities occur.</p>
    147 
    148 <table>
    149 <tbody>
    150 <tr>
    151 <th width=20%>Detection</td>
    152 <th width=60%>During Doze</th>
    153 <th width=20%>Exit</th>
    154 </tr>
    155 <tr>
    156 <td><p>The platform detects a device is idle when:</p>
    157 <ul>
    158 <li>Device is stationary (using significant motion detector).</li>
    159 <li>Device screen is off for some amount of time.</li>
    160 </ul>
    161 <p>Doze mode does not engage when the device is plugged into a power charger.
    162 </p>
    163 </td>
    164 <td><p>The platform attempts to keep the system in a sleep state, periodically
    165 resuming normal operations during a maintenance window then returning the device
    166 to sleep for longer repeating periods. During sleep, the following
    167 restrictions are active:</p>
    168 <ul>
    169 <li>Apps not allowed network access.</li>
    170 <li>App wakelocks ignored.</li>
    171 <li>Alarms deferred. Excludes alarm clock alarms and alarms set using
    172 <code>setAndAllowWhileIdle()</code> (limited to 1 per 15 minutes per app while
    173 in Doze). This exemption is intended for apps (such as Calendar) that must show
    174 event reminder notifications.</li>
    175 <li>Wi-Fi scans not performed.</li>
    176 <li>SyncAdapter syncs and JobScheduler jobs deferred until the next maintenance
    177 window.</li>
    178 <li>Apps receiving SMS and MMS messages are put on a temporary whitelist so
    179 they can complete their processing.</li>
    180 </ul>
    181 </td>
    182 <td><p>The platform exits the device from Doze when it detects:</p>
    183 <ul>
    184 <li>User interaction with device.</li>
    185 <li>Device movement.</li>
    186 <li>Device screen turns on.</li>
    187 <li>Imminent AlarmClock alarm.</li>
    188 </ul>
    189 <p>Notifications do not cause the device to exit from Doze.</p>
    190 </td>
    191 </tr>
    192 </tbody>
    193 </table>
    194 
    195 <p>Android N extends Doze by enabling a lightweight sleep mode during screen
    196 off, before the device is idle.</p>
    197 <p><img src="../images/doze_lightweight.png"></p>
    198 <p class="img-caption">Figure 1. Doze modes for non-stationary and stationary
    199 devices.</p>
    200 
    201 <table>
    202 <tbody>
    203 <tr>
    204 <th>Action</th>
    205 <th>Doze</th>
    206 <th>Lightweight Doze</th>
    207 </tr>
    208 <tr>
    209 <td>Trigger</td>
    210 <td>Screen off, on battery, stationary</td>
    211 <td>Screen off, on battery (unplugged)</td>
    212 </tr>
    213 <tr>
    214 <td>Timing</td>
    215 <td>Successively increasing periods with maintenance</td>
    216 <td>Repeated N-minute periods with maintenance windows</td>
    217 </tr>
    218 <tr>
    219 <td>Restrictions</td>
    220 <td>No network access, wake lock, or GPS/Wi-FI scan. Alarms and jobs/syncs deferred.</td>
    221 <td>No network access. Jobs/syncs deferred except during maintenance windows.</td>
    222 </tr>
    223 <tr>
    224 <td>Behavior</td>
    225 <td>Only high-priority push notification messages received.</td>
    226 <td>All real-time messages (instant messages, calls, etc.) received. High-priority push notification message enables temporary network access.</td>
    227 </tr>
    228 <tr>
    229 <td>Exit</td>
    230 <td>Motion, screen on, or alarm clock alarm.</td>
    231 <td>Screen on.</td>
    232 </tr>
    233 </tbody>
    234 </table>
    235 
    236 <h3 id="doze-interactions">Interaction with App Standby</h3>
    237 <ul>
    238 <li>Time spent in Doze does not count towards App Standby.</li>
    239 <li>While the device is in Doze, idle applications are allowed to perform normal
    240 operations at least once a day.</li>
    241 </ul>
    242 
    243 <h3 id="integrate-doze">Integrating Doze</h3>
    244 
    245 <p>When Doze is enabled, devices that support
    246 <a href="{@docRoot}devices/sensors/sensor-types.html#significant_motion">SENSOR_TYPE_SIGNIFICANT_MOTION</a>
    247 will perform full Doze optimizations (includes lightweight optimizations);
    248 devices without an SMD will perform only lightweight Doze optimizations. Android
    249 automatically selects the appropriate Doze optimizations and no vendor
    250 configuration is necessary.</p>
    251 
    252 <p>To enable Doze for a device, perform the following tasks:</p>
    253 
    254 <ol>
    255 <li>Confirm the device has a cloud messaging service installed.</li>
    256 <li>In the device overlay config file
    257 <code>overlay/frameworks/base/core/res/res/values/config.xml</code>, set
    258 <code>config_enableAutoPowerModes</code> to <b>true</b>:
    259 <pre>
    260 bool name="config_enableAutoPowerModes"&gt;true&lt;/bool&gt;
    261 </pre>
    262 <br>In AOSP, this parameter is set to false (Doze disabled) by default.<br>
    263 </li>
    264 <li>Confirm that preloaded apps and services:
    265 <ul>
    266 <li>Use the new
    267 <a href="https://developer.android.com/preview/behavior-changes.html#behavior-power">power-saving
    268 optimization guidelines</a>. For details, see <a href="#test-apps">Testing and
    269 optimizing applications</a>.
    270 <p><b>OR</b></p>
    271 <li>Are exempted from Doze and App Standby. For details, see
    272 <a href="#exempt-apps">Exempting applications</a>.</li>
    273 </ul>
    274 </li>
    275 <li>Confirm the necessary services are exempted from Doze.</a>
    276 </li>
    277 </ol>
    278 
    279 <h4 id="doze-tips">Tips</h4>
    280 <ul>
    281 <li>If possible, use GCM for
    282 <a href="https://developers.google.com/cloud-messaging/downstream">downstream
    283 messaging</a>.</li>
    284 <li>If your users must see a notification right away, use a
    285 <a href="https://developers.google.com/cloud-messaging/concept-options#setting-the-priority-of-a-message">GCM high priority
    286 message</a>.</li>
    287 <li>Provide sufficient information within the initial
    288 <a href="https://developers.google.com/cloud-messaging/concept-options#payload">message
    289 payload</a> (to avoid unnecessary subsequent network access).</li>
    290 <li>Set critical alarms with
    291 <a href="http://developer.android.com/reference/android/app/AlarmManager.html#setAndAllowWhileIdle(int,%20long,%20android.app.PendingIntent)">setAndAllowWhileIdle()</a>
    292 and
    293 <a href="http://developer.android.com/reference/android/app/AlarmManager.html#setExactAndAllowWhileIdle(int,%20long,%20android.app.PendingIntent)">setExactAndAllowWhileIdle()</a>.
    294 </li>
    295 </ul>
    296 
    297 <h4 id="test-apps">Testing and optimizing applications</h4>
    298 <p>Test all applications (especially preloaded applications) in Doze mode. For
    299 details, refer to
    300 <a href="https://developer.android.com/preview/testing/guide.html#doze-standby">Testing
    301 Doze and App Standby</a>.</p>
    302 
    303 <p class="note"><b>Note</b>: MMS/SMS/Telephony services function independently
    304 of Doze and will always wake client apps even while the device remains in Doze
    305 mode.</p>
    306 
    307 <h2 id="exempt-apps">Exempting applications</h2>
    308 <p>You can exempt applications from being subject to Doze or App Standby.
    309 Exemptions may be needed in the following use cases:</p>
    310 <ul>
    311 <li>OEM using non-GCM Cloud Messaging platform</li>
    312 <li>Carrier using non-GCM Cloud Messaging platform</li>
    313 <li>Third-party application using non-GCM Cloud Messaging platform</li>
    314 </ul>
    315 
    316 <p class="warning"><b>Warning</b>: Do not exempt apps to avoid testing and
    317 optimizing. Unnecessary exemptions undermine the benefits of Doze and App
    318 Standby and can compromise the user experience, so we strongly suggest
    319 minimizing such exemptions as they allow applications to defeat beneficial
    320 controls the platform has over power use. If users become unhappy about the
    321 power consumption of these apps, it can lead to frustration, bad experiences
    322 (and negative user reviews for the app), and customer support questions. For
    323 these reasons, we strongly recommend that you do not exempt third-party
    324 applications and instead exempt only cloud messaging services or apps with
    325 similar functions.</p>
    326 
    327 <p>Apps exempted by default are listed in a single view within the Settings >
    328 Battery menu. This list is used for exempting the app from both Doze and App
    329 Standby modes. To provide transparency to the user, the Settings menu
    330 <b>MUST</b> show all exempted applications.</p>
    331 
    332 <p>Users can manually exempt apps via Settings > Battery > Battery optimization
    333 > All apps and then selecting the app to turn off (or back on) optimization.
    334 However, users cannot unexempt any application or service that is exempted by
    335 default in the system image.</p>
    336