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

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,

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.

oupson,
@oupson@programming.dev avatar

Have you tried Shizuku or magisk’s libsu ?

They both allow you to run services as root (or adb shell user with suzuku).

salvador,

Do they allow run put and run my service from /system ?

oupson,
@oupson@programming.dev avatar

I don’t think so. However, you can write a magisk module that inject content into /system.

  • All
  • Subscribed
  • Moderated
  • Favorites
  • android@lemmy.world
  • anitta
  • DreamBathrooms
  • osvaldo12
  • mdbf
  • everett
  • magazineikmin
  • khanakhh
  • Youngstown
  • rosin
  • slotface
  • modclub
  • kavyap
  • tacticalgear
  • ngwrru68w68
  • JUstTest
  • thenastyranch
  • cisconetworking
  • Durango
  • ethstaker
  • InstantRegret
  • Leos
  • provamag3
  • GTA5RPClips
  • tester
  • cubers
  • megavids
  • normalnudes
  • lostlight
  • All magazines