Android Property System)

Source: Internet
Author: User
Android Property System)

Because I don't know much about the property system of Android, I translated this article "android Property System".

Each attribute has a name and value, which are in string format. Attributes are widely used in Android systems to record system settings or information exchange between processes. Properties are globally visible throughout the system. Each process can get/set attributes.
During system initialization, Android allocates a shared memory area to store the attributes. These are completed by the "init" daemon, and the source code is located at: device/system/init. The "init" daemon starts an Attribute Service. The property service runs in the "init" daemon. To set properties for each client, you must connect to the property service and then send information to it. Attribute Service will modify and create attributes in the shared memory area. Any client can directly read the property information from the shared memory. This improves read performance.
Client Applications can call the API functions in libcutils to get/set attribute information. The source code of libcutils is located at: device/libs/cutils. The API functions are:
Int property_get (const char * Key, char * value, const char * default_value );
Int property_set (const char * Key, const char * value );
Libcutils calls the _ system_property_xxx function in libc to obtain the attributes in the shared memory. The source code of libc is located at: device/system/bionic.
The property service calls the _ system_property_init function in libc to initialize the shared memory of the property system. When the property service is started, the default properties are loaded from the following files:
/Default. Prop
/System/build. Prop
/System/Default. Prop
/Data/local. Prop
The attribute will be loaded in the above sequence. The loaded attributes overwrite the original values. After these attributes are loaded, the last loaded attributes will be kept in/data/property.

Special attributes
If the attribute name starts with "Ro.", this attribute is regarded as a read-only attribute. Once set, the attribute value cannot be changed.
If the attribute name starts with "Persist.", when this attribute is set, its value will also be written to/data/property.
If the attribute name starts with "net.", when this attribute is set, the "net. Change" attribute is automatically set to add it to the last modified attribute name. (This is clever. The netresolve module uses this attribute to track any changes to the net. * attribute .)
The "Ctrl. Start" and "Ctrl. Stop" attributes are used to start and stop services. Each service must be defined in/init. Rc. When the system is started, the init. RC and the init daemon will parse the init. RC and start the Attribute Service. Once you receive a request to set the "Ctrl. Start" attribute, the property service uses this attribute value as the service name to locate the service and start the service. The startup result of this service will be placed in the "init. SVC. <service name>" attribute. The client application can poll the attribute value to determine the result.

Android toolbox Program
The android toolbox program provides two tools: setprop and getprop to get and set properties. Usage:
Getprop <property name>
Setprop <property name> <property value>

Java
In Java applications, you can use the system. getproperty () and system. setproperty () functions to obtain and set properties.

Action
By default, setting the attribute only causes the "init" daemon to write data to the shared memory. It does not execute any script or binary program. However, you can associate the operations you want to implement with changes to an attribute in init. Rc. For example, the default init. RC contains:

# 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

In this way, if you set persist. Service. ADB. Enable to 1, the "init" daemon knows that you need to take action to enable the adbd service.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.