3

We have a podcast player app, which works great on most phones, but some Samsung users are reporting that the stream stops playing when the screen turns off. We are using foreground services and notifications for playback with ExoPlayer.

After some investigation, it turns out that if you disable 'Put app to sleep' for our app in Settings -> Device Care -> Battery, it will work as expected.

Is it possible to automatically disable put app to sleep for our app? I have read about the Samsung Knox API ApplicationPolicy.addPackageToBatteryOptimizationWhiteList(), but that requires requesting device admin rights for our app, which would be scary for the users.

Daniel Zolnai
  • 16,487
  • 7
  • 59
  • 71
  • when you [test your app with doze](https://developer.android.com/training/monitoring-device-state/doze-standby#testing_doze) on different phones beside samsung you get the same results ? – Ben Shmuel Aug 16 '19 at 18:47
  • How do you mean? Doze results are OK, but Samsung puts the app on a separate put app to sleep list. No issues found on non-Samsung phones. – Daniel Zolnai Aug 17 '19 at 15:38
  • a good resource about the issue here https://dontkillmyapp.com looks like Samsung is following a nasty process to save battery power, this is giving us a huge headache, which is unfair and simply unjust for us a developers trying to get our services running as it should. I would understand when they kill a heavy app, but I don't understand how dare they kill and app with 0% battery usage without even a user consent, and with no way even to ask the user if they are ok to keep the app in the background to not, this is shameful – Hasson Nov 16 '19 at 21:57
  • Did you try the `addPackageToBatteryOptimizationWhiteList` method? It seems it works only with a KNOX_APP_MGMT permission which has a protection level of signature. Unfortunately it seems that normal apps cannot use it. – Blehi Feb 12 '20 at 16:05
  • No, I did not use it. – Daniel Zolnai Feb 13 '20 at 09:13
  • Did you find a solution? I am facing the same issue. – IgorGanapolsky Apr 16 '20 at 13:03
  • No we did not this API in the end. – Daniel Zolnai Apr 17 '20 at 07:57

1 Answers1

-1

From the documentation

An app holding the 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 ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS Intent to trigger the dialog.

Before asking the user to add your app to the whitelist, make sure the app matches the acceptable use cases for whitelisting.

By the way, shouldn't the 'Put app to sleep' be off by default for all apps? At least that's the case on my S8.

Community
  • 1
  • 1
Isak
  • 116
  • 9
  • 1
    This applies to the battery optimizations of the system, but Samsung has made another optimization app, which works differently. Put app to sleep might be off by default, but it says that if your app consumes power in the background it will be automatically put on. – Daniel Zolnai Aug 16 '19 at 07:45
  • Sorry, I realized I should've put my answer as a comment. I'm not sure how Samsung's battery optimizations work. – Isak Aug 16 '19 at 08:25