To start with, this post is for developers who work on android platform and not for application developers. The default version of android open source platform has system services coded in both Java (services hosted by system_server) and C,C++ (media services hosted by mediaserver).
Recently, i came across requests to have Java based customized services hosted in their own process (and definitely not by system_server). Personally, i preferred all customized services to be in their own process, that way any service specific exception is just going to bring down the respective process and wouldn't trigger a framework reboot and offer a better user experience, opportunity for graceful handling.
Besides, i don't like bloatware services being added to system_server just because its open source. These bloatware services when buggy (memory references, exceptions) has a direct negative impact on the android framework and is a big negative PR for android platform as such. Having said that, there are reasons to add custom services to android framework and it would only make more sense to have these changes reviewed by the Android Community and possibly be reused by various OEMs, Chip makers.
Anyways, now to the real world, I just managed to create a custom java service hosted in its own process, with few cons. I just added the source code of the service to existing services directory,
frameworks/base/services/java/com/android/server/NumberGeneratorService.java
frameworks/base/core/java/android/os/INumberGeneratorService.aidl
frameworks/base/Android.mk
The aidl is just to expose APIs and Android.mk is just to generate code from the aidl. Android's build system adds this new class to framework.jar.
Next, the instance of the service isn't created by system_server. NumberGeneratorService.java has its own public static void main(), which creates the service and registers it with servicemanager. The process is not forked by zygote instead is forked by init, similar to native services being forked by init and it needed the changes to init.rc,
service number /system/bin/app_process /system/framework com.android.server.NumberGeneratorService
class main
user system
group system
onrestart restart number
2 comments:
the method u have illustrated here is not working
Ok, what exactly is not working?
Post a Comment