17

Checking my app's behavior on M Preview device, it seems that its foreground (with active notification) service playing music is not affected by Doze mode. But reading docs it seems that foreground services are exempt only from AppStandby.

What is the real rule?

GPack
  • 2,494
  • 4
  • 19
  • 50
  • 1
    Wouldn't this be an expected behaviour? Doze mode should not close active services since the devices being actively being used. – Aegis Oct 08 '15 at 14:15
  • 1
    Yes, but reading docs it seems that foreground services are preserved only in App Standby Mode. – GPack Oct 08 '15 at 14:17
  • Are you sure you are in doze mode? You need to let the phone still for one hour in horizontal plane (a table for example). According to the docs, doze should be enabled and the system should ignore your wakelock. – greywolf82 Oct 08 '15 at 17:19
  • I tested it by `adb shell dumpsys deviceidle step` stepping until I got IDLE status of device: it was in Doze, surely. – GPack Oct 08 '15 at 17:31
  • In addition if your is whitelisted you can use partial wakelock so you have to be sure you are not ignoring optimizations – greywolf82 Oct 09 '15 at 05:24
  • checked: it is not whitelisted. – GPack Oct 11 '15 at 16:20
  • 1
    Can you please show some code where you create foreground service, because in my case does not work, even if foreground service is runnign in seperate process. I tested using "adb shell dumpsys deviceidle force-idle" – Domen Jakofčič Jan 16 '17 at 20:48

2 Answers2

33

In this post's comments on Sep 17 Dianne Hackborn writes:

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

So yes, your findings seem to be the intended behavior.

Tim
  • 41,901
  • 18
  • 127
  • 145
sec_aw
  • 1,594
  • 1
  • 15
  • 26
  • 9
    late reply, but I am testing a foreground service. In that service I implemented a Logwriter, every few seconds, I write information to a textfile. If app standby/doze mode comes up, nothing is written until I wake up the device. So, is the app in app standby or does doze mode not allow to write to external file? – Opiatefuchs May 26 '16 at 07:14
  • 1
    Similar issue as opiatefuchs had. Any resolutions yet ? – Napolean Jul 26 '16 at 11:05
  • 4
    Your issues might be related to a bug where foreground services may still be affected by doze mode, when not running in a separate process. See https://code.google.com/p/android/issues/detail?id=193802 – sec_aw Sep 28 '16 at 13:00
0

Attention, Foreground service can prevent your app never into app standby, but not doze.

Here use adb cmd to test

$ adb shell dumpsys battery unplug    
$ adb shell am set-inactive <packageName> true
Shrayas
  • 6,784
  • 11
  • 37
  • 54
zzz zzz
  • 89
  • 1
  • 5