2

I have an application we use for research purposes that collects data from sensors in background. I use a service that registers some broadcast receivers, with startForeground() attached to a notification and also I start the service in onStartCommand() using START_STICKY. Everything works fine on Marshmallow but when I try it on a OnePlus 3 with 7.1.1 after a while the application just disappears from the running applications.. everything gets killed by the system. Sometimes I get a system notification saying: "Attention, An application running in background is using a lot...". If I click this notification it opens the Settings window that says "Manage high power usage apps", my app is there but the option "Auto close high power usage apps" is disabled. Moreover, I already set the app as "do not optimize" in the system settings under Battery. Actually if I disable the logging from those sensors that consume more battery such as Location everything works fine, i can run the application for an unlimited amount of time. Any suggestion on how to solve?

Please remember that this is an application for research purposes, it is not published, so do not suggest to not do this because it can affect the user experience, this is not the case. Thank you!

phcaze
  • 1,597
  • 5
  • 25
  • 54

1 Answers1

2

Apparently it is an OxygenOS "feature" as reported here. My stacktrace is attached, I have to change smartphone..

... 05-19 21:03:12.434 it.unitn.disi.witmee.sensorlog I/System.out: SERVICE: true 05-19 21:03:27.689 it.unitn.disi.witmee.sensorlog I/art: Background partial concurrent mark sweep GC freed 265550(7MB) AllocSpace objects, 0(0B) LOS objects, 39% free, 14MB/23MB, paused 1.357ms total 106.126ms 05-19 21:03:43.649 it.unitn.disi.witmee.sensorlog I/art: Background sticky concurrent mark sweep GC freed 243975(7MB) AllocSpace objects, 0(0B) LOS objects, 30% free, 16MB/23MB, paused 1.610ms total 108.734ms 05-19 21:03:55.995 it.unitn.disi.witmee.sensorlog I/art: Background partial concurrent mark sweep GC freed 298424(8MB) AllocSpace objects, 0(0B) LOS objects, 39% free, 14MB/24MB, paused 1.716ms total 126.141ms 05-19 21:04:02.051 ? I/ActivityManager: [BgDetect]detect excessive cpu on process it.unitn.disi.witmee.sensorlog(pid : 27858) level 0 usage 29 05-19 21:04:02.088 ? I/ActivityManager: [BgDetect]force stop it.unitn.disi.witmee.sensorlog (uid 10245) level 0 05-19 21:04:02.089 ? I/ActivityManager: Force stopping it.unitn.disi.witmee.sensorlog appid=10245 user=0: from pid 1336 05-19 21:04:02.089 ? I/ActivityManager: Killing 27858:it.unitn.disi.witmee.sensorlog/u0a245 (adj 200): stop it.unitn.disi.witmee.sensorlog 05-19 21:04:02.089 ? W/ActivityManager: Scheduling restart of crashed service it.unitn.disi.witmee.sensorlog/.services.LoggingMonitoringService in 1000ms 05-19 21:04:02.091 ? I/ActivityManager: Force stopping service ServiceRecord{9156a9a u0 it.unitn.disi.witmee.sensorlog/.services.LoggingMonitoringService}

phcaze
  • 1,597
  • 5
  • 25
  • 54