Each attribute is a name-value pair, and the name and value are text. In the Android system, attributes are widely used to record system settings or exchange information between processes. Attributes are visible throughout the system, and each process can get/set attributes.
During system initialization, In the init daemon, Android allocates some memory to store these attributes. The init source code is in/system/init. Init daemon will enable a property service running in the INIT process. Every client that wants to set the property needs to connect to the property service and then send a message to it, property service updates/creates properties in the shared memory. The client that queries the attribute directly reads the attribute from the shared memory, which improves the Read efficiency.
The client calls the get/set API in libcutils, while the source code of libcutils is located in/libs/cutils. The API is as follows:
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 attribute in the shared memory. The source code of libc is in/system/bionic.
Property Service also calls the _ system_property_init function in libc to initialize the shared memory of the storage attribute. During the initial process of propertyservice, the default properties are loaded from the following files:
/Default. Prop
/System/build. Prop
/System/Default. Prop
/Data/local. Prop
The preceding figure shows the order in which attributes are loaded. When the attribute is repeated, the loaded value overwrites the loaded value. The last load is the persistent property stored in/data/property.
Special attributes
If an attribute name starts with "Ro.", the attribute is read-only. Once set, the attribute value will never be changed.
If the attribute name starts with "persistent.", when you set this attribute, the attribute value will be written to/data/property.
If the attribute name starts with "net.", the set attribute name will be added to the "NENT. Change" file. The netresolve module uses this attribute to track whether the net. * attribute has been changed.
The "Ctrl. Start" and "Ctrl. End" attributes are used to enable or stop a service. Each service must be defined in/init. RC. When the system starts, the init daemon will parse init. RC to enable the property service. Once a request for "Ctrl. Start" is set, propertyservice uses the property value as the name to locate and start the service. The service startup result is placed in the property "init. SVC. <Service
Name>. The client program checks this value to obtain the result.
Toolbox of Android
The toolbox of Android provides two gadgets: setprop and getprop, which are used for the set/get attributes respectively. The usage is as follows:
Getprop <property name>
Setprop <property name> <property value>
Java programs can use system. getproperty ()/system. setproperty to get/set attributes.
By default, the setting attribute can only be written to the shared memory through "init" daemon, and no script or program is executed. However, you can add actions in init. RC to respond to attribute updates. For example, in the default init. RC file, you can find the following:
# 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
Therefore, if you set persist. Service. ADB. Enable to 1, "init" daemon will start the adbd service.
During system initialization, In the init daemon, Android allocates some memory to store these attributes. The init source code is in/system/init. Init daemon will enable a property service running in the INIT process. Every client that wants to set the property needs to connect to the property service and then send a message to it, property service updates/creates properties in the shared memory. The client that queries the attribute directly reads the attribute from the shared memory, which improves the Read efficiency.
The client calls the get/set API in libcutils, while the source code of libcutils is located in/libs/cutils. The API is as follows:
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 attribute in the shared memory. The source code of libc is in/system/bionic.
Property Service also calls the _ system_property_init function in libc to initialize the shared memory of the storage attribute. During the initial process of propertyservice, the default properties are loaded from the following files:
/Default. Prop
/System/build. Prop
/System/Default. Prop
/Data/local. Prop
The preceding figure shows the order in which attributes are loaded. When the attribute is repeated, the loaded value overwrites the loaded value. The last load is the persistent property stored in/data/property.
Special attributes
If an attribute name starts with "Ro.", the attribute is read-only. Once set, the attribute value will never be changed.
If the attribute name starts with "persistent.", when you set this attribute, the attribute value will be written to/data/property.
If the attribute name starts with "net.", the set attribute name will be added to the "NENT. Change" file. The netresolve module uses this attribute to track whether the net. * attribute has been changed.
The "Ctrl. Start" and "Ctrl. End" attributes are used to enable or stop a service. Each service must be defined in/init. RC. When the system starts, the init daemon will parse init. RC to enable the property service. Once a request for "Ctrl. Start" is set, propertyservice uses the property value as the name to locate and start the service. The service startup result is placed in the property "init. SVC. <Service
Name>. The client program checks this value to obtain the result.
Toolbox of Android
The toolbox of Android provides two gadgets: setprop and getprop, which are used for the set/get attributes respectively. The usage is as follows:
Getprop <property name>
Setprop <property name> <property value>
Java programs can use system. getproperty ()/system. setproperty to get/set attributes.
By default, the setting attribute can only be written to the shared memory through "init" daemon, and no script or program is executed. However, you can add actions in init. RC to respond to attribute updates. For example, in the default init. RC file, you can find the following:
# 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
Therefore, if you set persist. Service. ADB. Enable to 1, "init" daemon will start the adbd service.