The difference between the value in XML in Settings and the value in Default.xml in Settingsprovider

Source: Internet
Author: User

When I recently looked at a default value in Settings, I found two places to use, a bit of a question.


What's the difference between these two defaultval?/res/xml/sound_settings.xml:109104 <checkboxpreference
"Android:key="sound_effects"
106 android:title= "@string/sound_effects_enable_title"
107Android:defaultvalue= "true"/> and Frameworks/base/packages/settingsprovider/res/values/defaults.xml<bool name= "def_sound_effects_enabled>true</bool>-----------------------Solution---------------------------First of all to see how the code is referenced, in the framework, The resource file is defined as:frameworks/base/packages/settingsprovider/res/values/defaults.xml<!--Default for UI touch sounds Enabled--
<bool name= "def_sound_effects_enabledThe >true</bool> code is used here./base/packages/settingsprovider/src/com/android/providers/settings/ databasehelper.java:2035:r.bool.def_sound_effects_enabled); take another look at the logic:-"private void" loaduisoundeffectssettings(Sqlitestatement stmt) {... loadbooleansetting (stmt, Settings.system.sound_effects_enabled,
R.bool.def_sound_effects_enabled);//Read the value of def_sound_effect_enabled from Defaults.xml, write to the database by SQLite soudn_effects_enabled The value of this key ...}
Class Databaehelper OnCreate ()//Load inital settings values
LoadSettings (db);->
LoadSettings (Sqlitedatabase db), loadsystemsettings (Sqlitedatabase db), loaduisoundeffectssettings(stmt);
That is, the value under the framework is in the OnCreate function of the Databasehelper.java class, using this value to write to the database (settings.db) to verify: [Email protected]:/data/data/ Com.android.providers.settings/databases # ls
Settings.db
Settings.db-journal
[Email protected]:/data/data/com.android.providers.settings/databases # sqlite3 Setting.db
Sqlite> SELECT * from system;155|sound_effects_enabled|1
So, when does the Databasehelper class instantiate?/base/packages/settingsprovider/src/com/android/providers/settings/ settingsprovider.java:381 inSettingsproviderThe OnCreate method in this class is the public boolean onCreate () {
...
Establishdbtracking (Userhandle.user_owner); ...} ->private void establishdbtracking (int userhandle) {
...
DBHelper = new Databasehelper(GetContext (), userhandle);
Go deeper, Settingsprovider. What is the instantiation of this class? Search code can be found, Settingsprovider is an APK package Frameworks/base/packages/settingsprovider/android.mk 1 local_path:= $ (call My-dir)
2 include $ (clear_vars)
3
4 Local_module_tags: = Optional
5
6 Local_src_files: = $ (call all-subdir-java-files)
7
8 Local_java_libraries: = Telephony-common
9
Ten Local_package_name: =Settingsprovider
One local_certificate: = Platform
12Local_privileged_module: = True
13
Include $ (build_package)
15
16 ########################
Include $ (call all-makefiles-under,$ (Local_path))
This is some of the Android apk, these apk also includes systemui.apk,inputdevice.apk and so on, these compilations will be placed under System/priv-app; So the problem is, 1, what kind of apk will be put under Pri-app? A: In the android.mk inside the Local_privileged_modeule attribute will be placed under the Pri-app, 2,/system/app and/system/priv-app/What is the difference? /system/priv-app include Launcher,systemui, Settingsprovider, etc., are the core applications of the system, these applications can use system-level permissions, all prior to 4.4/system/ Software under the app can use system-level permissions.

OK, sum up, Values below the framework: when SETTINGSPROVIDER.APK is running (oncreat), the Databasehelper class reads the values inside the framework default.xml, and then writes to the SETTINGS.DB database.
Next, how does settings use this value? In Packages/apps/settings/src/com/android/settings/soundsettings.java @Override
public void OnCreate (Bundle savedinstancestate) {... msoundeffects = (checkboxpreference) findpreference (key_sound_ EFFECTS);
Msoundeffects.setpersistent (FALSE);
Msoundeffects.setchecked (Settings.System.getInt (resolver,
Settings.system. sound_effects_enabled, 1)! = 0) ...} By sound_effects_enabled This key to read the database read value, this key is Settingsprovider write. So it seems that there is no relationship with the DefaultValue inside the Sound_settings.xml?! I made an implementation, in the Soundsettungs.java to sound_effects_enable this key operation of the place shielding. Set the Defaultvalue=true/false. Discover whether this control enables or not to follow this value. When drawing the UI, first use the value of the DefaultValue inside the Soudn_settings.xml, and then set this value when you read the database. It is also said that the value of the database within the framework "weight" is greater, it is set two times. But when adding attributes, it's best to unify both sides.

The difference between the value in XML in Settings and the value in Default.xml in Settingsprovider

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.