Pradeep Phatak
May 19, 2019
11:41 pm

App with foreground service is being put to sleep on Samsung Android 9.0 device

On Samsung S9 Android 9.0 device, we observe that our app that runs with foreground service and notification is being put to sleep. 

It automatically gets added under App Power Management Settings -> Sleeping Apps.

When that happens, app is no longer running. We confirmed this with adb shell ps command.

It is reproducible by setting the Sleep delay in Settings to 1 day and putting any of the App activity in background.

Is it expected that App with foreground service/notification will be put to sleep automatically?

Is there a way to programatically whitelist against app sleep? Or, can App register a callback to wake itself up after sometime. 

This issue was not seen on Android 8.0 devices.

Mikayla N.Samsung SEAP Moderator
May 23, 2019
4:51 pm

Hi Pradeep,

Starting in Android 9, Google has made the OS more strict on battery life. If the device senses that an app is not currently on the screen and it is using a lot of batttery in the background, the device will put the app to sleep. To counteract this, you can use the Knox API addPackageToBatteryOptimizationWhiteList() to prevent the device from putting your app to sleep.

Best regards,

Mikayla

Pradeep Phatak
May 23, 2019
5:02 pm

Thank you Mikayla. 

Can you confirm that this is applicable to application with a foreground service notification in Android 9.0 -

"If the device senses that an app is not currently on the screen and it is using a lot of batttery in the background, the device will put the app to sleep."

As per Android documentation, app with foreground service will be in active bucket and system will not put a restriction on it.

https://developer.android.com/about/versions/pie/power

Could you point to any documentation that says app will be put to sleep?

 

For the Knox API that you have pointed to whitelist against Google's Doze mode, app standby and power saving mode, is it available to Knox MDM/EMM app or a normal app can call it to whitelist itself?

 

Thanks,

Pradeep