Android 在frameworks中修改Setting中的默认值(一)

来源:互联网 发布:淘宝商品详情页模板 编辑:程序博客网 时间:2024/05/30 13:42

在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中定义了哪些值

<?xml version="1.0" encoding="utf-8"?><!--/** * Copyright (c) 2009, The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * *     http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */--><resources>    <bool name="def_dim_screen">true</bool>    <integer name="def_screen_off_timeout">60000</integer>    <bool name="def_airplane_mode_on">false</bool>    <!-- Comma-separated list of bluetooth, wifi, and cell. -->    <string name="def_airplane_mode_radios" translatable="false">cell,bluetooth,wifi,nfc,wimax</string>    <string name="airplane_mode_toggleable_radios" translatable="false">bluetooth,wifi,nfc</string>    <bool name="def_auto_time">true</bool>    <bool name="def_auto_time_zone">true</bool>    <bool name="def_accelerometer_rotation">true</bool>    <!-- Default screen brightness, from 0 to 255.  102 is 40%. -->    <integer name="def_screen_brightness">102</integer>    <bool name="def_screen_brightness_automatic_mode">false</bool>    <fraction name="def_window_animation_scale">100%</fraction>    <fraction name="def_window_transition_scale">100%</fraction>    <bool name="def_haptic_feedback">true</bool>    <bool name="def_bluetooth_on">false</bool>    <bool name="def_wifi_display_on">false</bool>    <bool name="def_install_non_market_apps">false</bool>    <bool name="def_package_verifier_enable">true</bool>    <!-- Comma-separated list of location providers.         Network location is off by default because it requires         user opt-in via Setup Wizard or Settings.    -->    <string name="def_location_providers_allowed" translatable="false">gps</string>    <bool name="assisted_gps_enabled">true</bool>    <bool name="def_netstats_enabled">true</bool>    <bool name="def_usb_mass_storage_enabled">true</bool>    <bool name="def_wifi_on">false</bool>    <!-- 0 == never, 1 == only when plugged in, 2 == always -->    <integer name="def_wifi_sleep_policy">2</integer>    <bool name="def_networks_available_notification_on">true</bool>    <bool name="def_backup_enabled">false</bool>    <!--string name="def_backup_transport" translatable="false">android/com.android.internal.backup.LocalTransport</string-->    <string name="def_backup_transport" translatable="false">com.google.android.backup/.BackupTransportService</string>    <!-- Default value for whether or not to pulse the notification LED when there is a         pending notification -->    <bool name="def_notification_pulse">true</bool>    <bool name="def_mount_play_notification_snd">true</bool>    <bool name="def_mount_ums_autostart">false</bool>    <bool name="def_mount_ums_prompt">true</bool>    <bool name="def_mount_ums_notify_enabled">true</bool>    <!-- user interface sound effects -->    <integer name="def_power_sounds_enabled">1</integer>    <string name="def_low_battery_sound" translatable="false">/system/media/audio/ui/LowBattery.ogg</string>    <integer name="def_dock_sounds_enabled">0</integer>    <string name="def_desk_dock_sound" translatable="false">/system/media/audio/ui/Dock.ogg</string>    <string name="def_desk_undock_sound" translatable="false">/system/media/audio/ui/Undock.ogg</string>    <string name="def_car_dock_sound" translatable="false">/system/media/audio/ui/Dock.ogg</string>    <string name="def_car_undock_sound" translatable="false">/system/media/audio/ui/Undock.ogg</string>    <integer name="def_lockscreen_sounds_enabled">1</integer>    <string name="def_lock_sound" translatable="false">/system/media/audio/ui/Lock.ogg</string>    <string name="def_unlock_sound" translatable="false">/system/media/audio/ui/Unlock.ogg</string>    <string name="def_wireless_charging_started_sound" translatable="false">/system/media/audio/ui/WirelessChargingStarted.ogg</string>    <bool name="def_lockscreen_disabled">false</bool>    <bool name="def_device_provisioned">false</bool>    <integer name="def_dock_audio_media_enabled">1</integer>    <!-- Notifications use ringer volume -->    <bool name="def_notifications_use_ring_volume">true</bool>    <!-- Default for Settings.System.VIBRATE_IN_SILENT -->    <bool name="def_vibrate_in_silent">true</bool>    <!-- Default for Settings.Secure.ACCESSIBILITY_SCRIPT_INJECTION -->    <bool name="def_accessibility_script_injection">false</bool>    <!-- Default for Settings.Secure.ACCESSIBILITY_SPEAK_PASSWORD -->    <bool name="def_accessibility_speak_password">false</bool>    <!-- Default for Settings.Secure.ACCESSIBILITY_WEB_CONTENT_KEY_BINDINGS -->    <string name="def_accessibility_web_content_key_bindings" translatable="false">            <!-- DPAD/Trackball UP - traverse previous on current axis and send an event. -->            0x13=0x01000100;            <!-- DPAD/Trackball DOWN - traverse next on current axis and send an event. -->            0x14=0x01010100;            <!-- DPAD/Trackball LEFT - traverse previous on the character navigation axis and send event. -->            0x15=0x02000001;            <!-- DPAD/Trackball RIGHT - traverse next on the character navigation axis end send event. -->            0x16=0x02010001;            <!-- Alt+DPAD/Trackball UP - go to the top of the document. -->            0x200000013=0x02000601;            <!-- Alt+DPAD/Trackball DOWN - go to the bottom of the document. -->            0x200000014=0x02010601;            <!-- Alt+DPAD/Trackball LEFT - transition from an axis to another and sends an event.-->            <!-- Axis transitions: 2 -> 1; -->            0x200000015=0x03020101;            <!-- Alt+DPAD/Trackball RIGHT - transition from an axis to another and sends an event. -->            <!-- Axis transitions:  1 -> 2; -->            0x200000016=0x03010201;            <!-- Alt+g - go to the previous heading and send an event. -->            0x200000023=0x02000301;            <!-- Alt+h - go to the next heading and send an event. -->            0x200000024=0x02010301;            <!-- Alt+COMMA - transition to sentence navigation axis and send an event. -->            <!-- Axis transitions:  7 -> 2; -->            0x200000037=0x03070201;            <!-- Alt+PERIOD - transition to default web view behavior axis and send an event. -->            <!-- Axis transitions:  0 -> 7; 1 - > 7; 2 -> 7; -->            0x200000038=0x03000701:0x03010701:0x03020701;    </string>    <!-- Default for Settings.Secure.ACCESSIBILITY_SCRIPT_INJECTION_URL -->    <string name="def_accessibility_screen_reader_url" translatable="false">        https://ssl.gstatic.com/accessibility/javascript/android/AndroidVox_v1.js    </string>    <!-- Default for Settings.Secure.TOUCH_EXPLORATION_ENABLED -->    <bool name="def_touch_exploration_enabled">false</bool>    <!-- Default value for Settings.Secure.ACCESSIBILITY_DISPLAY_MAGNIFICATION_SCALE -->    <fraction name="def_accessibility_display_magnification_scale">200%</fraction>    <!-- Default value for Settings.Secure.ACCESSIBILITY_DISPLAY_MAGNIFICATION_ENABLED -->    <bool name="def_accessibility_display_magnification_enabled">false</bool>    <!-- Default value for Settings.Secure.ACCESSIBILITY_DISPLAY_MAGNIFICATION_AUTO_UPDATE -->    <bool name="def_accessibility_display_magnification_auto_update">true</bool>    <!-- Default for Settings.System.USER_ROTATION -->    <integer name="def_user_rotation">0</integer>    <!-- Default for Settings.Secure.DOWNLOAD_MAX_BYTES_OVER_MOBILE. <=0 if no limit -->    <integer name="def_download_manager_max_bytes_over_mobile">-1</integer>    <!-- Default for Settings.Secure.DOWNLOAD_RECOMMENDED_MAX_BYTES_OVER_MOBILE. <=0 if no limit -->    <integer name="def_download_manager_recommended_max_bytes_over_mobile">-1</integer>    <!-- Default for Settings.Secure.LONG_PRESS_TIMEOUT_MILLIS -->    <integer name="def_long_press_timeout_millis">500</integer>    <!-- Default for Settings.System.POINTER_SPEED -->    <integer name="def_pointer_speed">0</integer>    <!-- Default for DTMF tones enabled -->    <bool name="def_dtmf_tones_enabled">true</bool>    <!-- M: Default for UI touch sounds disabled ,google defaulit is enable -->    <bool name="def_sound_effects_enabled">false</bool>    <!-- Development settings -->    <bool name="def_stay_on_while_plugged_in">false</bool>    <!-- Number of retries for connecting to DHCP.         Value here is the same as WifiStateMachine.DEFAULT_MAX_DHCP_RETRIES -->    <integer name="def_max_dhcp_retries">9</integer>    <!-- Default for Settings.Secure.USER_SETUP_COMPLETE -->    <bool name="def_user_setup_complete">false</bool>    <!-- Default for Settings.Global.LOW_BATTERY_SOUND_TIMEOUT.         0 means no timeout; battery sounds will always play         >0 is milliseconds of screen-off time after which battery sounds will not play -->    <integer name="def_low_battery_sound_timeout">0</integer></resources>
上面的xml定义中String有一个属性translatable="false"表示多国语言时不需要进行翻译,这里就不对上面的定义一一解释,只对<string name="def_location_providers_allowed" translatable="false">gps</string>进行分析

在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文件中查找。


2 0
原创粉丝点击