Analysis of systemproperties settings of Android

Source: Internet
Author: User
Android system attributes include the persistent attributes of file storage and the cache attributes imported at each boot. The former is mainly stored in the following files:

Bionic/libc/include/sys/_ system_properties.h

# Define prop_service_name "property_service"
# 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 latter is defined through the interface of frameworks/base/CORE/Java/Android/OS/systemproperties. java,

Private Static native string native_get (string key );
Private Static native string native_get (string key, string DEF );
Private Static native void native_set (string key, string DEF );
Public static void set (string key, string Val ){
If (key. Length ()> prop_name_max ){
Throw new illegalargumentexception ("key. length>" + prop_name_max );
}
If (Val! = NULL & Val. Length ()> prop_value_max ){
Throw new illegalargumentexception ("Val. length>" +
Prop_value_max );
}
Native_set (Key, Val );
}

This interface class registers the corresponding CPP interface android_ OS _systemproperties.cpp in the initialization runtime environment. The actual operation is to call the interface corresponding to the CPP file through JNI:

Frameworks/base/CORE/JNI/androidruntime. cpp

Namespace Android {
Extern int register_android_ OS _systemproperties (jnienv * env );
}

Frameworks/base/CORE/JNI/android_ OS _systemproperties.cpp

Static void systemproperties_set (jnienv * ENV, jobject clazz, jstring keyj, jstring valj)
{
Int err;
Const char * key;
Const char * val;
Key = env-> getstringutfchars (keyj, null );
If (valj = NULL ){
Val = "";/* NULL pointer not allowed here */
} Else {
Val = env-> getstringutfchars (valj, null );
}
Err = property_set (Key, Val );
Env-> releasestringutfchars (keyj, key );
If (valj! = NULL ){
Env-> releasestringutfchars (valj, Val );
}
}

When setting the value of the key, authentication is required. The UID value is obtained based on the FD of the process where the setting program is located. For example, the system server process can set the net hitting key, but cannot set the GSM hitting key, the related definitions are as follows:

System/CORE/include/private/android_filesystem_config.h
# Define aid_root 0/* traditional UNIX root user */
# Define aid_system 1000/* system server */
# Define aid_radio 1001/* telephony subsystem, rIL */
# Define aid_dhcp 1014/* DHCP Client */
# Define aid_shell 2000/* ADB and debug shell user */
# Define aid_cache 2001/* cache access */
# Define aid_app 10000/* first app user */

System/CORE/init/property_service.c
# Define persistent_property_dir "/data/property"
Struct {
Const char * prefix;
Unsigned int uid;
} Property_perms [] = {
{"Net. rmnet0.", aid_radio },
{"Net. GPRS.", aid_radio },
{"RIL.", aid_radio },
{"GSM.", aid_radio },
{"Net. DNS", aid_radio },
{"Net. usb0", aid_radio },
{"Net.", aid_system },
{"Dev.", aid_system },
{"Runtime.", aid_system },
{"HW.", aid_system },
{"SYS.", aid_system },
{"Service.", aid_system },
{"WLAN.", aid_system },
{"DHCP.", aid_system },
{"DHCP.", aid_dhcp },
{"Debug.", aid_shell },
{"Log.", aid_shell },
{"Service. ADB. Root", aid_shell },
{"Persist. SYS.", aid_system },
{"Persist. Service.", aid_system },
{Null, 0}
};
Int property_set (const char * Name, const char * value)
{
Property_changed (name, value );
Return 0;
}
Int start_property_service (void)
{
Int FD;

Load_properties_from_file (prop_path_system_build );
Load_properties_from_file (prop_path_system_default );
Load_properties_from_file (prop_path_local_override );
/* Read persistent properties after all default values have been loaded .*/
Load_persistent_properties ();

FD = create_socket (prop_service_name, sosock_stream, 0666, 0, 0 );
If (FD

Related Article

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.