Android的属性系统贯穿了从linux系统到Android应用的全过程,在每个层次都有相应的API进行调用。 当各层之间需要进行基本的数据传递的时候,可以使用该系统进行传递,非常方面。其各层的类或者头文件名称均为SystemProperties。 对于显示设置相关的内容,均应该采用该属性系统进行通信,以保证系统可以在启动时就进行相关的配置。
Android的属性系统具有生命期的区分:当次启动有效和持久化方式。对于该功能的区分是通过属性的前缀来实现的:
以“persist.”开头为持久化数据
其他未非持久化数据,当次启动有效
对于所有支持的前缀,Android中有明确的规定,规定的代码在:
$(ANDROID_ROOT)/system/core/init/property_service.c中:
{ "net.rmnet0.", AID_RADIO, 0 },
{ "net.gprs.", AID_RADIO, 0 },
{ "net.ppp", AID_RADIO, 0 },
{ "net.qmi", AID_RADIO, 0 },
{ "net.lte", AID_RADIO, 0 },
{ "net.cdma", AID_RADIO, 0 },
{ "ril.", AID_RADIO, 0 },
{ "gsm.", AID_RADIO, 0 },
{ "persist.radio", AID_RADIO, 0 },
{ "net.dns", AID_RADIO, 0 },
{ "net.dns", AID_DHCP, 0 },
{ "sys.usb.config", AID_RADIO, 0 },
{ "net.", AID_SYSTEM, 0 },
{ "dev.", AID_SYSTEM, 0 },
{ "runtime.", AID_SYSTEM, 0 },
{ "hw.", AID_SYSTEM, 0 },
{ "sys.", AID_SYSTEM, 0 },
{ "service.", AID_SYSTEM, 0 },
{ "wlan.", AID_SYSTEM, 0 },
{ "dhcp.", AID_SYSTEM, 0 },
{ "dhcp.", AID_DHCP, 0 },
{ "debug.", AID_SHELL, 0 },
{ "log.", AID_SHELL, 0 },
{ "service.adb.root", AID_SHELL, 0 },
{ "service.adb.tcp.port", AID_SHELL, 0 },
{ "persist.sys.", AID_SYSTEM, 0 },
{ "persist.service.", AID_SYSTEM, 0 },
{ "persist.security.", AID_SYSTEM, 0 },
通过AID_SYSTEM、AID_SHELL、AID_RADIO、AID_DHCP来区分属性可以被访问的进程 通过前缀net来区分是否为网络属性,如果是网络属性,还会触发通知机制:
if (strncmp("net.", name, strlen("net.")) == 0) {
if (strcmp("net.change", name) == 0) {
return 0;
}
/*
* The 'net.change' property is a special property used track when any
* 'net.*' property name is updated. It is _ONLY_ updated here. Its value
* contains the last updated 'net.*' property.
*/
property_set("net.change", name);
}
Android的属性系统
最新推荐文章于 2022-05-06 17:20:24 发布