1page.title=Power-Saving Optimizations
2page.keywords=preview,sdk,compatibility
3sdk.platform.apiLevel=MNC
4@jd:body
5
6<div id="qv-wrapper">
7<div id="qv">
8
9<h2>In this document</h2>
10
11<ol  class="hide-nested">
12    <li><a href="#behavior-doze">Doze</a></li>
13    <li><a href="#behavior-app-standby">App Standby</a></li>
14</ol>
15
16<h2>API Differences</h2>
17<ol>
18<li><a href="{@docRoot}preview/download.html">API level 22 to M Preview &raquo;</a> </li>
19</ol>
20
21
22<h2>See Also</h2>
23<ol>
24<li><a href="{@docRoot}preview/api-overview.html">M Developer Preview API Overview</a> </li>
25</ol>
26
27</div>
28</div>
29
30<p>Android M Preview helps prolong battery life by introducing new power-saving optimizations:
31<em>Doze</em> mode improves the sleep efficiency of idle devices. <em>App Standby</em> prevents apps
32from eating up power while idle.</p>
33
34<h2 id="behavior-doze">Doze</h2>
35<p>If a user leaves a device unplugged and stationary for a period of time, with the screen off,
36the device enters Doze mode. Doze attempts to keep the system in a sleep state as long as the
37device remains undisturbed. In this mode, devices periodically resume normal operations for brief periods of time so that the system can perform app syncing and any other pending operations.</p>
38
39<p>The following restrictions apply to your apps while in Doze:</p>
40<ul>
41<li>Network access is disabled, unless your app receives a high-priority
42<a href="https://developers.google.com/cloud-messaging/" class="external-link">
43Google Cloud Messaging</a> tickle.</li>
44<li>The system ignores <a href="{@docRoot}reference/android/os/PowerManager.WakeLock.html">
45Wake locks</a>.</li>
46<li>Alarms scheduled using the {@link android.app.AlarmManager} class are deferred, unless you have
47exempted them using the
48{@link android.app.AlarmManager#setAndAllowWhileIdle setAndAllowWhileIdle()} method.</li>
49<li>The system does not perform Wi-Fi scans.</li>
50<li>The system does not permit syncs or jobs for your sync adapters.</li>
51<li>The system does not allow {@link android.app.job.JobScheduler} to run.</li>
52</ul>
53</p>
54<p>When the device exits Doze mode, it executes any jobs and syncs that are pending.</p>
55
56<h3>Testing apps with Doze</h3>
57
58<p>You can test Doze mode by connecting your development host to a device running the M Preview,
59and calling the following commands:
60</p>
61<pre class="no-prettyprint">
62$ adb shell dumpsys battery unplug
63$ adb shell dumpsys deviceidle step
64$ adb shell dumpsys deviceidle -h
65</pre>
66<p class="note"><strong>Note</strong>: As of M Preview 3 release,
67<a href="https://developers.google.com/cloud-messaging/" class="external-link">
68Google Cloud Messaging</a> (GCM) lets you designate
69<a href="https://developers.google.com/cloud-messaging/downstream#setting-the-priority-of-a-message">
70high-priority messages</a>. If your app receives a high-priority GCM message</a>, the system grants
71brief network access even when the device is dozing.
72</p>
73
74<p>See the
75<a href="{@docRoot}preview/testing/guide.html#doze-standby">Testing Guide</a> for tips on how
76to test Doze in your apps. </p>
77
78<h2 id="behavior-app-standby">App Standby</h2>
79<p>App Standby allows the system to determine that an app is idle when the user is not actively
80using it. The system makes this determination when the user does not touch the app for a certain
81period of time, and none of the following conditions applies:</p>
82
83<ul>
84<li>The user explicitly launches the app.</li>
85<li>The app has a process currently in the foreground (either as an activity or foreground service,
86or in use by another activity or foreground service).</li>
87<li>The app generates a notification that users see on the lock screen or in the
88notification tray.</li>
89<li>The user explicitly asks for the app to be exempt from optimizations,
90via the Settings app.</li>
91</ul>
92
93<p>When the user plugs the device into a power supply, the system releases apps from the standby
94state, allowing them to freely access the network and to execute any pending jobs and syncs. If the
95device is idle for long periods of time, the system allows idle apps network access around once a
96day.</p>
97
98<h3>Testing apps with App Standby</h3>
99<p>You can test App Standby by connecting your development host to a device running the M Preview,
100and calling the following commands:
101</p>
102<pre class="no-prettyprint">
103$ adb shell dumpsys battery unplug
104$ adb shell am set-idle &lt;packageName&gt; true
105$ adb shell am set-idle &lt;packageName&gt; false
106$ adb shell am get-idle &lt;packageName&gt;
107</pre>
108
109<p class="note"><strong>Note</strong>:
110As of M Preview 3 release,
111<a href="https://developers.google.com/cloud-messaging/" class="external-link">
112Google Cloud Messaging</a> (GCM) lets you
113designate
114<a href="https://developers.google.com/cloud-messaging/downstream#setting-the-priority-of-a-message">
115high-priority messages</a>. If your app receives high-priority GCM messages, the system grants
116brief network access even when the app is idle.
117</p>
118
119<p>See the
120<a href="{@docRoot}preview/testing/guide.html#doze-standby">Testing Guide</a> for tips on how
121to test App Standby in your apps. </p>
122