Android – Starting an Android init.rc service from an Activity

androidandroid-activityinit

Before I start, this is meant for our own android based device and not for a phone nor for deployment elsewhere.

We have a service in init.rc that is a postgresql database server. This launches on startup and always runs in the background for the system. There's the possibility that it might close however and we would like to have a way to stop and start this service from the android side of the system.

Is there a way to send an init start command from an android Activity? From a root shell, this would be the equivalent of running "start servicename" and "stop servicename".

Best Answer

To start a service which is declared in the init.rc file, i think you must change the "ctl.start" system property with following commands :

In c file :

property_set("ctl.start", "<service_name>");

In java :

SystemProperties.set("ctl.start", "<service_name>");

This implies that your activity has system permissions (in the manifest) :

android:sharedUserId="android.uid.system"

and is signed by your system key (or put platform in the Android.mk)

As you can guess, to stop the service use following commands :

property_set("ctl.stop", "<service_name>");

or

SystemProperties.set("ctl.stop", "<service_name>");