Android attribute system and its Supplement

Source: Internet
Author: User

I verified my opinion N years ago.

 

Http://blog.csdn.net/tekkamanitachi/archive/2009/06/18/4280982.aspx

Http://blog.csdn.net/chief1985/archive/2009/09/14/4551242.aspx

 

Because I do not know much about the property system of Android, I have translated this article
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. Attribute is global throughout the system
Visible. 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, whose source code is located at: device/System
/Init. The "init" daemon starts an Attribute Service. The property service runs in the "init" daemon. Each client must connect to the property service before sending
Send information. 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 );
While libcutils calls _ system_property_xxx in libc
Function 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 attributes will be loaded from the following files
Sex:
/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 .)
Properties "Ctrl. Start" and "Ctrl. Stop"
Is used to start and stop the service. 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 the"
CTRL. Start "property request. The property service uses this property value as the service name to locate the service and start the service. The startup result of this service will be placed in"
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
Changes to an attribute are associated. 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.

The shared memory mentioned in this article is a unique Android sharing method: ashmen

Ashmem is an anonymous shared memory (anonymous shared
Memory) system, the system adds interfaces, so the process can share the named memory block. For example, the system can use the ashmem storage icon. Multiple processes can also be used when the user interface is drawn.
To access. Ashmem is better than traditional Linux shared memory tables. Now, when shared memory blocks are no longer used, it provides kernel with a way to recycle these shared memory blocks. If a program tries
Try to access a shared memory block released by the kernel. It will receive an error message, re-allocate the memory and reload the data.

 

There is an article on the android Property System (http://blog.csdn.net/tekkamanitachi/archive/2009/06/18/4280982.aspx
),
I will add:

1. Currently, Android only seems to have two files:/Default. Prop,/system/build. Prop, and the other two files cannot be found.

2.
/Data/property has four prop files
Files: persist. SYS. timezone, persist. SYS. Language, persist. SYS. Country, persist. SYS. localevar,
It stores the attribute values starting with "Persist.

3.
The source code of libcutils is located under system/CORE/libcutils/. The code for obtaining and setting properties is located in properties. C.
The shared memory is obtained. The attribute is set by sending a request to property_service.

4. Related functions include property_set, property_get, and property_list.

5.
The initialization of the property system is completed through the _ system_properties_init function, and the code of the __system_properties_init function is as follows:

View
Plain
Copy
To clipboard
Print
?
  1. Int
    _ System_properties_init (
    Void
    )
  2. {
  3. Prop_area * pA;
  4. Int
    S, FD;
  5. Unsigned SZ;
  6. Char
    * Env;
  7. If
    (_ System_property_area __! = ((
    Void
    *) & Dummy_props )){
  8. Return
    0;
  9. }
  10. ENV = getenv ("android_property_workspace"
    );
  11. If
    (! ENV ){
  12. Return
    -1;
  13. }
  14. FD = atoi (ENV );
  15. ENV = strchr (ENV ,','
    );
  16. If
    (! ENV ){
  17. Return
    -1;
  18. }
  19. SZ = atoi (ENV + 1 );
  20. Pa = MMAP (0, SZ, prot_read, map_shared, FD, 0 );
  21. If
    (Pa = map_failed ){
  22. Return
    -1;
  23. }
  24. If
    (Pa-> magic! = Prop_area_magic) | (Pa-> version! = Prop_area_version )){
  25. Munmap (Pa, SZ );
  26. Return
    -1;
  27. }
  28. _ System_property_area _ = PA;
  29. Return
    0;
  30. }

Int <br/>__ system_properties_init (void) <br/>{< br/> prop_area * pA; <br/> int S, FD; <br/> unsigned SZ; <br/> char * env; <br/> If (_ system_property_area __! = (Void *) & dummy_props) {<br/> return 0; <br/>}< br/> Env = getenv ("android_property_workspace "); <br/> If (! ENV) {<br/> return-1; <br/>}< br/> FD = atoi (ENV); <br/> Env = strchr (ENV ,', '); <br/> If (! ENV) {<br/> return-1; <br/>}< br/> SZ = atoi (ENV + 1); <br/> Pa = MMAP (0, SZ, prot_read, map_shared, FD, 0); <br/> If (Pa = map_failed) {<br/> return-1; <br/>}< br/> If (Pa-> magic! = Prop_area_magic) | (Pa-> version! = <Br/> prop_area_version) {<br/> munmap (Pa, SZ); <br/> return-1; <br/>}< br/>__ system_property_area _ = PA; <br/> return 0; <br/>}
 

We can see that android_property_workspace and android_property_workspace are obtained from the environment variables first.
The value is in the following format: android_property_workspace = 9,32768. Then obtain the file handle and length of the shared memory, and check and set the shared memory.
Set the value of the global variable _ system_property_area _. property_get is from _ system_property_area _.
Attribute Value of the read area. Environment variables are initialized in the service_start function of init. C.

6./init. RC contains the code for setting attributes, for example:

# Define the oom_adj values for the classes of processes that can be

# Killed by the kernel. These are used in activitymanagerservice.

Setprop Ro. foreground_app_adj 0

Setprop Ro. visible_app_adj 1

Setprop Ro. secondary_server_adj 2

Setprop Ro. home_app_adj 4

Setprop Ro. hidden_app_min_adj 7

Setprop Ro. content_provider_adj 14

Setprop Ro. empty_app_adj 15

7. You can use property_list to enumerate all attributes. Below is a piece of code that prints all attributes.

View
Plain
Copy
To clipboard
Print
?
  1. # Include <cutils/properties. h>

  2. # Include <stdio. h>

  3. Void
    Print_prop (
    Const
     
    Char
    * Key,
    Const
     
    Char
    * Value,
    Void
    * Cookie)
  4. {
  5. Printf ("Key = % s, value = % S/N"
    , Key, value );
  6. }
  7. Int
    Main ()
  8. {
  9. Property_list (print_prop, null );
  10. }

# Include <br/> <cutils/properties. h> <br/> # include <stdio. h> <br/> void print_prop (const char * Key, const char * value, void * cookie) <br/>{< br/> printf ("Key = % s, value = % s/n ", key, value); <br/>}< br/> int main () <br/>{< br/> property_list (print_prop, null); <br/>}
 

Android. mk file:

Local_path: = $ (call my-DIR)

Include $ (clear_vars)

Local_src_files: =/

List_property.cpp/

Local_shared_libraries: =/

Libcutils/

Libutils/

Local_module: = list_prop

Include $ (build_executable)

Include $ (call all-makefiles-under, $ (local_path ))

All attributes are as follows:

Key = Ro. Secure, value = 0

Key = Ro. Allow. Mock. Location, value = 1

Key = Ro. debuggable, value = 1

Key = persist. Service. ADB. Enable, value = 1

Key = Ro. kernel. qemu, value = 1

Key = Ro. kernel. Console, value = ttys0

Key = Ro. kernel. Android. checkjni, value = 1

Key = Ro. kernel. Android. qemud, value = ttys1

Key = Ro. factorytest, value = 0

Key = Ro. serialno, value =

Key = Ro. bootmode, value = unknown

Key = Ro. baseband, value = unknown

Key = Ro. Carrier, value = unknown

Key = Ro. bootloader, value = unknown

Key = Ro. Hardware, value = goldfish

Key = Ro. Revision, value = 0

Key = Ro. Build. ID, value = cupcake

Key = Ro. Build. display. ID, value = SDK-Eng 1.5 cupcake 148875 test-keys

Key = Ro. Build. version. incremental, value = 148875

Key = Ro. Build. version. SDK, value = 3

Key = Ro. Build. version. Release, value = 1.5

Key = Ro. Build. Date, value = Thu May 14 17:29:49 PDT 2009

Key = Ro. Build. Date. Universal, value = 1242347389

Key = Ro. Build. type, value = ENG

Key = Ro. Build. User, value = Android-build

Key = Ro. Build. Host, value = e-honda.mtv.corp.google.com

Key = Ro. Build. tags, value = test-keys

Key = Ro. Product. Model, value = SDK

Key = Ro. Product. Brand, value = generic

Key = Ro. Product. Name, value = SDK

Key = Ro. Product. device, value = generic

Key = Ro. Product. Board, value =

Key = Ro. Product. manufacturer, value = unknown

Key = Ro. Product. locale. Language, value = en

Key = Ro. Product. locale. region, value = us

Key = Ro. Board. Platform, value =

Key = Ro. Build. Product, value = generic

Key = Ro. Build. Description, value = SDK-Eng 1.5 cupcake 148875 test-keys

Key = Ro. Build. fingerprint, value = generic/SDK/generic/: 1.5/cupcake/148875: Eng/test-keys

Key = rild. libpath, value =/system/lib/libreference-ril.so

Key = rild. libargs, value =-D/dev/ttys0

Keypolicro.config.notification_sound,value?f=new_sms.ogg

Key = XMPP. Auto-presence, value = true

Key = Ro. config. nocheckin, value = Yes

Key = net. bt. Name, value = android

Key = net. Change, value = net. GPRS. Local-IP

Key = Dalvik. VM. Stack-trace-file, value =/data/ANR/traces.txt

Key = persist. SYS. timezone, value = GMT

Key = persist. SYS. Language, value = en

Key = persist. SYS. Country, value = us

Key = persist. SYS. localevar, value =

Key = Ro. foreground_app_adj, value = 0

Key = Ro. visible_app_adj, value = 1

Key = Ro. secondary_server_adj, value = 2

Key = Ro. home_app_adj, value = 4

Key = Ro. hidden_app_min_adj, value = 7

Key = Ro. content_provider_adj, value = 14

Key = Ro. empty_app_adj, value = 15

Key = Ro. foreground_app_mem, value = 1536

Key = Ro. visible_app_mem, value = 2048

Key = Ro. secondary_server_mem, value = 4096

Key = Ro. home_app_mem, value = 4096

Key = Ro. hidden_app_mem, value = 5120

Key = Ro. content_provider_mem, value = 5632

Key = Ro. empty_app_mem, value = 6144

Key = net. tcp. buffersize. Default, value = 4096,87380, 110208,4096, 16384,110208

Key = net. tcp. buffersize. WiFi, value = 4095,87380, 110208,4096, 16384,110208

Key = net. tcp. buffersize. UMTS, value = 4094,87380, 110208,4096, 16384,110208

Key = net. tcp. buffersize. Edge, value = 4093,26280, 35040,4096, 16384,35040

Key = net. tcp. buffersize. GPRS, value = 4092,8760, limit 80, 4096, 8760,limit 80

Key = init. SVC. Console, value = running

Key = init. SVC. servicemanager, value = running

Key = init. SVC. Vold, value = running

Key = init. SVC. debugadh, value = running

Key = init. SVC. RIL-daemon, value = running

Key = init. SVC. zygote, value = running

Key = init. SVC. Media, value = running

Key = init. SVC. installd, value = running

Key = init. SVC. flash_recovery, value = stopped

Key = init. SVC. Goldfish-setup, value = stopped

Key = init. SVC. qemud, value = stopped

Key = init. SVC. Goldfish-logcat, value = stopped

Key = Argh, value = argh

Key = net. eth0.dns1, value = 10.0.2.3

Key = net. GPRS. Local-IP, value = 10.0.2.15

Key = Ro. Radio. Use-PPP, value = No

Key = status. Battery. State, value = slow

Key = status. Battery. Level, value = 5

Key = status. Battery. level_raw, value = 50

Key = status. Battery. level_scale, value = 9

Key = Ro. setupwizard. mode, value = emulator

Key = ro.com. Google. locationfeatures, value = 1

Key = init. SVC. adbd, value = running

Key = Ro. qemu. init. Completed, value = 1

Key = HW. keyboards.65536.devname, value = qwerty2

Key = SYS. settings_secure_version, value = 2

Key = Dev. bootcomplete, value = 1

Key = SYS. settings_system_version, value = 6

Key = GSM. Sim. Operator. Numeric, value =

Key = GSM. Sim. Operator. Alpha, value =

Key = GSM. Sim. Operator. iso-country, value =

Key = GSM. Sim. State, value = unknown

Key = aDb. Connected, value = 1

 

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.