2015-09-11 19:00:08 -07:00
|
|
|
|
page.title=Optimizing for Doze and App Standby
|
|
|
|
|
page.metaDescription=Test and optimize your app for the power-saving features in Android 6.0.
|
2015-09-28 10:52:18 -07:00
|
|
|
|
page.tags=doze, app standby, marshmallow, alarms
|
2015-09-11 19:00:08 -07:00
|
|
|
|
meta.tags="battery", "marshmallow", "alarms"
|
2015-09-28 11:22:53 -07:00
|
|
|
|
page.image=images/cards/card-doze_16-9_2x.png
|
2015-09-29 09:43:46 -07:00
|
|
|
|
|
|
|
|
|
|
2015-09-11 19:00:08 -07:00
|
|
|
|
parent.link=index.html
|
|
|
|
|
|
|
|
|
|
trainingnavtop=true
|
|
|
|
|
next.title=Monitoring the Battery Level and Charging State
|
|
|
|
|
next.link=battery-monitoring.html
|
|
|
|
|
@jd:body
|
|
|
|
|
|
|
|
|
|
<div id="tb-wrapper">
|
|
|
|
|
<div id="tb">
|
|
|
|
|
<h2>In this document</h2>
|
|
|
|
|
<ol>
|
|
|
|
|
<li><a href="#understand_doze">Understanding Doze</a>
|
|
|
|
|
<ol>
|
2015-09-28 12:29:41 -07:00
|
|
|
|
<li><a href="#restrictions">Doze restrictions</a></li>
|
|
|
|
|
<li><a href="#assessing_your_app">Adapting your app to Doze</a></li>
|
2015-09-11 19:00:08 -07:00
|
|
|
|
</ol>
|
|
|
|
|
</li>
|
|
|
|
|
<li><a href="#understand_app_standby">Understanding App Standby</a></li>
|
2015-09-28 12:29:41 -07:00
|
|
|
|
<li><a href="#using_gcm">Using GCM to Interact with Your App</a></li>
|
|
|
|
|
<li><a href="#support_for_other_use_cases">Support for Other Use Cases</a></li>
|
|
|
|
|
<li><a href="#testing_doze_and_app_standby">Testing with Doze and App
|
|
|
|
|
Standby</a>
|
2015-09-11 19:00:08 -07:00
|
|
|
|
<ol>
|
2015-09-28 12:29:41 -07:00
|
|
|
|
<li><a href="#testing_doze">Testing your app with Doze</a></li>
|
|
|
|
|
<li><a href="#testing_your_app_with_app_standby">Testing your app with App Standby</a></li>
|
2015-09-11 19:00:08 -07:00
|
|
|
|
</ol>
|
|
|
|
|
</li>
|
2015-09-28 12:29:41 -07:00
|
|
|
|
<li><a href="#whitelisting-cases">Example Use Cases for Whitelisting</a></li>
|
2015-09-11 19:00:08 -07:00
|
|
|
|
</ol>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<p>
|
|
|
|
|
Starting from Android 6.0 (API level 23), Android introduces two
|
|
|
|
|
power-saving features that extend battery life for users by managing how apps behave when a
|
2015-09-28 12:29:41 -07:00
|
|
|
|
device is not connected to a power source. <em>Doze</em> reduces battery consumption by deferring
|
|
|
|
|
background CPU and network activity for apps when the device is unused for long periods
|
2015-09-11 19:00:08 -07:00
|
|
|
|
of time. <em>App Standby</em> defers background network activity for apps
|
2015-09-28 12:29:41 -07:00
|
|
|
|
with which the user has not recently interacted.
|
2015-09-11 19:00:08 -07:00
|
|
|
|
</p>
|
|
|
|
|
|
|
|
|
|
<p>
|
|
|
|
|
Doze and App Standby manage the behavior of all apps running on Android 6.0
|
|
|
|
|
or higher, regardless whether they are specifically targeting API level 23.
|
|
|
|
|
To ensure the best experience for users, test your app in Doze and App
|
|
|
|
|
Standby modes and make any necessary adjustments to your code. The sections
|
|
|
|
|
below provide details.
|
|
|
|
|
</p>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<h2 id="understand_doze">Understanding Doze</h2>
|
|
|
|
|
<p>
|
|
|
|
|
If a user leaves a device unplugged and stationary for a period of time, with
|
|
|
|
|
the screen off, the device enters Doze mode. In Doze mode, the system
|
2015-09-28 12:29:41 -07:00
|
|
|
|
attempts to conserve battery by restricting apps' access to network and
|
|
|
|
|
CPU-intensive services. It also prevents apps from accessing the network and
|
2015-09-11 19:00:08 -07:00
|
|
|
|
defers their jobs, syncs, and standard alarms.
|
|
|
|
|
</p>
|
|
|
|
|
|
|
|
|
|
<p>
|
|
|
|
|
Periodically, the system exits Doze for a brief time to let apps complete
|
|
|
|
|
their deferred activities. During this <em>maintenance window</em>, the
|
2015-09-28 12:29:41 -07:00
|
|
|
|
system runs all pending syncs, jobs, and alarms, and lets apps access the
|
2015-09-11 19:00:08 -07:00
|
|
|
|
network.
|
|
|
|
|
</p>
|
|
|
|
|
|
|
|
|
|
<div style="margin:1em 0em;">
|
|
|
|
|
<img src="{@docRoot}images/training/doze.png">
|
|
|
|
|
<p class="img-caption" style="text-align:center;">
|
2015-09-28 12:29:41 -07:00
|
|
|
|
<strong>Figure 1.</strong> Doze provides a recurring maintenance window for apps to use the
|
|
|
|
|
network and handle pending activities.
|
2015-09-11 19:00:08 -07:00
|
|
|
|
</p>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<p>
|
|
|
|
|
At the conclusion of each maintenance window, the system again enters Doze,
|
|
|
|
|
suspending network access and deferring jobs, syncs, and alarms. Over time,
|
|
|
|
|
the system schedules maintenance windows less and less frequently, helping to
|
2015-09-28 12:29:41 -07:00
|
|
|
|
reduce battery consumption in cases of longer-term inactivity when the device is not
|
2015-09-11 19:00:08 -07:00
|
|
|
|
connected to a charger.
|
|
|
|
|
</p>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<p>
|
|
|
|
|
As soon as the user wakes the device by moving it, turning on the screen, or
|
|
|
|
|
connecting a charger, the system exits Doze and all apps return to normal
|
|
|
|
|
activity.
|
|
|
|
|
</p>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<h3 id="restrictions">Doze restrictions</h3>
|
|
|
|
|
|
|
|
|
|
<p>
|
|
|
|
|
The following restrictions apply to your apps while in Doze:
|
|
|
|
|
</p>
|
|
|
|
|
|
|
|
|
|
<ul>
|
2015-09-28 12:29:41 -07:00
|
|
|
|
<li>Network access is suspended.
|
2015-09-11 19:00:08 -07:00
|
|
|
|
</li>
|
|
|
|
|
|
2015-09-28 12:29:41 -07:00
|
|
|
|
<li>The system ignores <a href="{@docRoot}reference/android/os/PowerManager.WakeLock.html">
|
|
|
|
|
wake locks</a>.
|
2015-09-11 19:00:08 -07:00
|
|
|
|
</li>
|
|
|
|
|
|
|
|
|
|
<li>Standard {@link android.app.AlarmManager} alarms (including {@link
|
|
|
|
|
android.app.AlarmManager#setExact(int, long, android.app.PendingIntent) setExact()} and
|
|
|
|
|
{@link android.app.AlarmManager#setWindow(int, long, long,
|
2015-09-28 10:52:18 -07:00
|
|
|
|
android.app.PendingIntent) setWindow()}) are deferred to the next maintenance window.
|
2015-09-11 19:00:08 -07:00
|
|
|
|
</li>
|
|
|
|
|
|
|
|
|
|
<li style="list-style: none; display: inline">
|
|
|
|
|
<ul>
|
2015-09-28 12:29:41 -07:00
|
|
|
|
<li>If you need to set alarms that fire while in Doze, use {@link
|
2015-09-11 19:00:08 -07:00
|
|
|
|
android.app.AlarmManager#setAndAllowWhileIdle(int,long,android.app.PendingIntent)
|
|
|
|
|
setAndAllowWhileIdle()}
|
|
|
|
|
or {@link android.app.AlarmManager#setExactAndAllowWhileIdle(int, long,
|
|
|
|
|
android.app.PendingIntent) setExactAndAllowWhileIdle()}.
|
|
|
|
|
</li>
|
|
|
|
|
|
|
|
|
|
<li>Alarms set with {@link
|
|
|
|
|
android.app.AlarmManager#setAlarmClock(android.app.AlarmManager.AlarmClockInfo,
|
|
|
|
|
android.app.PendingIntent) setAlarmClock()} continue to fire normally — the system
|
|
|
|
|
exits Doze shortly before those alarms fire.
|
|
|
|
|
</li>
|
|
|
|
|
</ul>
|
|
|
|
|
</li>
|
|
|
|
|
|
|
|
|
|
<li>The system does not perform Wi-Fi scans.
|
|
|
|
|
</li>
|
|
|
|
|
|
2015-09-28 12:29:41 -07:00
|
|
|
|
<li>The system does not allow
|
|
|
|
|
<a href="{@docRoot}reference/android/content/AbstractThreadedSyncAdapter.html">sync adapters</a>
|
|
|
|
|
to run.
|
2015-09-11 19:00:08 -07:00
|
|
|
|
</li>
|
|
|
|
|
|
|
|
|
|
<li>The system does not allow {@link android.app.job.JobScheduler} to run.
|
|
|
|
|
</li>
|
|
|
|
|
</ul>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<div id="qv-wrapper">
|
|
|
|
|
<div id="qv" style="width:300px">
|
|
|
|
|
<h2>Doze checklist</h2>
|
|
|
|
|
<ol>
|
|
|
|
|
<ul>
|
|
|
|
|
<li>If possible, use GCM for <a href=
|
|
|
|
|
"https://developers.google.com/cloud-messaging/downstream">downstream
|
2015-09-28 12:29:41 -07:00
|
|
|
|
messaging</a>.
|
2015-09-11 19:00:08 -07:00
|
|
|
|
</li>
|
|
|
|
|
|
|
|
|
|
<li>If your users must see a notification right away, make sure to use a <a href=
|
|
|
|
|
"https://developers.google.com/cloud-messaging/concept-options#setting-the-priority-of-a-message">GCM
|
|
|
|
|
high priority message</a>.
|
|
|
|
|
</li>
|
|
|
|
|
|
2015-09-28 10:52:18 -07:00
|
|
|
|
<li>Provide sufficient information within the initial <a href=
|
2015-09-11 19:00:08 -07:00
|
|
|
|
"https://developers.google.com/cloud-messaging/concept-options#payload">message
|
2015-09-28 10:52:18 -07:00
|
|
|
|
payload</a>, so subsequent network access is unnecessary.
|
2015-09-11 19:00:08 -07:00
|
|
|
|
</li>
|
|
|
|
|
|
|
|
|
|
<li>Set critical alarms with {@link
|
|
|
|
|
android.app.AlarmManager#setAndAllowWhileIdle(int, long,
|
|
|
|
|
android.app.PendingIntent) setAndAllowWhileIdle()} and {@link
|
|
|
|
|
android.app.AlarmManager#setExactAndAllowWhileIdle(int, long,
|
|
|
|
|
android.app.PendingIntent) setExactAndAllowWhileIdle()}.
|
|
|
|
|
</li>
|
|
|
|
|
|
|
|
|
|
<li>
|
2015-09-28 12:29:41 -07:00
|
|
|
|
<a href="#testing_doze">Test your app in Doze.</a>
|
2015-09-11 19:00:08 -07:00
|
|
|
|
</li>
|
|
|
|
|
</ul>
|
|
|
|
|
</ol>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
|
2015-09-28 12:29:41 -07:00
|
|
|
|
<h3 id="assessing_your_app">Adapting your app to Doze</h3>
|
2015-09-11 19:00:08 -07:00
|
|
|
|
|
|
|
|
|
<p>
|
|
|
|
|
Doze can affect apps differently, depending on the capabilities they offer
|
2015-09-28 12:29:41 -07:00
|
|
|
|
and the services they use. Many apps function normally across Doze
|
|
|
|
|
cycles without modification. In some cases, you must optimize the way
|
2015-09-11 19:00:08 -07:00
|
|
|
|
that your app manages network, alarms, jobs, and syncs. Apps should be able
|
|
|
|
|
to efficiently manage activities during each maintenance window.
|
|
|
|
|
</p>
|
|
|
|
|
<p>
|
2015-09-28 12:29:41 -07:00
|
|
|
|
Doze is particularly likely to affect activities that {@link android.app.AlarmManager} alarms and
|
|
|
|
|
timers manage, because alarms in Android 5.1 (API level 22) or lower do not fire when the system
|
|
|
|
|
is in Doze.
|
2015-09-11 19:00:08 -07:00
|
|
|
|
</p>
|
|
|
|
|
|
|
|
|
|
<p>
|
2015-09-28 12:29:41 -07:00
|
|
|
|
To help with scheduling alarms, Android 6.0 (API level 23) introduces two new
|
|
|
|
|
{@link android.app.AlarmManager} methods: {@link
|
2015-09-11 19:00:08 -07:00
|
|
|
|
android.app.AlarmManager#setAndAllowWhileIdle(int, long,
|
|
|
|
|
android.app.PendingIntent) setAndAllowWhileIdle()} and {@link
|
|
|
|
|
android.app.AlarmManager#setExactAndAllowWhileIdle(int, long,
|
|
|
|
|
android.app.PendingIntent) setExactAndAllowWhileIdle()}. With these methods,
|
2015-09-28 12:29:41 -07:00
|
|
|
|
you can set alarms that will fire even if the device is in Doze.
|
2015-09-11 19:00:08 -07:00
|
|
|
|
</p>
|
|
|
|
|
|
2015-09-29 09:43:46 -07:00
|
|
|
|
<p class="note"><strong>Note:</strong> Neither
|
|
|
|
|
{@link
|
2015-09-11 19:00:08 -07:00
|
|
|
|
android.app.AlarmManager#setAndAllowWhileIdle(int, long,
|
2015-09-29 09:43:46 -07:00
|
|
|
|
android.app.PendingIntent) setAndAllowWhileIdle()} nor {@link
|
|
|
|
|
android.app.AlarmManager#setExactAndAllowWhileIdle(int, long,
|
|
|
|
|
android.app.PendingIntent) setExactAndAllowWhileIdle()} can fire alarms more than once per 15
|
|
|
|
|
minutes per app.</p>
|
2015-09-11 19:00:08 -07:00
|
|
|
|
|
|
|
|
|
<p>
|
|
|
|
|
The Doze restriction on network access is also likely to affect your app,
|
2015-09-28 10:52:18 -07:00
|
|
|
|
especially if the app relies on real-time messages such as tickles or
|
2015-09-11 19:00:08 -07:00
|
|
|
|
notifications. If your app requires a persistent connection to the network to
|
2015-09-30 12:26:12 -07:00
|
|
|
|
receive messages, you should use <a href="#using_gcm">Google Cloud Messaging (GCM)</a>
|
2015-09-28 12:29:41 -07:00
|
|
|
|
if possible.
|
2015-09-11 19:00:08 -07:00
|
|
|
|
</p>
|
|
|
|
|
|
|
|
|
|
<p>
|
2015-09-28 12:29:41 -07:00
|
|
|
|
To confirm that your app behaves as expected with Doze, you can use adb commands to force the
|
|
|
|
|
system to enter and exit Doze and observe your app’s behavior. For details, see
|
|
|
|
|
<a href="#testing_doze_and_app_standby">Testing with Doze and App Standby</a>.
|
2015-09-11 19:00:08 -07:00
|
|
|
|
</p>
|
|
|
|
|
|
2015-09-28 10:52:18 -07:00
|
|
|
|
<h2 id="understand_app_standby">Understanding App Standby</h2>
|
|
|
|
|
|
|
|
|
|
<p>
|
|
|
|
|
App Standby allows the system to determine that an app is idle when the user
|
|
|
|
|
is not actively using it. The system makes this determination when the user
|
|
|
|
|
does not touch the app for a certain period of time and none of the following
|
|
|
|
|
conditions applies:
|
|
|
|
|
</p>
|
|
|
|
|
|
|
|
|
|
<ul>
|
|
|
|
|
<li>The user explicitly launches the app.
|
|
|
|
|
</li>
|
|
|
|
|
|
|
|
|
|
<li>The app has a process currently in the foreground (either as an activity
|
|
|
|
|
or foreground service, or in use by another activity or foreground service).
|
|
|
|
|
</li>
|
|
|
|
|
|
|
|
|
|
<li>The app generates a notification that users see on the lock screen or in
|
|
|
|
|
the notification tray.
|
|
|
|
|
</li>
|
|
|
|
|
</ul>
|
2015-09-11 19:00:08 -07:00
|
|
|
|
|
|
|
|
|
<p>
|
2015-09-28 10:52:18 -07:00
|
|
|
|
When the user plugs the device into a power supply, the system releases apps
|
|
|
|
|
from the standby state, allowing them to freely access the network and to
|
|
|
|
|
execute any pending jobs and syncs. If the device is idle for long periods of
|
|
|
|
|
time, the system allows idle apps network access around once a day.
|
|
|
|
|
</p>
|
|
|
|
|
|
2015-09-28 12:29:41 -07:00
|
|
|
|
<h2 id="using_gcm">Using GCM to Interact with Your App While the Device is Idle</h2>
|
|
|
|
|
|
|
|
|
|
<p>
|
|
|
|
|
<a href="https://developers.google.com/cloud-messaging/">Google Cloud
|
|
|
|
|
Messaging (GCM)</a> is a cloud-to-device service that lets you support
|
|
|
|
|
real-time downstream messaging between backend services and apps on
|
|
|
|
|
Android devices. GCM provides a single, persistent connection to the cloud; all apps needing
|
|
|
|
|
real-time messaging can share this connection. This shared
|
|
|
|
|
connection significantly optimizes battery consumption by making it unnecessary for
|
|
|
|
|
multiple apps to maintain their own, separate persistent connections, which can
|
|
|
|
|
deplete the battery rapidly. For this reason, if your app requires messaging integration with a
|
|
|
|
|
backend service, we strongly recommend that you <strong>use GCM if possible</strong>, rather than
|
|
|
|
|
maintaining your own persistent network connection.
|
|
|
|
|
</p>
|
|
|
|
|
|
|
|
|
|
<p>
|
|
|
|
|
GCM is optimized to work with Doze and App Standby idle modes by means of
|
|
|
|
|
<a href="https://developers.google.com/cloud-messaging/concept-options#setting-the-priority-of-a-message">
|
|
|
|
|
high-priority GCM messages</a>. GCM high-priority messages let you reliably wake your app to
|
|
|
|
|
access the network, even if the user’s device is in Doze or the app is in App Standby mode.
|
|
|
|
|
In Doze or App Standby mode, the system delivers the message and gives the
|
|
|
|
|
app temporary access to network services and partial wakelocks, then returns the device or app
|
|
|
|
|
to idle state.
|
|
|
|
|
</p>
|
|
|
|
|
|
|
|
|
|
<p>
|
|
|
|
|
High-priority GCM messages do not otherwise affect Doze mode, and they don’t
|
2015-09-30 12:26:12 -07:00
|
|
|
|
affect the state of any other app. This means that your app can use them to communicate
|
2015-09-28 12:29:41 -07:00
|
|
|
|
efficiently while minimizing battery impacts across the system and device.
|
|
|
|
|
</p>
|
|
|
|
|
|
|
|
|
|
<p>
|
|
|
|
|
As a general best practice, if your app requires downstream messaging, it
|
|
|
|
|
should use GCM. If your server and client already uses GCM, make sure that your service uses
|
|
|
|
|
high-priority messages for critical messages, since this will reliably
|
|
|
|
|
wake apps even when the device is in Doze.
|
|
|
|
|
</p>
|
|
|
|
|
|
|
|
|
|
<h2 id="support_for_other_use_cases">Support for Other Use Cases</h2>
|
2015-09-28 10:52:18 -07:00
|
|
|
|
|
|
|
|
|
<p>
|
2015-09-28 12:29:41 -07:00
|
|
|
|
Almost all apps should be able to support Doze by managing network connectivity, alarms,
|
|
|
|
|
jobs, and syncs properly, and using GCM high-priority messages. For a narrow
|
|
|
|
|
set of use cases, this might not be sufficient. For such cases, the system
|
|
|
|
|
provides a configurable whitelist of apps that are <strong>partially
|
|
|
|
|
exempt</strong> from Doze and App Standby optimizations.
|
2015-09-11 19:00:08 -07:00
|
|
|
|
</p>
|
|
|
|
|
|
|
|
|
|
<p>
|
2015-09-28 12:29:41 -07:00
|
|
|
|
An app that is whitelisted can use the network and hold
|
|
|
|
|
|
|
|
|
|
<a href="{@docRoot}reference/android/os/PowerManager.html#PARTIAL_WAKE_LOCK">
|
|
|
|
|
partial wake locks</a> during Doze and
|
2015-09-11 19:00:08 -07:00
|
|
|
|
App Standby. However, <strong>other restrictions still apply</strong> to the
|
|
|
|
|
whitelisted app, just as they do to other apps. For example, the whitelisted
|
2015-09-28 12:29:41 -07:00
|
|
|
|
app’s jobs and syncs are deferred, and its regular {@link android.app.AlarmManager} alarms do not
|
|
|
|
|
fire. An app can check whether it is currently on the exemption whitelist by
|
|
|
|
|
calling {@link
|
|
|
|
|
android.os.PowerManager#isIgnoringBatteryOptimizations(java.lang.String)
|
|
|
|
|
isIgnoringBatteryOptimizations()}.
|
|
|
|
|
</li>
|
2015-09-11 19:00:08 -07:00
|
|
|
|
</p>
|
|
|
|
|
|
|
|
|
|
<p>
|
|
|
|
|
Users can manually configure the whitelist in <strong>Settings > Battery
|
|
|
|
|
> Battery Optimization.</strong> Alternatively, the system provides
|
2015-09-28 10:52:18 -07:00
|
|
|
|
ways for apps to ask users to whitelist them.
|
2015-09-28 12:29:41 -07:00
|
|
|
|
|
2015-09-11 19:00:08 -07:00
|
|
|
|
</p>
|
|
|
|
|
|
|
|
|
|
<ul>
|
2015-09-28 12:29:41 -07:00
|
|
|
|
<li>An app can fire the {@link
|
2015-09-11 19:00:08 -07:00
|
|
|
|
android.provider.Settings#ACTION_IGNORE_BATTERY_OPTIMIZATION_SETTINGS} intent
|
2015-09-28 12:29:41 -07:00
|
|
|
|
to take the user directly to the <strong>Battery Optimization</strong>, where they can
|
|
|
|
|
add the app.
|
2015-09-11 19:00:08 -07:00
|
|
|
|
</li>
|
|
|
|
|
|
2015-09-28 12:29:41 -07:00
|
|
|
|
<li>An app holding the {@link
|
2015-09-11 19:00:08 -07:00
|
|
|
|
android.Manifest.permission#REQUEST_IGNORE_BATTERY_OPTIMIZATIONS} permission
|
|
|
|
|
can trigger a system dialog to let the user add the app to the whitelist
|
|
|
|
|
directly, without going to settings. The app fires a {@link
|
|
|
|
|
android.provider.Settings#ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS} Intent
|
2015-09-28 12:29:41 -07:00
|
|
|
|
to trigger the dialog.
|
2015-09-11 19:00:08 -07:00
|
|
|
|
</li>
|
|
|
|
|
|
|
|
|
|
<li>The user can manually remove apps from the whitelist as needed.
|
|
|
|
|
</li>
|
|
|
|
|
</ul>
|
|
|
|
|
|
2015-09-28 12:29:41 -07:00
|
|
|
|
<p>Before asking the user to add your app to the whitelist, make sure the app
|
|
|
|
|
|
|
|
|
|
matches the <a href="#whitelisting-cases">acceptable use cases</a> for whitelisting.</p>
|
2015-09-11 19:00:08 -07:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<p class="caution">
|
|
|
|
|
<strong>Note:</strong> Google Play policies prohibit apps from requesting
|
|
|
|
|
direct exemption from Power Management features in Android 6.0+ (Doze and App
|
|
|
|
|
Standby) unless the core function of the app is adversely affected.
|
|
|
|
|
</p>
|
|
|
|
|
|
2015-09-28 10:52:18 -07:00
|
|
|
|
<h2 id="testing_doze_and_app_standby">Testing with Doze and App Standby</h2>
|
2015-09-11 19:00:08 -07:00
|
|
|
|
|
|
|
|
|
<p>
|
2015-09-28 10:52:18 -07:00
|
|
|
|
To ensure a great experience for your users, you should test your app fully
|
2015-09-28 12:29:41 -07:00
|
|
|
|
in Doze and App Standby.
|
2015-09-11 19:00:08 -07:00
|
|
|
|
</p>
|
|
|
|
|
|
2015-09-28 12:29:41 -07:00
|
|
|
|
<h3 id="testing_doze">Testing your app with Doze</h4>
|
2015-09-11 19:00:08 -07:00
|
|
|
|
|
2015-09-28 12:29:41 -07:00
|
|
|
|
<p>You can test Doze mode by following these steps:</p>
|
2015-09-11 19:00:08 -07:00
|
|
|
|
<ol>
|
|
|
|
|
<li>Configure a hardware device or virtual device with an Android 6.0 (API
|
|
|
|
|
level 23) or higher system image.
|
|
|
|
|
</li>
|
|
|
|
|
|
|
|
|
|
<li>Connect the device to your development machine and install your app.
|
|
|
|
|
</li>
|
|
|
|
|
|
|
|
|
|
<li>Run your app and leave it active.
|
|
|
|
|
</li>
|
|
|
|
|
|
2015-09-30 12:26:12 -07:00
|
|
|
|
<li>Shut off the device screen. (The app remains active.)
|
|
|
|
|
</li>
|
|
|
|
|
|
2015-09-11 19:00:08 -07:00
|
|
|
|
<li>Force the system to cycle through Doze modes by running the following
|
|
|
|
|
commands:
|
|
|
|
|
|
2015-09-30 12:26:12 -07:00
|
|
|
|
<pre class="no-pretty-print">
|
|
|
|
|
$ adb shell dumpsys battery unplug
|
|
|
|
|
$ adb shell dumpsys deviceidle step</pre>
|
|
|
|
|
|
|
|
|
|
<p>You may need to run the second command more than once. Repeat it until
|
|
|
|
|
the device state changes to idle.</p>
|
2015-09-11 19:00:08 -07:00
|
|
|
|
</li>
|
|
|
|
|
|
|
|
|
|
<li> Observe the behavior of your app after you reactivate the device. Make
|
|
|
|
|
sure the app recovers gracefully when the device exits Doze.
|
|
|
|
|
</li>
|
|
|
|
|
</ol>
|
|
|
|
|
|
2015-09-28 12:29:41 -07:00
|
|
|
|
<h3 id="testing_your_app_with_app_standby">Testing your app with App Standby</h4>
|
2015-09-11 19:00:08 -07:00
|
|
|
|
|
|
|
|
|
<p>To test the App Standby mode with your app:</p>
|
|
|
|
|
|
|
|
|
|
<ol>
|
|
|
|
|
<li> Configure a hardware device or virtual device with an Android 6.0 (API level
|
|
|
|
|
23) or higher system image.
|
|
|
|
|
</li>
|
|
|
|
|
<li> Connect the device to your development machine and install your app.</li>
|
|
|
|
|
<li> Run your app and leave it active.</li>
|
|
|
|
|
<li> Force the app into App Standby mode by running the following commands:
|
|
|
|
|
|
|
|
|
|
<pre class="no-pretty-print">$ adb shell dumpsys battery unplug
|
|
|
|
|
$ adb shell am set-inactive <packageName> true</pre>
|
|
|
|
|
<li>Simulate waking your app using the following commands:
|
|
|
|
|
|
|
|
|
|
<pre class="no-pretty-print">$ adb shell am set-inactive <packageName> false
|
|
|
|
|
$ adb shell am get-inactive <packageName></pre>
|
|
|
|
|
</li>
|
|
|
|
|
<li>Observe the behavior of your app after waking it. Make sure the app recovers gracefully
|
|
|
|
|
from standby mode. In particular, you should check if your app's Notifications and background
|
|
|
|
|
jobs continue to function as expected.
|
|
|
|
|
</li>
|
|
|
|
|
</ol>
|
|
|
|
|
|
|
|
|
|
|
2015-09-28 12:29:41 -07:00
|
|
|
|
<h2 id="whitelisting-cases">Example Use Cases for Whitelisting</h2>
|
2015-09-11 19:00:08 -07:00
|
|
|
|
|
2015-09-28 12:29:41 -07:00
|
|
|
|
<p>The table below highlights the acceptable use cases for requesting or being on
|
|
|
|
|
the Battery Optimizations exceptions whitelist. In general, your app should not be on the
|
2015-10-16 10:08:55 -07:00
|
|
|
|
whitelist unless Doze or App Standby break the core function of the app or there is a
|
2015-09-28 12:29:41 -07:00
|
|
|
|
technical reason why your app cannot use GCM high-priority messages.</p>
|
2015-09-11 19:00:08 -07:00
|
|
|
|
|
2015-09-28 12:29:41 -07:00
|
|
|
|
<p>For more information, see <a href="#support_for_other_use_cases">Support for Other Use Cases
|
|
|
|
|
</a>.</p>
|
2015-09-11 19:00:08 -07:00
|
|
|
|
|
|
|
|
|
<table>
|
|
|
|
|
<tr>
|
|
|
|
|
<th>Type</td>
|
|
|
|
|
<th>Use-case</td>
|
|
|
|
|
<th>Can use GCM?</td>
|
|
|
|
|
<th>Whitelisting acceptable?</td>
|
|
|
|
|
<th>Notes</td>
|
|
|
|
|
</tr>
|
|
|
|
|
|
|
|
|
|
<tr>
|
|
|
|
|
<td rowspan="2">Instant messaging, chat, or calling app. </td>
|
2015-09-28 10:52:18 -07:00
|
|
|
|
<td rowspan="3">Requires delivery of real-time messages to users while device is in Doze or app
|
2015-09-11 19:00:08 -07:00
|
|
|
|
is in App Standby.</td>
|
|
|
|
|
<td>Yes, using GCM</td>
|
|
|
|
|
<td rowspan="2" style="color:red">Not Acceptable</td>
|
2015-09-28 10:52:18 -07:00
|
|
|
|
<td rowspan="2">Should use GCM high-priority messages to wake the app and access the network.</td>
|
2015-09-11 19:00:08 -07:00
|
|
|
|
</tr>
|
|
|
|
|
|
|
|
|
|
<tr>
|
2015-09-28 10:52:18 -07:00
|
|
|
|
<td>Yes, but is not using GCM high-priority messages.</td>
|
2015-09-11 19:00:08 -07:00
|
|
|
|
</tr>
|
|
|
|
|
|
|
|
|
|
<tr>
|
|
|
|
|
<td rowspan="1">Instant messaging, chat, or calling app;
|
|
|
|
|
enterprise VOIP apps</td>
|
|
|
|
|
<td>No, can not use GCM because of technical dependency on another messaging
|
2015-10-16 10:08:55 -07:00
|
|
|
|
service or Doze and App Standby break the core function of the app.</td>
|
2015-09-11 19:00:08 -07:00
|
|
|
|
<td style="color:green">Acceptable</td>
|
|
|
|
|
<td></td>
|
|
|
|
|
</tr>
|
|
|
|
|
|
|
|
|
|
</table>
|
|
|
|
|
|
|
|
|
|
|