Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add a system service to the Android Framework

I want to add my own framework code that runs in the Android "system_server" (handles all the system level services). My service loads a JNI library that talks to a driver I have added to the kernel. The service is designed to allow an app to register a listener with it to get updates from the driver. I found a pretty good blog post (http://www.androidenea.com/2009/12/adding-system-server-to-android.html) that explains how to add a system service, but I cannot get it completely working.

First of all, the post mentions that an "appropriate" Android.mk file should be used to write the client/test application, but does not give an example of this. When I try to build it, I get build errors saying it can't find the service I have added. Could someone give an example of what this might look like?

Also, I'd like to implement this in the vendor directory (or device directory in froyo) rather than in the Android open source code. The blog post mentions that the proper place for this is the vendor directory, but does not give an example of what this should look like. Anyone know?

ANY additional information on implementing your own system service in Android would be helpful. Again my specific workflow is:

Android App -> System Service -> JNI (native) library -> Device Driver

like image 818
ashughes Avatar asked Jul 12 '10 22:07

ashughes


2 Answers

Texas instruments has provided a nice example:

http://processors.wiki.ti.com/index.php/Android-Adding_SystemService

Additionally, the CyanogenMod SystemServer.java has also code for dynamically loading system services as defined in the array "config_vendorServices" in config.xml (see core/res/res/values/config.xml), which I believe can be overwritten in the vendor or device directories using the overlays. This is a CyanogenMod-specific addition, added in this commit:

https://github.com/CyanogenMod/android_frameworks_base/commit/88fff90131f54d45dc496c45127ac1d16ad257df

like image 130
Pekka Nikander Avatar answered Oct 22 '22 20:10

Pekka Nikander


There are multiply way (or 6 ways, just to be explicit) of adding a system service.

What you tried (Android App -> System Service -> JNI (native) library -> Device Driver) is one of them. You might want check out this article for an in-depth explanation regarding system service implementation patterns.

enter image description here

like image 3
pierrotlefou Avatar answered Oct 22 '22 19:10

pierrotlefou