According to this thread after Android Oreo, Google introduced some background limitations so it's not possible to run a Service always in background without displaying a user notification.
Is it possible to achieve this with root privileges?
EDIT: I see that people are voting to close my question because apparently it looks like it's too broad, but I am running LineageOS, and I would like to put my app to run as system service if possible, and I think that this would be feasible without modifying the source code. For example when installing the OS, I could flash GApps, but it was optional, and they seem to have the functionality that I'm talking about. I am also not expecting you to do all my research for me, and I am willing to accept the answer that points me in the right direction.
There's indeed an undocumented shell command, which can be used to white-list packages, by adding them to the global location_background_throttle_package_whitelist
(I haven't tested it):
settings put global location_background_throttle_package_whitelist "package1,package2,package3"
^ this is for location
services, but there might be further background_throttle
settings available:
settings list global | grep background_throttle
Source: XDA Developers.
Also in the source code I've only found these settings:
Settings.Global.LOCATION_BACKGROUND_THROTTLE_PACKAGE_WHITELIST
Settings.Global.LOCATION_BACKGROUND_THROTTLE_PROXIMITY_ALERT_INTERVAL_MS
Settings.Global.LOCATION_BACKGROUND_THROTTLE_INTERVAL_MS
The documentation is clear about the fact that certain services are being added into a temporary white-list. To find out what actually white-lists these services, one would have to dig further. These background service restriction is actually being described in Context.java ...while the methods annotated with @UnsupportedAppUsage
are the ones which only the system uses.
The Firebase WorkManager is still the best option available - or the underlying JobIntentService, which will still run as a regular background service < Android O
. Flashing Android N
or Lineage OS 14.1
would be a certain workaround, which is barely being considered.
The assumption that root
permissions would provide super-powers might be a misconception. Permitting unfettered location access is still quite limited and even Google's own services are only temporarily white-listed. The only services excluded from these background execution restrictions would be Linux system services, written in C++
(which are running outside of the JVM) - while this is something very else than Android background services, written in Java
(which are running inside the JVM and all extend the same restricted Service
class).