Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make native Unix/Linux daemon work on Android?

I'm searching the Internet for a several days with no result. So, I decided to ask the community to shed some light on this.

I have an application written in C++ that I compiled for Android OS. The app can also be run as daemon (by specifying --daemon option). When it's run as the regular executable it works fine, but when I try it to start as daemon it disappears after the fork() is performed I see it in logcat.

The questions are: 1. Whether it is possible to adapt Unix/Linux daemon code to work on Android? If yes how? 2. How to start it on boot? I suppose by init.rc, but how to edit it persistently? 3. If no. Is there any android specific approach to solve the task?

Please feel free to post links you think can be useful.

like image 907
4xy Avatar asked Nov 01 '22 09:11

4xy


1 Answers

Yes, this can be done on the platform level. Under the hood, Android is almost yet another Linux system, and it runs Linux-style services. You can pick up an existing service in AOSP, like SurfaceFlinger, and add your functionality to it. Or you can develop your own service from ground up. In any case, you start with building your own AOSP fork.

Here is a nice tutorial: https://devarea.com/aosp-adding-a-native-daemon

like image 193
Alex Cohn Avatar answered Nov 09 '22 09:11

Alex Cohn