How to add a system service to the Android Framework

4,058 views
Skip to first unread message

ashughes

unread,
Jul 12, 2010, 6:26:54 PM7/12/10
to android-platform
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

purera...@163.com

unread,
Jul 13, 2010, 2:59:44 AM7/13/10
to android-platform
fisrt, define your own service.
second, add service start in framework.( aobut in SystemServer.java)

ashughes

unread,
Jul 13, 2010, 9:26:57 AM7/13/10
to android-platform
Can you give an example of how you would add a system service in the
vendor (or device) directory? I'm unclear as to the structure of the
files (where they need to be) and what should be contained in the
Android.mk files to make it work.

There is hardly any information on the web (that I can find) that
helps with Android Platform development. I finally found the PDK
(http://pdk.android.com), which has been a big help, but it doesn't
look like it's maintained. I would love to write tutorials about how
to do platform development for others to use, but I need to figure out
how to do things myself!

Thanks,
Andrew

On Jul 13, 1:59 am, "purerain2...@163.com" <purerain2...@163.com>
wrote:

FrankG

unread,
Jul 13, 2010, 10:08:09 AM7/13/10
to android-platform
Hello Andrew,

I would suggest that you start with a service which is started by a
system intent
as first example

Means you create your own BrodcastReceiver , which will called via
BOOT_COMPLETED
and this receiver then start via the local Binder Pattern you Service
class ..

<receiver android:enabled="true"
android:name="AndrewSystemstartReceiver">
<intent-filter>
<action
android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>

I know that this approach is not so popular in this forum, but
nevertheless use them as a starting point for yourself.

And the structure of the files i.e. a vendor extension directory is
not different to a normal app.

Examples for the Android.mk can you find i.e. for the different Apps
of the plattform , i.e. the Settings-App or
others under app/mydroid/packages/apps

The contents can maybe the following one :

LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)

LOCAL_SRC_FILES := $(call all-subdir-java-files) \
src/<yourpackage>/IAndrewInterface.aidl \


LOCAL_PACKAGE_NAME := AndrewService

include $(BUILD_PACKAGE)

include $(call all-makefiles-under,$(LOCAL_PATH))

Good luck !

Frank
> > > Android App -> System Service -> JNI (native) library -> Device Driver- Zitierten Text ausblenden -
>
> - Zitierten Text anzeigen -

ashughes

unread,
Jul 13, 2010, 10:43:36 AM7/13/10
to android-platform
Thanks for the information Frank, I will definitely try that.

Is this really the "right" way to do this? If I were a company making
a device and adding a new piece of hardware, wouldn't I want to add a
more integrated system level service that communicates with the driver
of the new hardware? Rather than a service that runs after the system
boot process completes? From the little I've found on the topic, you
can either add something to the system_server or to the HAL framework,
neither of which I have figured out how to do properly.

I will try the way you suggested right now, but I'd still like to know
how to do it the more system integrated ways. If for some reason you
think _this_ is still the proper way to do it, let me know.

Again, my communication workflow is: Android App -> System Service ->
JNI (native) library -> Device Driver

Thanks,
Andrew

FrankG

unread,
Jul 14, 2010, 11:03:22 AM7/14/10
to android-platform
Hi Andrew,

In my experiences you will find different solutions on one and the
same
device.

Many things, which are more hardware related are started via entries
in init.rc.

So you can change your communication workflow in this way too :
App-> AIDL->native APP->Device Driver

The problem for this is the usage of AIDL in your native APP.
I think, from a vendor point of view this is the better way.

Good luck !

Frank
> > > - Zitierten Text anzeigen -- Zitierten Text ausblenden -

ashughes

unread,
Jul 15, 2010, 6:22:07 PM7/15/10
to android-platform
Okay, I successfully implemented an Application level Service that
will boot on startup and handle my communication with the driver.

Now I'm back to trying to do it on a system service level. I have
created the actual service that I want to run in the system_server by
extending my IAndrewInterface.Stub like the other system_server
services do. I have also added the service using
ServiceManager.addService in SystemServer.java. When I compile, my
build obviously fails because it has no idea what AndrewService is. I
have added an import statement based on the package name, but I still
need to add something to the makefiles to tell it to look in the
vendor directory for my service.

I have tried adding my aidl files to the list of aidls in frameworks/
base/Android.mk, but that gives me build errors as well.

How do I tell the SystemSever that my service is in the vendor
directory?

Thanks,
Andrew
Reply all
Reply to author
Forward
0 new messages