SoFunction
Updated on 2025-03-04

Key value settings of Property module in Android

Key value settings of Property module in Android

The Prop module saves a small amount of global shared information, and the data it saves has the characteristics of small amount of information and sharing data across processes. Each piece of information contains two attributes, key names and key values ​​corresponding to key names, such as:

=en

"" means the local language of this product, the name of the message, and "en" means the value of the message is in English, so that any application will know the language used by the machine. When designing an interface, there are also two parameters, name and value (key name and key value), and the methods include set and get, for example:

Set(String name,String value);
String Get(String name);

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

The prop module is encapsulated in the class. This class uses Set and Get to directly set and obtain. Of course, these java interfaces are ultimately completed by calling the system interface. There is a property_service.c file in the jni layer, and there are corresponding actual processing interfaces in the file. These interfaces can be called for Java, or some system commands can be used (for example, the setprop and getprop commands are to 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 at will.

The access to the SystemProperties class must have system permissions, and the application's uid must be system id: 1000 or root: 0. Because set and get operations are different, the operation establishes a socket pipeline during set and sends cmd out. The server receives cmd and compares permissions at the same time. The key code is as follows:

if (uid == AID_SYSTEM || uid == AID_ROOT)
  return check_control_mac_perms(name, sctx);

Only the permissions are AID_SYSTEM (system ID) and AID_ROOT (root user ID) can pass the verification; but get does not have permission to check, but imagine it is normal. If anyone can modify it, then this hacker is too easy to be a good person. Of course, I personally think that it is understandable to verify the design and use permissions of sets, but for functions such as viewing system properties, you should also be subdivided. For example, some attributes are not important and can be read and used by any process or user; of course, some sensitive data can also be specified when specifying the read permissions (due to limited time, I have not read more in-depth, and I don’t know whether the Android system has completed these functions).

Things to note when setting key-value names

When setting, it contains two parameters, variable name and variable value, such as: [[key]]: [[value]]. If there is no corresponding key value in the original module, a new key value will be created, otherwise the original key value will be overwritten. For key-value names, it is best to write them according to specifications when designing, such as "class name, module, purpose", so that they can be remembered clearly and not easily conflicted. Also, if the property name begins with "ro.", then this property is considered a read-only property. Once set, the property value cannot be changed. This judgment action is done in the property_set function in property_service.c:

if(!strncmp(name, "ro.", 3)) return -1;

If it starts with "persist.", when setting this property, its value will also be written to the /data/property/ directory. The key value name is the property name. The next time you start the computer, reload and read the property; the load_persistent_properties function in the file is used to complete the function. If a special attribute name starts with "", then its value must start with "net." For example, the key value is []: Then the key value is [net.qtaguid_enabled]. I haven't thought of any effect of this setting yet.

The corresponding prop operation command in the shell

There are also corresponding commands to operate in the android shell, with the following three commands:

  • getprop [keyname] Keyname is the key value name to be obtained. If there are no parameters, print all key value information.
  • setprop [keyname] [value] Keyname is the key value name to be obtained, value is the set value, this value is a string.
  • watchprops monitors changes in system properties, and displays the changed value if the system properties change during the period.

Setprop is also used in the settings to set some attribute states.

Supplement setprop:

Key value settings of Property module

The Prop module stores a small amount of global shared information, and the data it saves has the characteristics of small amount of information and sharing data across processes. Each piece of information contains two attributes, key names and key values ​​corresponding to key names. "" means the local language of this product, the name of the message, and "en" means the value of the message is in English, so that any application will know the language used by the machine.

The underlying implementation of Android terminal attribute prop operation

The main function in the file will be called start_property_service(), and it will call the load_properties_from_file function to read it separatelyPROP_PATH_SYSTEM_BUILD (/system/), PROP_PATH_SYSTEM_DEFAULT (/system/) and PROP_PATH_LOCAL_OVERRIDE (/data/)Stores the file of system properties and sets it to system properties.

Thank you for reading, I hope it can help you. Thank you for your support for this site!