Adding a system service to the build

214 views
Skip to first unread message

Andre Zuban

unread,
Apr 30, 2016, 2:01:22 PM4/30/16
to Android Building
Hello!

I know how to add another Android system service to the platform build
when I do the final builds, but in a situation when some partners do
the actual builds and produce the final FW I need to give them the
service in a prebuilt form (I guess as a jar file) to be included into
their platform build because I cannot give them the sources (for
intellectual property reasons). How can I do that? I guess this should
be easily achievable.

Thanks,
Andre

Dave Smith

unread,
May 2, 2016, 10:25:45 AM5/2/16
to Android Building

Andre -

How did you plan to integrate the system service at runtime? Are you injecting the code into system_server, or are you packaging the result into a separate application process (a la the pattern used by the Bluetooth and NFC services)? If the latter, the issue should be fairly straightforward as you can just provide the APK and the final build can include it using BUILD_PREBUILT. This is generally my preferred approach to adding system services.

If the former, that may be more difficult as there isn't a clean separation between the code you are adding and the framework code that you change. In this case, at least some of the code to register the service may be need to be in the sources, while the service implementation itself could be a JAR listed as a dependency in the makefile of framework core.

Cheers,
Dave Smith, PE
@devunwired

--
--
You received this message because you are subscribed to the "Android Building" mailing list.
To post to this group, send email to android-...@googlegroups.com
To unsubscribe from this group, send email to
android-buildi...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-building?hl=en


You received this message because you are subscribed to the Google Groups "Android Building" group.
To unsubscribe from this group and stop receiving emails from it, send an email to android-buildi...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Andre Zuban

unread,
May 3, 2016, 11:25:04 AM5/3/16
to Android Building
It's the former. It's OK to include some registration code in the source our partner uses to do the build. Do you know any details on how to include the JAR in their build?

Andre

Dave Smith

unread,
May 4, 2016, 10:15:04 AM5/4/16
to Android Building
Well, presumably that means you'll have some code like this in SystemServer.java somewhere, in order for the service to be created and registered inside system_server:

MyCustomService newService = new MyCustomService();
ServiceManager.addService("custom_service", newService);


In order for the framework build to compile, you will need to provide the code for that new class in a library somewhere. You could create a prebuilt module for the JAR file with a separate Android.mk like so:

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

LOCAL_PREBUILT_STATIC_JAVA_LIBRARIES := libprivate:private-service-lib.jar

include $(BUILD_MULTI_PREBUILT)


…then take that library name and add it to frameworks/base/Android.mk somewhere:

LOCAL_STATIC_JAVA_LIBRARIES := libprivate

You might have to tweak some, but that's the general idea.

Cheers,
Dave Smith, PE
@devunwired
Reply all
Reply to author
Forward
0 new messages