I am trying to execute a daemon on boot of my Nexus 5. This is a daemon built from source in c++
. But whenever I build AOSP and flash the images on my Nexus 5 device, the daemon is not running in the background. I added this code to my init.rc file: (which should make it run in the background on boot)
setenforce 0
service my_daemon /system/bin/my_daemon
class main # Also tried: class core (but it didn't make a difference)
user root
group root
setenforce 1
The reason I use setenfonce is because of SELinux on Android 5.0 and above. The problem is that on boot, the daemon is not running on boot. I don't have any clue as to why. Any suggestions?
I got the same issue with nexus 9. I added code to device/htc/flounder/init.flounder.rc but doesnt work.
service pollingclient /system/bin/sh logwrapper
class late_start
user root
group root
oneshot
on property:dev.bootcomplete=1
start pollingclient
My quick fix is added code to start my daemon in system/core/adb/adb_auth_client.c after fdevent_add(&t->auth_fde, FDE_READ);
kill_if_exist_service("mydaemon");
system("sleep 5; mydaemon");
It works but its some kind of "quick fix". I am still investigating right solution.
update: I disable selinux by edit ./arch/arm64/configs/flounder_defconfig set CONFIG_SECURITY_SELINUX=n then recompile kernel and recompile boot.img. Wow, it works!