I verified my opinion N years ago.
Because I do not know much about the property system of Android, I have translated this article
Property System
.
The shared memory mentioned in this article is a unique Android sharing method: ashmen
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
?
- Int
_ System_properties_init (
Void
)
- {
- Prop_area * pA;
- Int
S, FD;
- Unsigned SZ;
- Char
* Env;
- If
(_ System_property_area __! = ((
Void
*) & Dummy_props )){
- Return
0;
- }
- ENV = getenv ("android_property_workspace"
);
- If
(! ENV ){
- Return
-1;
- }
- FD = atoi (ENV );
- ENV = strchr (ENV ,','
);
- If
(! ENV ){
- Return
-1;
- }
- SZ = atoi (ENV + 1 );
- Pa = MMAP (0, SZ, prot_read, map_shared, FD, 0 );
- If
(Pa = map_failed ){
- Return
-1;
- }
- If
(Pa-> magic! = Prop_area_magic) | (Pa-> version! = Prop_area_version )){
- Munmap (Pa, SZ );
- Return
-1;
- }
- _ System_property_area _ = PA;
- Return
0;
- }
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
?
- # Include <cutils/properties. h>
- # Include <stdio. h>
- Void
Print_prop (
Const
Char
* Key,
Const
Char
* Value,
Void
* Cookie)
- {
- Printf ("Key = % s, value = % S/N"
, Key, value );
- }
- Int
Main ()
- {
- Property_list (print_prop, null );
- }
# 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