状态服务器相关:
在init.c 的main函数中启动状态服务器。
property_set_fd = start_property_service();
状态读取函数:
Property_service.c (system\core\init)
const char* property_get(const char *name)
Properties.c (system\core\libcutils)
int property_get(const char *key, char *value, const char *default_value)
状态设置函数:
Property_service.c (system\core\init)
int property_set(const char *name, const char *value)
Properties.c (system\core\libcutils)
int property_set(const char *key, const char *value)
在终端模式下我们可以通过执行命令 setprop <key> <value>
setprop 工具源代码所在文件: Setprop.c (system\core\toolbox)
Getprop.c (system\core\toolbox): property_get(argv[1], value, default_value);
Property_service.c (system\core\init)
中定义的状态读取和设置函数仅供init进程调用,
handle_property_set_fd(property_set_fd);
property_set() //Property_service.c (system\core\init)
property_changed(name, value) //Init.c (system\core\init)
queue_property_triggers(name, value)
drain_action_queue()
只要属性一改变就会被触发,然后执行相应的命令:
例如:
在init.rc 文件中有
on property:persist.service.adb.enable=1
start adbd
on property:persist.service.adb.enable=0
stop adbd
所以如果在终端下输入:
setprop property:persist.service.adb.enable 1或者0
那么将会开启或者关闭adbd 程序。
本文深入解析了Android系统中属性服务的工作机制,包括如何在init.c的main函数中启动状态服务器,以及如何通过终端命令进行属性读取和设置。详细介绍了属性服务在系统初始化、组件管理和配置调整中的作用,特别是如何通过属性服务来控制后台服务的启动与停止,如adbd程序。此外,还探讨了属性服务与init.rc文件的交互,以及如何在不同场景下利用属性服务进行系统配置的灵活调整。
757

被折叠的 条评论
为什么被折叠?



