Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Add our own System Service in Android Framework?

I am new to android and i have been analyzing the android source code to understand how the System services are implemented. My Question is am I able to create my own System Service and add it to the framework so that all the applications should be Able to access my service. Any comments/Code snippets would be helpful.

Thanks to the Replier in advance.

like image 552
Sakthi.droid Avatar asked Jul 11 '11 12:07

Sakthi.droid


People also ask

What is Android system service?

Android services are system component which allows performing a longer-running operation while not interacting with the user. Just like Activities , Service runs on Main Thread and has a life cycle but unlike Activity , Services do not have a UI.

How do I declare a service in manifest android?

You declare a service in your app's Manifest, by adding a <service> element as a child of your <application> element. There's a list of attributes that you can use to control a service's behavior, but as a minimum you'll need to provide the service's name (android:name) and a description (android:description).

How do I start a service in android?

Starting a service You can start a service from an activity or other application component by passing an Intent to startService() or startForegroundService() . The Android system calls the service's onStartCommand() method and passes it the Intent , which specifies which service to start.


2 Answers

For a system service, more is needed. Essentially, at least for Android 2.3, the SystemServer.java must be extended so that the new service gets instantiated when the system_server starts.

Texas Instruments has kindly provided a nice example:

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

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. However, we haven't tried to use that ourselves, and I don't know if that is CyanogenMod specific or common to 2.3.[45].

like image 66
Pekka Nikander Avatar answered Sep 22 '22 20:09

Pekka Nikander


You can add your own service but there is no way to add system service, unless you can modify the framework source code.

System services are running in system_sever with system privilege, which allow those service can access system resource that normal application service can't.

This article explain in detail how the system service are implemented in Android. enter image description here

like image 25
pierrotlefou Avatar answered Sep 21 '22 20:09

pierrotlefou