简体   繁体   中英

Starting an Android init.rc service from an Activity

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".

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>");

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM