在frameworks中跟Setting默认值相关的几个文件
/frameworks/base/packages/SettingsProvider/res/values/defaults.xml
/frameworks/base/packages/SettingsProvider/src/com/android/providers/settings/DatabaseHelper.java
在defaults.xml文件中定义了相关的值,DatabaseHelper.java会把相应的值读取出来保存到ContentProvider
下面就来看下defaults.xml中定义了哪些值
true
60000
false
cell,bluetooth,wifi,nfc,wimax
bluetooth,wifi,nfc
true
true
true
102
false
100%
100%
true
false
false
false
true
gps
true
true
true
false
2
true
false
com.google.android.backup/.BackupTransportService
true
true
false
true
true
1
/system/media/audio/ui/LowBattery.ogg
0
/system/media/audio/ui/Dock.ogg
/system/media/audio/ui/Undock.ogg
/system/media/audio/ui/Dock.ogg
/system/media/audio/ui/Undock.ogg
1
/system/media/audio/ui/Lock.ogg
/system/media/audio/ui/Unlock.ogg
/system/media/audio/ui/WirelessChargingStarted.ogg
false
false
1
true
true
false
false
0x13=0x01000100;
0x14=0x01010100;
0x15=0x02000001;
0x16=0x02010001;
0x200000013=0x02000601;
0x200000014=0x02010601;
0x200000015=0x03020101;
0x200000016=0x03010201;
0x200000023=0x02000301;
0x200000024=0x02010301;
0x200000037=0x03070201;
0x200000038=0x03000701:0x03010701:0x03020701;
https://ssl.gstatic.com/accessibility/javascript/android/AndroidVox_v1.js
false
200%
false
true
0
-1
-1
500
0
true
false
false
9
false
0
上面的xml定义中String有一个属性translatable="false"表示多国语言时不需要进行翻译,这里就不对上面的定义一一解释,只对在DatabaseHelper.java中有一个函数来加载.xml中的字段
private void loadSecureSettings(SQLiteDatabase db) {
SQLiteStatement stmt = null;
try {
stmt = db.compileStatement("INSERT OR IGNORE INTO secure(name,value)"
+ " VALUES(?,?);");
loadSetting(stmt, Settings.Secure.LOCATION_PROVIDERS_ALLOWED,
mUtils.getStringValue(Settings.Secure.LOCATION_PROVIDERS_ALLOWED, R.string.def_location_providers_allowed));
String wifiWatchList = SystemProperties.get("ro.com.android.wifi-watchlist");
if (!TextUtils.isEmpty(wifiWatchList)) {
loadSetting(stmt, Settings.Secure.WIFI_WATCHDOG_WATCH_LIST, wifiWatchList);
}
// Don't do this. The SystemServer will initialize ADB_ENABLED from a
// persistent system property instead.
loadSetting(stmt, Settings.Secure.ADB_ENABLED, 1);
// Allow mock locations default, based on build
loadSetting(stmt, Settings.Secure.ALLOW_MOCK_LOCATION,
"1".equals(SystemProperties.get("ro.allow.mock.location")) ? 1 : 0);
loadSecure35Settings(stmt);
loadBooleanSetting(stmt, Settings.Secure.MOUNT_PLAY_NOTIFICATION_SND,
R.bool.def_mount_play_notification_snd);
loadBooleanSetting(stmt, Settings.Secure.MOUNT_UMS_AUTOSTART,
R.bool.def_mount_ums_autostart);
loadBooleanSetting(stmt, Settings.Secure.MOUNT_UMS_PROMPT,
R.bool.def_mount_ums_prompt);
loadBooleanSetting(stmt, Settings.Secure.MOUNT_UMS_NOTIFY_ENABLED,
R.bool.def_mount_ums_notify_enabled);
loadBooleanSetting(stmt, Settings.Secure.ACCESSIBILITY_SCRIPT_INJECTION,
R.bool.def_accessibility_script_injection);
loadStringSetting(stmt, Settings.Secure.ACCESSIBILITY_WEB_CONTENT_KEY_BINDINGS,
R.string.def_accessibility_web_content_key_bindings);
loadIntegerSetting(stmt, Settings.Secure.LONG_PRESS_TIMEOUT,
R.integer.def_long_press_timeout_millis);
loadBooleanSetting(stmt, Settings.Secure.TOUCH_EXPLORATION_ENABLED,
R.bool.def_touch_exploration_enabled);
loadBooleanSetting(stmt, Settings.Secure.ACCESSIBILITY_SPEAK_PASSWORD,
R.bool.def_accessibility_speak_password);
loadStringSetting(stmt, Settings.Secure.ACCESSIBILITY_SCREEN_READER_URL,
R.string.def_accessibility_screen_reader_url);
if (SystemProperties.getBoolean("ro.lockscreen.disable.default", false) == true) {
loadSetting(stmt, Settings.System.LOCKSCREEN_DISABLED, "1");
} else {
loadBooleanSetting(stmt, Settings.System.LOCKSCREEN_DISABLED,
R.bool.def_lockscreen_disabled);
}
loadBooleanSetting(stmt, Settings.Secure.SCREENSAVER_ENABLED,
com.android.internal.R.bool.config_dreamsEnabledByDefault);
loadBooleanSetting(stmt, Settings.Secure.SCREENSAVER_ACTIVATE_ON_DOCK,
com.android.internal.R.bool.config_dreamsActivatedOnDockByDefault);
loadBooleanSetting(stmt, Settings.Secure.SCREENSAVER_ACTIVATE_ON_SLEEP,
com.android.internal.R.bool.config_dreamsActivatedOnSleepByDefault);
loadStringSetting(stmt, Settings.Secure.SCREENSAVER_COMPONENTS,
com.android.internal.R.string.config_dreamsDefaultComponent);
loadStringSetting(stmt, Settings.Secure.SCREENSAVER_DEFAULT_COMPONENT,
com.android.internal.R.string.config_dreamsDefaultComponent);
loadBooleanSetting(stmt, Settings.Secure.ACCESSIBILITY_DISPLAY_MAGNIFICATION_ENABLED,
R.bool.def_accessibility_display_magnification_enabled);
loadFractionSetting(stmt, Settings.Secure.ACCESSIBILITY_DISPLAY_MAGNIFICATION_SCALE,
R.fraction.def_accessibility_display_magnification_scale, 1);
loadBooleanSetting(stmt,
Settings.Secure.ACCESSIBILITY_DISPLAY_MAGNIFICATION_AUTO_UPDATE,
R.bool.def_accessibility_display_magnification_auto_update);
loadBooleanSetting(stmt, Settings.Secure.USER_SETUP_COMPLETE,
R.bool.def_user_setup_complete);
mUtils.loadCustomSecureSettings(stmt);
} finally {
if (stmt != null) stmt.close();
}
}
在上面的代码中有
loadSetting(stmt, Settings.Secure.LOCATION_PROVIDERS_ALLOWED,
mUtils.getStringValue(Settings.Secure.LOCATION_PROVIDERS_ALLOWED, R.string.def_location_providers_allowed));去加载字符串,保存到数据库中,数据库名称为:
private static final String DATABASE_NAME = "settings.db";
static String dbNameForUser(final int userHandle) {
// The owner gets the unadorned db name;
if (userHandle == UserHandle.USER_OWNER) {
return DATABASE_NAME;
} else {
// Place the database in the user-specific data tree so that it's
// cleaned up automatically when the user is deleted.
File databaseFile = new File(
Environment.getUserSystemDirectory(userHandle), DATABASE_NAME);
return databaseFile.getPath();
}
}
public DatabaseHelper(Context context, int userHandle) {
super(context, dbNameForUser(userHandle), null, DATABASE_VERSION);
mContext = context;
mUserHandle = userHandle;
}
来看下是如何读取ContentProvider中的数据,在Setting中就可以使用getContentResolver()去查询对应的字段
当然并不是所有的默认值都是通过读取defaults.xml的,也有的是在DatabaseHelper.java中直接设置
如loadSetting(stmt, Settings.Secure.ADB_ENABLED, 1); 这个ADB Debugging开关就是直接在数据库文件中写入的。
关于USB Debugging 开关也可以在systemui的systemui/usb/StorageNotification.java文件中去设置,可以判断是否有IMEI号
分析代码时如果发现在defaults.xml找不到这一项就直接在DatabaseHelper.java文件中查找。