How to make my Android service run forever? On a rooted phone - eviltoast

I have a rooted Android 10. And I’ve written a service (off the class Service) which I want to run under too, in background. A service uses a microphone and location. It’s written in Kotlin.

I’ve not found any information of how to run a service on a rooted device under root. I’ve found some, about running some commands in a service (code) itself under root, though, but it may be only a part of what I need.

How to do it?

Essentially, I want my service to run forever, with elevated preveligies, get itself restarted if it fails, gets killed by Android.


Also, I’ve tried to copy it into /system and /system/init directories, but I haven’t been able to, due to “read-only file system”. Nor have I been able to remount it to make it writteable. I’ve managed to make the / writteable, but it didn’t allow me to copy my service in /system nonetheless.

  • Pantherina@feddit.de
    link
    fedilink
    English
    arrow-up
    3
    ·
    9 months ago

    Just disable battery optimization and disable energy saver. Android apps can start if they want, this is only prevented in “battery restricted”. Also an app can listen for the Boot event and start directly.

    No need for Root.