blob: 51c87e7914ee85c24c36f3e28d9790eb63cbe6ef [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
122<p>System services (such as telephony) and other preloaded services/apps are
123exempted from Doze by default. Users can also exempt specific applications from
124Doze in the Settings menu. By default, Doze is <b>disabled</b> in the Android
125Open Source 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
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
170<code>setAndAllowWhileIdle()</code>. This exemption is intended for apps (such
171as Calendar) that must show event reminder notifications.</li>
172<li>Wi-Fi scans not performed.</li>
173<li>SyncAdapter syncs and JobScheduler jobs deferred until the next maintenance
174window.</li>
175<li>Apps receiving SMS and MMS messages are put on a temporary whitelist so
176they can complete their processing.</li>
177</ul>
178</td>
179<td><p>The platform exits the device from Doze when it detects:</p>
180<ul>
181<li>User interaction with device.</li>
182<li>Device movement.</li>
183<li>Device screen turns on.</li>
184<li>Imminent AlarmClock alarm.</li>
185</ul>
186<p>Notifications do not cause the device to exit from Doze.</p>
187</td>
188</tr>
189</tbody>
190</table>
191
192<h3 id="doze-interactions">Interaction with App Standby</h3>
193<ul>
194<li>Time spent in Doze does not count towards App Standby.</li>
195<li>While the device is in Doze, idle applications are allowed to perform normal
196operations at least once a day.</li>
197</ul>
198
199<h3 id="integrate-doze">Integrating Doze</h3>
200<p>To enable Doze for a device, perform the following tasks:</p>
201
202<ol>
203<li>Confirm the device supports
204<a href="http://source.android.com/devices/sensors/sensor-types.html#significant_motion">SENSOR_TYPE_SIGNIFICANT_MOTION
205</a>. If the device does not support this sensor, it cannot support Doze.</li>
206<li>Confirm the device has a cloud messaging service installed.</li>
207<li>In the device overlay config file
208<code>overlay/frameworks/base/core/res/res/values/config.xml</code>, set
209<code>config_enableAutoPowerModes</code> to <b>true</b>:
210<pre>
211bool name="config_enableAutoPowerModes"&gt;true&lt;/bool&gt;
212</pre>
213<br>In AOSP, this parameter is set to false (Doze disabled) by default.<br>
214</li>
215<li>Confirm that preloaded apps and services:
216<ul>
217<li>Use the new
218<a href="https://developer.android.com/preview/behavior-changes.html#behavior-power">power-saving
219optimization guidelines</a>. For details, see <a href="#test-apps">Testing and
220optimizing applications</a>.
221<p><b>OR</b></p>
222<li>Are exempted from Doze and App Standby. For details, see
223<a href="#exempt-apps">Exempting applications</a>.</li>
224</ul>
225</li>
226<li>Confirm the necessary services are exempted from Doze.</a>
227</li>
228</ol>
229
230<h4 id="test-apps">Testing and optimizing applications</h4>
231<p>Test all applications (especially preloaded applications) in Doze mode. For
232details, refer to
233<a href="https://developer.android.com/preview/testing/guide.html#doze-standby">Testing
234Doze and App Standby</a>.</p>
235
236<p class="note"><b>Note</b>: MMS/SMS/Telephony services function independently
237of Doze and will always wake client apps even while the device remains in Doze
238mode.</p>
239
240<h2 id="exempt-apps">Exempting applications</h2>
241<p>You can exempt applications from being subject to Doze or App Standby.</p>
242
243<p class="warning"><b>Warning</b>: Do not exempt apps to avoid testing and
244optimizing. Unnecessary exemptions undermine the benefits of Doze and App
245Standby and can compromise the user experience, so we strongly suggest
246minimizing such exemptions as they allow applications to defeat beneficial
247controls the platform has over power use. If users become unhappy about the
248power consumption of these apps, it can lead to frustration, bad experiences
249(and negative user reviews for the app), and customer support questions. For
250these reasons, we strongly recommend that you do not exempt third-party
251applications and instead exempt only cloud messaging services or apps with
252similar functions.</p>
253
254<p>Apps exempted by default are listed in a single view within the Settings >
255Battery menu. This list is used for exempting the app from both Doze and App
256Standby modes. To provide transparency to the user, the Settings menu
257<b>MUST</b> show all exempted applications.</p>
258
259<p>Users can manually exempt apps using the Settings menu. However, users cannot
260unexempt any application or service that is exempted by default in the system
261image.</p>