Research and analysis of prop properties of Android system

Source: Internet
Author: User

In the process of development, often share some data information, there is an environment variable or attribute the following several situations:

1. This variable needs to be used in multiple places and is cross-process or cross-threading.

2. This environment variable is generally only read once and does not need to be saved frequently.

3. At the same time, this variable information can be saved after the shutdown restart.

For these requirements, it is common practice to save this information in a file, and to extract and save the information by reading and writing the file, which has a small amount of data. This method is possible, but not very system-perfect, and when the need to read the information required to do the IO operation of the file, which is time- consuming and wasteful system resources; There is also a situation, is a variable information, boot only from the Flash It is seldom modified when the system is running, so this information is more appropriate to save to memory.

Windows has a well-established module that stores a small amount of configuration information, and There is a similar Prop module in Android. the Prop Module stores Many of the configuration information that is run by the system and reads it when a system state is required for the program to run. the Prop module is essentially a piece of data that is stored in memory while the system is running, and reads and writes data to operate on that area, with the benefit of fast read and write, shared data across processes, and the disadvantage of sudden loss of data when power is lost; Prop can also save the data, which is mentioned later.

Some useful configuration information in the system:

after Android is started, it is completed in property_service.c property_init prop The initialization . There are several files in the system, such as build.prop and default.prop , which are generated at the time of system construction and contain many system configuration information. The system goes back to load the information in these files and saves them to the prop module for use by other programs.

For example, in Build.prop , the following information is available:

Dalvik.vm.heapstartsize=5m

dalvik.vm.heapgrowthlimit=96m

dalvik.vm.heapsize=256m

dalvik.vm.heaptargetutilization=0.75

dalvik.vm.heapminfree=512k

Dalvik.vm.heapmaxfree=2m

The stack size of the virtual machine and other properties.

Persist.sys.timezone=asia/shanghai

Time zone information.

Ro.build.version.codename=rel

ro.build.version.release=4.2.2

RO.BUILD.DATE=FRI Dec 15:56:10 UTC 2014

ro.build.date.utc=1419609370

Build the information.

ro.product.cpu.abi=armeabi-v7a

Ro.product.cpu.abi2=armeabi

Ro.product.manufacturer=unknown

ro.product.locale.language=en

Ro.product.locale.region=us

Cpu information, default language settings.

Dalvik.vm.stack-trace-file=/data/anr/traces.txt

The debug information for the virtual machine saves the path.

These actions are done in init.rc , which calls the Start_property_service in property_service.c function to complete the loading of the following files in this function:

#define Prop_path_ramdisk_default "/default.prop"

#define Prop_path_system_build "/system/build.prop"

#define Prop_path_system_default "/system/default.prop"

#define Prop_path_local_override "/data/local.prop"

The load_persistent_properties function is also called , and the function looks for the user's save settings in/data/property/.

The ENV environment variable has a android_property_workspace variable that stores the size of the prop memory area, which is completed in the Init_property_area.

Propcorresponding to theJavaInterface:

Propmodule, you canSetand theGetperform the appropriate operations, which areproperty_service.cin aProperty_setand theProperty_getinterface to operate. Androidof theJAVAlayer also has a corresponding interface, which is applied to theandroid.os.SystemPropertiesclass, the class'sSetand theGetdirectly to set up and get, these interface methods chasing the bottom layer is also usedProperty_setfunction to complete. But these interfaces are not directly available to the application,Setinterface, you must have system permissions.

Systempropertiesaccess to the class must have system permissions, and the application'sUIDmust be a systemID: +or forroot:0. BecauseSetand theGetoperation is different,Setwhen the operation establishes aSocketpipeline through the haircmdout of the way, the server receivescmdCompare permissions at the same time,such as:

if (uid = = Aid_system | | uid = = aid_root)

Return check_control_mac_perms (name, sctx);

Only permissions can be setafter it is passed. and get does not have permission to check, but think also normal, if anyone can make changes, then this hacker is too good when.

Places to note when setting key-value names:

When setting, contains two parameters, variable names and variable values, as follows: [[Key]]: [[value]]. If there is no corresponding key value, then a new key value is created in the module, but there are some requirements for the key name. It is best to use a key name that is easy to distinguish and does not conflict with other key names. If the property name begins with "ro.", then this property is treated as a read-only property. Once set, the property value cannot be changed. This action is done in the property_set function in property_service.c , with the following code:

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

if " "begins, when this property is set, its value is also written to the /data/property/ The next time the value is present, the file's load_persistent_properties function, complete /data/property/ property loading and setting.

If the property name is " Net.change "At the beginning then its value must be in the" net. "begins. For example, the key value is named [Net.change]: then the key value is [net.qtaguid_enabled].

Shellin the correspondingpropOperation Command:

In the android Shell There are also commands to operate, with the following three commands:

Getprop [KeyName]

Keyname is the name of the key value that needs to be obtained, and all key-value information is printed if no parameters are available.

SetProp [KeyName] [value]

Keyname is the name of the key value to get , Value is the set value, and the value is a string.

Watchprops

Monitor the change of the system properties, and display the change value if the system's properties change during the period.

In init.rc , you also use setprop to set some attribute states.


[ This article is based on the android4.2 Source code Analysis ]

Research and analysis of prop properties of Android system

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.