Systemproperties and Settings.system
1 Using Systemproperties.get
If the property name is "Ro." Begins, then this property is treated as a read-only property. Once set, the property value cannot be changed.
If the property name is "persist." At the beginning, when this property is set, its value is also written to/data/property.
The Java code is as follows:
Import android.os.SystemProperties; // setting Systemproperties.set ("Persist.sys.language", "Default value"); // Read String lang= systemproperties.get ("Persist.sys.language"); // string int lang = systemproperties.getint ("Persist.sys.language", ten); Boolean false); // Boolean
Create and modify Android properties with
Systemproperties.set (name, value);
Get Android Properties with
Systemproperties.get (name);
It is important to note that the name of the Android attribute is in a certain format,
Prefix must be prefixed with the prefix defined in SYSTEM\CORE\INIT\PROPERTY_SERVICE.C
The contents of property_service.c are as follows
Property_perms[] = { { "net.rmnet0.", Aid_radio,0 }, { "Net.gprs.", Aid_radio,0 }, { "NET.PPP", Aid_radio,0 }, { "Net.qmi", Aid_radio,0 }, { "Net.lte", Aid_radio,0 }, { "NET.CDMA", Aid_radio,0 }, { "Ril.", Aid_radio,0 }, { "Persist.ril.", Aid_radio,0 }, { "Persist.ril.cfu.querytype", Aid_app,0 }, { "Mux.", Aid_radio,0 }, { "Mux.", Aid_system,0 }, { "mtk_telephony_mode_slot1", Aid_system,0 }, { "Mtk_telephony_mode_slot2", Aid_system,0 }, { "GSM.", Aid_radio,0 }, { "Persist.radio", Aid_radio,0 }, { "Net.dns", Aid_radio,0 }, { "Sys.usb.config", Aid_radio, Aid_system}, {"net.", Aid_system,0 }, { "net.", AID_DHCP,0 }, { "Dev.", Aid_system,0 }, { "Runtime.", Aid_system,0 }, { "HW.", Aid_system,0 }, { "sys.", Aid_system,0 }, { "Sys.powerctl", Aid_shell,0 }, { "service.", Aid_system,0 }, { "WLAN.", Aid_system,0 }, { "bluetooth.", Aid_bluetooth,0 }, { "DHCP.", Aid_system,0 }, { "bwc.mm.", Aid_system,0 }, { "DHCP.", AID_DHCP,0 }, { "Debug.", Aid_system,0 }, { "Debug.", Aid_shell,0 }, { "log.", Aid_shell,0 }, { "Service.adb.root", Aid_shell,0 }, { "Service.adb.tcp.port", Aid_shell,0 }, { "Persist.sys.", Aid_system,0 }, { "Persist.service.", Aid_system,0 }, { "persist.security.", Aid_system,0 }, { "persist.service.bdroid.", Aid_bluetooth,0 }, { "SELinux.", Aid_system,0 }, { "GPS.", Aid_gps, Aid_system}, {"Persist.af.", Aid_media,0},
Programs that perform system property settings must also have either system or root permissions
If we want to add a property: for example: Zhang
Path:
system/core/rootdir/init. RC
Its content is as follows
On post-fs-Data#We Chown/chmod/data again so because Mount is run as root + defaultsChown System System/Data chmod0771/Data#We Restorecon/data in case the UserData partition have been reset.Restorecon/Data#Avoid predictable entropy pool. Carry over entropy from previous boot.copy/data/system/entropy.dat/dev/Urandom#Create dump dir and collect dumps. #Do the before we mount cache so eventually we can use the cache for #storing dumps on platforms which does not has a dedicated dump partition.Mkdir/data/dontpanic 0750Root Log#Collect apanic data, free resources and re-arm triggercopy/proc/apanic_console/data/dontpanic/apanic_console chown Root log/data/dontpanic/apanic_console chmod0640/data/dontpanic/apanic_console Copy/proc/apanic_threads/data/dontpanic/apanic_threads chown Root log/data/dontpanic/apanic_threads chmod0640/data/dontpanic/Apanic_threads Write/proc/apanic_console 1#If There is no fs-post-data action in the init.<device>.rc file, you #must uncomment this line, otherwise encrypted filesystems #won ' t work. #Set Indication (checked by vold) then we have the finished this action #setprop Vold.post_fs_data_done 1
Under the on Post-fs-data directory
SetProp persist.sys.zhang 1//persist.sys prefix name; 1 is the initial value
PS: Different prefix name permissions are different, this is not explained here; and why load the on Post-fs-data directory, which is related to int.rc syntax
2 Using Settings.System.putInt
This way the switch is saved to the settings database, and the flight mode switches are implemented in this way.
You first need to define a system property value
Path
Frameworks/base/core/java/android/provider/settings.java
Add a property label
Public Static FinalString Qs_dynamic_wifi = "Qs_dyanmic_wifi"; /*** Quick Settings Quick Pulldown * * @hide*/ Public Static FinalString Qs_quick_pulldown = "Qs_quick_pulldown"; /*** Quick Settings Collapse Pane * * @hide*/ Public Static FinalString Qs_collapse_panel = "Qs_collapse_panel"; /*** Quick Settings Quick Access Ribbon * * @hide*/ Public Static FinalString qs_quick_access = "Qs_quick_access";//don't forget to add it in here. Public Static Finalstring[] Settings_to_backup ={Qs_quick_pulldown stay_on_while_plugged_in,//moved to Globalwifi_use_static_ip, Wifi_static_ip, Wifi_static_gateway, Wifi_static_netm ASK, Wifi_static_dns1, Wifi_static_dns2, bluetooth_discoverability, Bluetooth_ Discoverability_timeout, Dim_screen, Screen_off_timeout, screen_brightness, SC Reen_brightness_mode, Screen_auto_brightness_adj, Vibrate_input_devices, Mode_ringer_stre ams_affected, Volume_voice, Volume_system, volume_ring, Volume_music, Volume_alarm,}
1) Get the following method:
Settings.System.getInt (Getcontentresolver (), settings.system.qs_quick_pulldown,0);
The third parameter is a default value
2) Set
Settings.System.putInt (Getcontentresolver (), Settings.System.QS_QUICK_PULLDOWN, 1);
When used in code, the package needs to be imported
Import android.provider.Settings required;
setting.system-setting of global properties