赞
踩
系统属性,用于存储系统的一下属性信息,在开机的时候在init进程中完成初始化和启动。
system\core\init\init.cpp
- int SecondStageMain(int argc, char** argv) {
- ...
- property_init();//属性初始化
- ...
- property_load_boot_defaults(load_debug_prop);//加载开机默认属性配置
- StartPropertyService(&epoll);//启动属性服务
- ...
- }
- getprop |grep 节点名
- setprop 节点名 节点的值
- SystemProperties.get("key");
- SystemProperties.set("key", value);
- int property_get(const char* key, char* value, const char* default_value);
- int property_set(const char *key, const char *value);
ro即read only这类属性通常是系统默认属性,在系统编译或初始化时设置的。
设置persist开头的属性,断电后仍能保存,值写入data/property/persistent_properties。
- setprop ctl.start xxx //启动某服务
- setprop ctl.stop xxx //关闭某服务
- setprop ctl.restart xxx //重启某服务
sys.powerctl属性可控制设备重启关机
- setprop sys.powerctl shutdown //设备关机
- setprop sys.powerctl reboot //设备重启
设置其他格式开头的属性,断电后不能保存
从前面的介绍中我们知道系统开机时会load *.prop属性配置文件中的属性,因此开机后就有了默认属性。这里我们可以在device/xxx/xxx/system.prop 中添加自定义属性
注意:这里添加的属性前缀必须是在system/sepolicy/private/property_contexts中被定义过的,否则无效;
make android后在out/target/product/xxx/system/build.prop 或out/target/product/xxx/vendor/build.prop可找到添加的属性persist.hello.world,则说明基本添加成功,烧录img验证即可。
- frameworks\base\core\java\android\os\SystemProperties.java
- frameworks\base\core\jni\android_os_SystemProperties.cpp
- system\core\base\properties.cpp
- system\core\init\main.cpp
- system\core\init\init.cpp
- system\core\init\property_service.cpp
- system\core\property_service\libpropertyinfoparser\property_info_parser.cpp
- bionic\libc\include\sys\_system_properties.h
- bionic\libc\include\sys\system_properties.h
- bionic\libc\bionic\system_property_set.cpp
- bionic\libc\bionic\system_property_api.cpp
- bionic\libc\system_properties\contexts_serialized.cpp
- bionic\libc\system_properties\system_properties.cpp
- bionic\libc\system_properties\prop_area.cpp
如果需要拦截setprop命令 需要在 system_property_set.cpp中进行处理
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。