简体   繁体   English

从Activity启动Android init.rc服务

[英]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. 在我开始之前,这适用于我们自己的基于Android的设备,不适用于手机,也不适用于其他地方。

We have a service in init.rc that is a postgresql database server. 我们在init.rc中有一个服务,它是一个postgresql数据库服务器。 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. 但它有可能会关闭,我们希望有一种方法可以从系统的android端停止并启动此服务。

Is there a way to send an init start command from an android Activity? 有没有办法从Android Activity发送init启动命令? From a root shell, this would be the equivalent of running "start servicename" and "stop servicename". 从root shell开始,这相当于运行“start servicename”和“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 : 要启动在init.rc文件中声明的服务,我认为您必须使用以下命令更改“ctl.start”系统属性:

In c file : 在c文件中:

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

In java : 在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) 并由您的系统密钥签署(或在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>");

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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