blob: 32c20aabb88c85fc72db56d93c6a4db3b3949304 [file] [log] [blame]
Heidi von Markhambfadf222015-09-09 16:18:44 -07001page.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
27continually adds new features and optimizations to help the platform optimize
28the off-charger behavior of applications and devices.</p>
29<p>The Android 6.0 release includes the following improvements to battery life:
30</p>
31
32<ul>
33<li><b><a href="#app-standby">App Standby</b></a>. The platform can now place
34unused applications in App Standby mode, temporarily restricting network access
35and deferring syncs and jobs for those applications.</li>
36<li><b><a href="#doze">Doze</b></a>. The platform now enters a state of deep
37sleep (periodically resuming normal operations) if users have not actively used
38their device (screen off and stationary) for extended periods of time. As this
39feature requires the platform to detect the stationary state, it is available
40only on devices that implement the significant motion detection APIs in the
41Sensor HAL. Doze dramatically improves battery life.</li>
42<li><b><a href="#exempt-apps">Exemptions</b></a>. System apps and cloud
43messaging services preloaded on a device are typically exempted by default. App
44developers can intent their applications into this setting. Users can also
45exempt applications from App Standby and Doze via Settings > Battery >
46Battery optimization > All apps and then selecting the app to turn off (or back
47on) optimization.</li>
48</ul>
49<p>The following sections describe these improvements.</p>
50
51<h2 id="app-standby">App Standby</h2>
52<p>App Standby extends battery life by deferring background network activity
53and jobs for applications the user is not actively using.</p>
54
55<h3 id="app-standby-life">App Standby lifecycle</h3>
56<p>The platform detects inactive applications and places them in App Standby
57until the user begins actively engaging with the application.</p>
58
59<table>
60<tbody>
61<tr>
62<th width=33%>Detection</th>
63<th width=33%>During App Standby</th>
64<th width=33%>Exit</th>
65</tr>
66
67<tr>
68<td><p>The platform detects an application is inactive when the device is not
69charging <strong>and</strong> the user has not launched the application directly
70or indirectly for a specific amount of clock time as well as a specific amount
71of screen-on time. (Indirect launches occur when a foreground app accesses a
72service in a second app.)</p></td>
73<td><p>The platform prevents applications from accessing the network more than
74once a day, deferring application syncs and other jobs.</p></td>
75<td><p>The platform exits the app from App Standby when:</p>
76<ul>
77<li>Application becomes active.</li>
78<li>Device is plugged in and charging.</li>
79</ul>
80</td>
81</tr>
82</tbody>
83</table>
84
85<p>Active applications are unaffected by App Standby. An application is active
86when it has:</p>
87<ul>
88<li>A process currently in the foreground (either as an activity or foreground
89service, or in use by another activity or foreground service), such as
90notification listener, accessibility services, live wallpaper, etc.</li>
91<li>A notification viewed by the user, such as in the lock screen or
92notification tray.</li>
93<li>Explicitly been launched by the user.</li>
94</ul>
95<p>An application is inactive if none of the above activities has occurred for
96a period of time.
97</p>
98
99<h3>Testing App Standby</h3>
100<p>You can manually test App Standby using the following ADB commands:</p>
101
102<pre>
103$ adb shell dumpsys battery unplug
104$ adb shell am set-idle packageName true
105$ adb shell am set-idle packageName false
106$ adb shell am get-idle packageName
107</pre>
108
109<h2 id="doze">Doze</h2>
110
111<p>Doze extends battery life by deferring application background CPU and
112network activity when a device is unused for long periods.</p>
113
114<p>Idle devices in Doze periodically enter a maintenance window, during which
115apps can complete pending activities (syncs, jobs, etc.). Doze then resumes sleep
116for a longer period of time, followed by another maintenance window. The
117platform continues the Doze sleep/maintenance sequence, increasing the length of
118idle each time, until a maximum of a few hours of sleep time is reached. At all
119times, a device in Doze remains aware of motion and immediately leaves Doze
120if motion is detected.</p>
121
Heidi von Markham914a5622015-10-20 15:25:22 -0700122<p>System services (such as telephony) may be preloaded and exempted from Doze
123by default. Users can also exempt specific applications from Doze in the
124Settings menu. By default, Doze is <b>disabled</b> in the Android Open Source
125Project (AOSP). For details on enabling Doze, see
Heidi von Markhambfadf222015-09-09 16:18:44 -0700126<a href="#integrate-doze">Integrating Doze</a>.</p>
127
128<h3 id="doze-reqs">Doze requirements</h3>
129
130<p>Doze support requires the following:</p>
131<ul>
132<li>Device implements the
133<a href="http://source.android.com/devices/sensors/sensor-types.html#significant_motion">significant
134motion detector (SMD) APIs</a> in the Sensor HAL. Devices that do not implement
135these APIs cannot support Doze.</li>
136<li>Device has a cloud messaging service, such as
137<a href="https://developers.google.com/cloud-messaging/">Google Cloud Messaging
138(GCM).</a> This enables the device to know when to wake from Doze.</li>
139</ul>
140
141<h3 id="doze-life">Doze lifecycle</h3>
142
143<p>The Doze lifecycle begins when the platform detects the device is idle and
144ends when the device exits Doze mode.</p>
145
146<table>
147<tbody>
148<tr>
149<th width=33%>Detection</td>
150<th width=33%>During Doze</th>
151<th width=33%>Exit</th>
152</tr>
153<tr>
154<td><p>The platform detects a device is idle when:</p>
155<ul>
156<li>Device is stationary (using significant motion detector).</li>
157<li>Device screen is off for some amount of time.</li>
158</ul>
159<p>Doze mode does not engage when the device is plugged into a power charger.
160</p>
161</td>
162<td><p>The platform attempts to keep the system in a sleep state, periodically
163resuming normal operations during a maintenance window then returning the device
164to sleep for longer repeating periods. During the sleep state, the following
165restrictions are active:</p>
166<ul>
167<li>Apps not allowed network access.</li>
168<li>App wakelocks ignored.</li>
169<li>Alarms deferred. Excludes alarm clock alarms and alarms set using
Heidi von Markham914a5622015-10-20 15:25:22 -0700170<code>setAndAllowWhileIdle()</code> (limited to 1 per 15 minutes per app while
171in Doze). This exemption is intended for apps (such as Calendar) that must show
172event reminder notifications.</li>
Heidi von Markhambfadf222015-09-09 16:18:44 -0700173<li>Wi-Fi scans not performed.</li>
174<li>SyncAdapter syncs and JobScheduler jobs deferred until the next maintenance
175window.</li>
176<li>Apps receiving SMS and MMS messages are put on a temporary whitelist so
177they can complete their processing.</li>
178</ul>
179</td>
180<td><p>The platform exits the device from Doze when it detects:</p>
181<ul>
182<li>User interaction with device.</li>
183<li>Device movement.</li>
184<li>Device screen turns on.</li>
185<li>Imminent AlarmClock alarm.</li>
186</ul>
187<p>Notifications do not cause the device to exit from Doze.</p>
188</td>
189</tr>
190</tbody>
191</table>
192
193<h3 id="doze-interactions">Interaction with App Standby</h3>
194<ul>
195<li>Time spent in Doze does not count towards App Standby.</li>
196<li>While the device is in Doze, idle applications are allowed to perform normal
197operations at least once a day.</li>
198</ul>
199
200<h3 id="integrate-doze">Integrating Doze</h3>
201<p>To enable Doze for a device, perform the following tasks:</p>
202
203<ol>
204<li>Confirm the device supports
205<a href="http://source.android.com/devices/sensors/sensor-types.html#significant_motion">SENSOR_TYPE_SIGNIFICANT_MOTION
206</a>. If the device does not support this sensor, it cannot support Doze.</li>
207<li>Confirm the device has a cloud messaging service installed.</li>
208<li>In the device overlay config file
209<code>overlay/frameworks/base/core/res/res/values/config.xml</code>, set
210<code>config_enableAutoPowerModes</code> to <b>true</b>:
211<pre>
212bool name="config_enableAutoPowerModes"&gt;true&lt;/bool&gt;
213</pre>
214<br>In AOSP, this parameter is set to false (Doze disabled) by default.<br>
215</li>
216<li>Confirm that preloaded apps and services:
217<ul>
218<li>Use the new
219<a href="https://developer.android.com/preview/behavior-changes.html#behavior-power">power-saving
220optimization guidelines</a>. For details, see <a href="#test-apps">Testing and
221optimizing applications</a>.
222<p><b>OR</b></p>
223<li>Are exempted from Doze and App Standby. For details, see
224<a href="#exempt-apps">Exempting applications</a>.</li>
225</ul>
226</li>
227<li>Confirm the necessary services are exempted from Doze.</a>
228</li>
229</ol>
230
231<h4 id="test-apps">Testing and optimizing applications</h4>
232<p>Test all applications (especially preloaded applications) in Doze mode. For
233details, refer to
234<a href="https://developer.android.com/preview/testing/guide.html#doze-standby">Testing
235Doze and App Standby</a>.</p>
236
237<p class="note"><b>Note</b>: MMS/SMS/Telephony services function independently
238of Doze and will always wake client apps even while the device remains in Doze
239mode.</p>
240
241<h2 id="exempt-apps">Exempting applications</h2>
242<p>You can exempt applications from being subject to Doze or App Standby.</p>
243
244<p class="warning"><b>Warning</b>: Do not exempt apps to avoid testing and
245optimizing. Unnecessary exemptions undermine the benefits of Doze and App
246Standby and can compromise the user experience, so we strongly suggest
247minimizing such exemptions as they allow applications to defeat beneficial
248controls the platform has over power use. If users become unhappy about the
249power consumption of these apps, it can lead to frustration, bad experiences
250(and negative user reviews for the app), and customer support questions. For
251these reasons, we strongly recommend that you do not exempt third-party
252applications and instead exempt only cloud messaging services or apps with
253similar functions.</p>
254
255<p>Apps exempted by default are listed in a single view within the Settings >
256Battery menu. This list is used for exempting the app from both Doze and App
257Standby modes. To provide transparency to the user, the Settings menu
258<b>MUST</b> show all exempted applications.</p>
259
260<p>Users can manually exempt apps using the Settings menu. However, users cannot
261unexempt any application or service that is exempted by default in the system
262image.</p>