Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can my Android app communicate with a native daemon?

So, I have a custom Android application running as System (built as a system app in my ROM). And Ive written a native daemon that works fine too and runs as root. However, I was wondering how the two can communicate? I know I can have the native daemon create a network socket and have the App connect to it, but using a local socket for IPC seems even better, but I am struggling to find example code for it.

I figured I could create the socket like as described here but I have no idea how to communicate with it in Java.

Any help would be much appreciated.

Also, at first I wrote a native library and used JNI to communicate with it from Java, but quickly realized that it obviously runs in the context of the app, so it cant be run as root, which is a requirement I have, and something the native daemon can do fine. Is using sockets the best alternative here or would Binder work too?

Thanks a ton!

like image 926
ardevd Avatar asked Sep 19 '13 15:09

ardevd


1 Answers

The solution here was to look at AOSP and see how installd communicates with the Installer java app. In init.rc you see how the named local socket is created and in installd.c you see how native code communicates with the socket. In Installer.java you see how its done from Java land.

Dont think Binder would be the right way to go for my particular use case.

like image 79
ardevd Avatar answered Oct 23 '22 14:10

ardevd