android ctl.start
通过控制ctl.start和ctl.stop这两个属性,可以控制init.rc文件中定义的各种service。
如启动与关闭adb服务
frameworks\base\services\core\java\com\android\server\adb\AdbService.java
private void startAdbd() {
SystemProperties.set(CTL_START, ADBD);
}
private void stopAdbd() {
if (!mIsAdbUsbEnabled && !mIsAdbWifiEnabled) {
SystemProperties.set(CTL_STOP, ADBD);
}
}
如android开机动画的启动和停止同样也是
SystemProperties.set("ctl.start", "bootanim");
java
SystemProperties.set("ctl.start", "service_name");
shell :
setprop ctl.start service_name
setprop ctl.stop service_name
JNI:
property_set("ctl.start", service_name);
property_set("ctl.stop", service_name);
我们经常使用adb shell stop ,start命令来重启framework,我们来看下其代码
是在system/core/toolbox下面,原理很简单就是利用ctl属性来控制进程。
start.c #include #include #include #include int start_main(int argc, char *argv[]) { if(argc > 1) { property_set("ctl.start", argv[1]); } else { /* defaults to starting the common services stopped by stop.c */ property_set("ctl.start", "netd"); property_set("ctl.start", "surfaceflinger"); property_set("ctl.start", "zygote"); property_set("ctl.start", "zygote_secondary"); } return 0; } stop.c #include #include #include int stop_main(int argc, char *argv[]) { if(argc > 1) { property_set("ctl.stop", argv[1]); } else{ /* defaults to stopping the common services */ property_set("ctl.stop", "zygote_secondary"); property_set("ctl.stop", "zygote"); property_set("ctl.stop", "surfaceflinger"); property_set("ctl.stop", "netd"); } return 0; }
版权声明:如无特殊标注,文章均为本站原创,转载时请以链接形式注明文章出处。
评论