A remote root service using native Android Binder IPC.
+
+ Pro tip: while developing an app with RootServices, modify the run/debug configuration and check
+ the "Always install with package manager" option if testing on Android 11+, or else the code
+ changes will not be reflected after Android Studio's deployment.
+
+ This class is almost a complete recreation of a bound service running in a root process.
+ Instead of using the original Context.bindService(...)
methods to start and bind
+ to a service, use the provided static methods RootService.bind(...)
.
+ Because the service will not run in the same process as your application, you have to use either
+ Messenger
or AIDL to define the IPC interface for communication. Please read the
+ official documentations for more details.
+
+ Even though a RootService
is a Context
of the app package, since we are running
+ in a root environment and the ContextImpl is not constructed in the "normal" way, the
+ functionality of this context is much more limited compared to normal non-root cases. Be aware
+ of this and do not assume all context methods will work, many will result in Exceptions.
+
+ Daemon mode:
+ By default, the root service will be destroyed when no components are bound to it
+ (including when the non-root app process is terminated). However, if you'd like to have
+ the root service run independently of the app's lifecycle (aka "Daemon Mode"), override the
+ method onUnbind(Intent)
and return true
. Subsequent bindings will call
+ the onRebind(Intent)
method.
+
+ All RootServices of an app will run in the same root process, as root processes are launched
+ per package. The root service process will terminate in the following conditions:
+
+ - When the application is updated/deleted
+ - When all services are destroyed (after
onDestroy()
is called)
+ - Non-daemon services will be automatically destroyed when all clients are
+ unbounded or terminated
+ - Daemon services will only be destroyed when the client called
stop(Intent)
+ or the root service called stopSelf()
+
+ The library will NOT attempt to automatically restart and bind to services under any circumstance.
+