Key value setting of property module in Android

Key value setting of property module in Android

Prop module saves a small amount of global shared information, and its saved data has the characteristics of less information and sharing data across processes; Each piece of information contains two attributes, the key name and the key value corresponding to the key name, for example:

"Ro. Product. Locale. Language" means the local language of the product and the name of the message, "en" means that the value of the message is English, so that any application can know the language used by the machine. In the interface design, there are also two parameters, name and value (key name and key value). The methods are set and get, for example:

Of course, no matter how the upper layer is designed, the key name name and key value at the bottom of C are saved in char array, because the designer does not know the data size of the incoming name and value.

The prop module is encapsulated in the android.os.systemproperties class. This class uses set and get to set and obtain directly. Of course, these Java interfaces are finally completed by calling the system interface. There is a property in the JNI layer_ Service. C file. There are corresponding actual processing interfaces in the file. These interfaces can be called to Java or used by some system commands (for example, setprop and getprop commands call these interface methods). There are no restrictions on the get method in the SystemProperties class, but the set method has permission restrictions. Applications cannot use the set interface casually.

The access of SystemProperties class must have system permission, and the uid of the application must be system ID: 1000 or root: 0. Because the set operation is different from the get operation, the set operation establishes a socket pipeline and is completed by sending CMD. The server receives CMD and compares permissions. The key codes are as follows:

Only permission is aid_ System (system ID) and aid_ Root (root user ID) can pass the verification; And get doesn't have permission to check, but it's normal to imagine. If anyone can modify it, it's too easy to be a hacker. Of course, I personally feel that there is nothing wrong with the design permission verification of set, but the function of viewing system properties (get) should also be subdivided. For example, some properties are unimportant and can be read and used by any process and user; Of course, some sensitive data can also be specified when the read permission is specified (due to the limited time, I don't have a more in-depth reading, and I don't know whether the Android system has completed these functions).

Points to pay attention to when setting key value name

When setting, it contains two parameters, variable name and variable value, such as: [[key]]: [[value]]. If there is no corresponding key value, a new key value will be created in the module, otherwise the original key value will be overwritten. For the key value name, it is best to write it according to the specification, such as "class name, module and purpose", which is clear and not easy to conflict. In addition, if the attribute name starts with "ro." then the attribute is considered read-only. Once set, the property value cannot be changed. This judgment action is in property_ Property in service. C_ Completed in the set function:

If it starts with "persist." when this property is set, its value will also be written to the / data / property / directory. The key value name is the property name. The property will be loaded and read again after the next boot; Load in this file_ persistent_ The properties function is used to complete this function. If the special attribute name starts with "net. Change", its value must start with "net.", for example, if the key value name is [net. Change]: then the key value is [net. Qtaguid_enabled]. This setting has no effect at present.

Corresponding prop operation command in shell

There are also corresponding commands in the Android shell for operation, including the following three commands:

Setprop is also used in init.rc to set some attribute states.

Supplement setprop:

Key value setting of property module

Prop module saves a small amount of global shared information, and its saved data has the characteristics of less information and sharing data across processes; Each piece of information contains two attributes, the key name and the key value corresponding to the key name. "Ro. Product. Locale. Language" means the local language of the product and the name of the message, "en" means that the value of the message is English, so that any application can know the language used by the machine.

Bottom layer implementation of prop operation of Android terminal attribute

Start is called in the main function in the init. C file_ property_ Service (), which calls load respectively_ properties_ from_ The file function reads prop_ PATH_ SYstem_ BUILD(/system/build.prop)、PROP_ PATH_ SYstem_ Default (/ system / default. Prop) and prop_ PATH_ LOCAL_ Override (/ data / local. Prop) stores files of system properties and sets them to system properties.

Thank you for reading, hope to help you, thank you for your support to this site!

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>