Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How does doze mode affect background/foreground services, with/without partial/full wakelocks?

This is a simple question, seeing that there is a huge post about this on G+ (here), and lack of information on official docs (here ):

What happens to the app's services when the device goes to "doze" mode?

What does it do to background/foreground services (bound/unbound, started/not-started), with/without partial/full wakelocks?

What would you do, for example, in order to create a service that plays an audio stream while the device's screen is turned off? What if the audio stream is not from a local file, but from the network?

Seeing that there was a claim by Google developer:

Apps that have been running foreground services (with the associated notification) are not restricted by doze.

-yet a lot of discussion after that, claiming this is not entirely true, I think it's quite confusing to know what special background-operations apps should do.

like image 501
android developer Avatar asked Jun 16 '16 20:06

android developer


People also ask

Can foreground service be killed by Android?

The Android system stops a service only when memory is low and it must recover system resources for the activity that has user focus. If the service is bound to an activity that has user focus, it's less likely to be killed; if the service is declared to run in the foreground, it's rarely killed.

What is the doze mode?

Doze. Doze extends battery life by deferring app background CPU and network activity when a device is unused for long periods. Idle devices in Doze periodically enter a maintenance window, during which apps can complete pending work (syncs, jobs, etc.).

How does doze work?

Doze Mode focuses on improving battery life on Android by cutting down on background network activity when the device is not in use. Background updates by apps are instead grouped into controlled maintenance windows, allowing for data freshness when the user comes back to their phone and exits Doze Mode.

What is the difference between foreground and background services on Android?

A Background Service is a service that runs only when the app is running so it'll get terminated when the app is terminated. A Foreground Service is a service that stays alive even when the app is terminated. And a Bound Service is a service that runs only if the component it is bound to is still active.


1 Answers

Processes which have a current running foreground service are supposed to be unaffected by Doze. Bound/unbound, started/not-started, and wakelocks do not affect this whitelisting process.

However, there is an issue on Android M devices where foreground services are not properly whitelisted when the foreground service is the in the same process as the top activity and improperly dozed.

The fix is available on AOSP and will be included in builds of Android N. It would be up to OEMs to integrate that patch into any Android M builds they produce.

like image 121
ianhanniballake Avatar answered Oct 31 '22 19:10

ianhanniballake