Android Property System

/system/build.prop 是一个属性文件,在Android系统中.prop文件很重要,记录了系统的设置和改变,类似於/etc中的文件。这个文件是如何生成的呢?build/tools/buildinfo.sh 脚本就是专门用于生成build.prop文件build/core/Makefile中使用build/tools/buildinfo.sh 脚本生成build.prop文件,并把系统默认的system.prop以及定制的system.prop中的设定追加到build.prop文件中后面还有一些设备相关的配置追加到build.prop


Everyproperty has a name and value. Both name and value are text strings.Property is heavily used in Android to record system setting orexchange information between processes. The property is globallyvisible in the whole system. Every process can get/set a property.

Onsystem initialization, Android will allocates a block of shared memoryfor storing the properties. This is done in “init” daemon whose sourcecode is at: device/system/init. The “init” daemon will start a PropertyService. The Property Service is running in the process of “init”daemon. Every client that wants to SET property needs to connect to theProperty Service and send message to Property Service. Property Servicewill update/create the property in shared memory. Any client that wantsto GET property can read the property from the shared memory directly.This promotes the read performance.

Theclient application can invoke the API function exposed from libcutilsto GET/SET a property. The source code of libcutils locates at: device/libs/cutils.

The API function is:

int property_get(const char *key, char *value, const char *default_value);

int property_set(const char *key, const char *value);

Thelibcutils is in turn calling the __system_property_xxx function in libcto get a property from the shared memory. The source code of libc isat: device/system/bionic.

TheProperty Service is also in turn calling the __system_property_initfunction in libc to initiate the shared memory for properties. Whenstarting the Property Service will load the default properties frombelow files:

/default.prop

/system/build.prop

/system/default.prop

/data/local.prop

Theproperties are loaded in the above order. Later loaded properties willoverride the previous values. After those properties are loaded, thelast loaded is the persistent properties which is persisted in/data/property.

Special Properties

Ifa property’s name begins with “ro.”, then this property is treated as aread-only property. Once set, the value of the property can’t bechanged.

If a property’s name begins with “persist.”, then when setting this property, the value will be written to /data/property, too.

Ifa property’s name begins with “net.”, when when setting this property,the “net.change” property will be set automatically to contain the nameof the last updated property. (It’s tricky. The netresolve module usesthis property to track if there is any change on the net.* properties.)

Theproperty “ctrl.start” and “ctrl.stop” is used to start and stop aservice. Every service must be defined in /init.rc. On system startup,the init daemon will parse the init.rc and start the Property Service.Once received a request to set the property of “ctrl.start”, theProperty Service will use the property value as the service name tofind the service and then start the service. The service startingresult is then put to the property “init.svc.<service name>”. Theclient application can poll the value of that property to determine theresult.

Android toolbox

The Android toolbox provides two applets: setprop and getprop to get and set properties. The usage is:

getprop <property name>

setprop <property name> <property value> 

Java

The java application can use the System.getProperty() and System.setProperty() function to Get and Set the property.

Action

Bydefault the set property will only cause "init" daemon to write toshared memory, it won't execute any script or binary. But you can addyour actions to correspond to property change in init.rc. For example,in the default init.rc, you can find.

# adbd on at boot in emulator
on property:ro.kernel.qemu=1
    start adbd

on property:persist.service.adb.enable=1
    start adbd

on property:persist.service.adb.enable=0
    stop adbd

So if you set persist.service.adb.enable to 1, the "init" daemon knows it has actions to do, then it will start adbd service.


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值