The reason you may want to do this is that you are creating a device with some new features that you want to be available for some specific applications shipped with the device. It is also a good exercise to run through in order to understand the frameworks used by Android. This is the preferred way to do this and to quote Dianne Hackborn on the official mailing lists (found here):
If you are going to allow the user to keep Market on their phone, and are adding any new features, please do this the official way: include your own shared library with the features that applications use, rather than having magic hacks in the framework for them.
The example for this reside in the vendor/samples folder in the Android open source project. There are several components in this example:
- The PlatformLibraryExample code itself which is a sample native library implementing some example platform functionality.
- A java library that interfaces the platform library through JNI and exposes the API:s to applications.
- A sample client application that uses this functionality
It is even possible to create an SDK add-on in order to have the added features easily available when developing applications. We will talk more about SDK add-ons in a later post.
To understand what is in this sample start out by reading the readme file in vendor/sample/frameworks/PlatformLibrary. This file describes the above components in more detail and will also tell you what you need to know in order to test the framework additions on a system.
If you are like us and like to try things out on the platform and work directly with some features that are not currently available in Android it is a good thing to follow these examples. It removes the need for making changes directly in the framework when exploring the possibilities of the platform.