0

I have seen a few very old posts, like How to launch a native server application (ELF) on a rooted Android at/after boot? with this answer: https://stackoverflow.com/a/9920463/ and this questions Android daemon process which both touch on my issue but not really give an answer what I need to do. Also since there are only a few questions on this topic either this is so obviously simple that there is no need to ask a question or I'm not searching with the correct terminology

I have a natively built application which I run as root on an Android(AOSP) development board.

Starting this program from the console works fine but I would like it to start automatically in the background on boot-up.

  • What would be a simple way of starting my process in the background at startup?
  • What is be the currently recommended way of doing it?
Simson
  • 3,373
  • 2
  • 24
  • 38
  • 1
    The [initrc](https://web.archive.org/web/20100513023326/http://www.androidenea.com/2009/08/init-process-and-initrc.html) approach is still valid and fully supported. – Alex Cohn Nov 05 '19 at 04:42

1 Answers1

2

This is how I solved this problem. My tool builds in the aosp tree.

  • added a file mytool.rc this file is pushed to /etc/init
on boot
start myservice
service myservice /bin/mytool
   user root
   seclabel u:r:su:s0
   disabled
  • added rc-file to Android.bp
cc_binary {
    name: "mytool",
    init_rc: ["mytool.rc"],
    defaults: ["mytool_defaults"],
    srcs: [
        "mytool.cpp",
    ],
}
  • Temporary set SELinux to permissive mode by running shell command setenforce 0
  • service is started with shell command start mytool
Simson
  • 3,373
  • 2
  • 24
  • 38