前言
大部分的开关状态都存储在了SettingProvider(设置存储) 的db中,与状态值相关的有三个文件
- /frameworks/base/packages/SettingsProvider/src/com/android/providers/settings/DatabaseHelper.java:该文件中对状态值进行存储
- /frameworks/base/packages/SettingsProvider/res/values/defaults.xml:定义了开关状态的默认值
- /frameworks/base/core/java/android/provider/Settings.java:定义了各开关状态默认值存储时对应的key
Android系统frameworks在开机后会根据defaults.xml配置表生成一个数据库来保存设置功能的一些默认数据,比如默认开启WiFi,默认开启蓝牙等等
Android10版本的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> <!-- --><!--是否让屏幕亮度渐渐变暗 Settings.System.DIM_SCREEN -->
<integer name="def_screen_off_timeout">2147483647</integer> <!--屏幕关闭超时 Settings.System.SCREEN_OFF_TIMEOUT -->
<integer name="def_sleep_timeout">-1</integer> <!--睡眠超时 (该值要比灭屏时间长,因为在休眠之前会先灭屏) Settings.Secure.SLEEP_TIMEOUT -->
<bool name="def_airplane_mode_on">false</bool><!--飞行模式开启 Settings.Global.AIRPLANE_MODE_ON -->
<bool name="def_theater_mode_on">false</bool> <!--剧场模式开启 Settings.Global.THEATER_MODE_ON -->
<!-- Comma-separated list of bluetooth, wifi, and cell. -->
<string name="def_airplane_mode_radios" translatable="false">cell,bluetooth,wifi,nfc,wimax</string> <!-- 开启飞行模式时会关掉的开关列表(通常会包括蓝牙,wifi,nfc等)Settings.Global.AIRPLANE_MODE_RADIOS -->
<string name="airplane_mode_toggleable_radios" translatable="false">bluetooth,wifi,nfc</string> <!-- 飞行模式下用户可以手动开启的开关列表 Settings.Global.AIRPLANE_MODE_TOGGLEABLE_RADIOS -->
<string name="def_bluetooth_disabled_profiles" translatable="false">0</string> <!-- 蓝牙禁用配置文件 -->
<bool name="def_auto_time">true</bool> <!-- 是否从网络自动同步日期、时间、时 Settings.Global.AUTO_TIME -->
<bool name="def_auto_time_zone">true</bool> <!-- 是否从网络自动同步时区 Settings.Global.AUTO_TIME_ZONE -->
<bool name="def_accelerometer_rotation">false</bool> <!-- 是否开启自动旋转(即是否根据加速度传感器旋转屏幕方向) Settings.System.ACCELEROMETER_ROTATION -->
<!-- Default screen brightness, from 0 to 255. 102 is 40%. -->
<integer name="def_screen_brightness">102</integer> <!-- 屏幕默认亮度(取值区间为0–255) Settings.System.SCREEN_BRIGHTNESS -->
<bool name="def_screen_brightness_automatic_mode">false</bool> <!-- 是否开启屏幕亮度的自动调节 Settings.System.SCREEN_BRIGHTNESS_MODE -->
<fraction name="def_window_animation_scale">100%</fraction> <!-- 窗口动画缩放 Settings.System.WINDOW_ANIMATION_SCALE -->
<fraction name="def_window_transition_scale">100%</fraction> <!-- 窗口透明度 Settings.System.TRANSITION_ANIMATION_SCALE -->
<bool name="def_haptic_feedback">true</bool> <!-- 是否开启触摸反馈 Settings.System.HAPTIC_FEEDBACK_ENABLED -->
<bool name="def_bluetooth_on">true</bool> <!-- 默认是否开启蓝牙 Settings.Global.BLUETOOTH_ON -->
<bool name="def_wifi_display_on">false</bool> <!-- 是否开启wifi显示 Settings.Global.WIFI_DISPLAY_ON -->
<bool name="def_install_non_market_apps">false</bool> <!-- 是否允许安装不是在应用市场下载的app Settings.Secure.INSTALL_NON_MARKET_APPS -->
<bool name="def_package_verifier_enable">true</bool> <!-- 在安装app之前进行证书检查 Settings.Global.PACKAGE_VERIFIER_ENABLE -->
<!-- 0 == off, 3 == on -->
<integer name="def_location_mode">3</integer> <!-- 定位模式 0 == 关, 3 == 开 -->
<bool name="assisted_gps_enabled">true</bool> <!-- 是否开启辅助的gps应用 Settings.Global.ASSISTED_GPS_ENABLED -->
<bool name="def_netstats_enabled">true</bool> <!-- 是否开启流量统计 Settings.Global.NETSTATS_ENABLED -->
<bool name="def_usb_mass_storage_enabled">true</bool> <!-- 是否启用USB大容量存储 Settings.Global.USB_MASS_STORAGE_ENABLED -->
<bool name="def_wifi_on">false</bool> <!-- wifi默认是否开启 Settings.Global.WIFI_ON -->
<!-- 0 == never, 1 == only when plugged in, 2 == always -->
<integer name="def_wifi_sleep_policy">2</integer> <!-- wifi是否休眠(会和移动网络来回切换)取值为0-从来不, 1-仅在插入时, 2-总是 Settings.Global.WIFI_SLEEP_POLICY-->
<bool name="def_wifi_wakeup_enabled">true</bool> <!-- 是否启用wifi唤醒 -->
<bool name="def_networks_available_notification_on">true</bool> <!-- 是否通知用户打开网络 Settings.Global.WIFI_NETWORKS_AVAILABLE_NOTIFICATION_ON -->
<bool name="def_backup_enabled">false</bool> <!-- 是否开启设置备份 Settings.Secure.BACKUP_ENABLED -->
<string name="def_backup_transport" translatable="false">com.android.localtransport/.LocalTransport</string> <!-- 用于备份或者恢复的传输文件 Settings.Secure.BACKUP_TRANSPORT -->
<!-- Default value for whether or not to pulse the notification LED when there is a
pending notification -->
<bool name="def_notification_pulse">true</bool> <!-- 当有通知来时,led灯是否要重复闪烁 Settings.System.NOTIFICATION_LIGHT_PULSE -->
<bool name="def_mount_play_notification_snd">true</bool> <!-- 当有事件来临时是否播放通知铃声 Settings.Secure.MOUNT_PLAY_NOTIFICATION_SND -->
<bool name="def_mount_ums_autostart">false</bool> <!-- 是否自动启动主机检测系统 Settings.Secure.MOUNT_UMS_AUTOSTART -->
<bool name="def_mount_ums_prompt">true</bool> <!-- 是否在主机检测时显示通知 Settings.Secure.MOUNT_UMS_PROMPT -->
<bool name="def_mount_ums_notify_enabled">true</bool> <!-- 当开启ums时是否显示通知 Settings.Secure.MOUNT_UMS_NOTIFY_ENABLED -->
<!-- user interface sound effects 用户界面音效 -->
<integer name="def_power_sounds_enabled">1</integer> <!-- 电量过低时是否铃声通知 Settings.Global.POWER_SOUNDS_ENABLED -->
<string name="def_low_battery_sound" translatable="false">/product/media/audio/ui/LowBattery.ogg</string> <!-- 低电量时播放的铃声文件来源 Settings.Global.LOW_BATTERY_SOUND -->
<integer name="def_dock_sounds_enabled">0</integer> <!-- 当插拔电源时是否播放声音 Settings.Global.DOCK_SOUNDS_ENABLED -->
<integer name="def_dock_sounds_enabled_when_accessibility">0</integer> <!--可访问性时启用停靠声音-->
<string name="def_desk_dock_sound" translatable="false">/product/media/audio/ui/Dock.ogg</string> <!-- 插上电源时播放的音频文件 Settings.Global.DESK_DOCK_SOUND -->
<string name="def_desk_undock_sound" translatable="false">/product/media/audio/ui/Undock.ogg</string> <!-- 拔下电源时播放的音频文件 Settings.Global.DESK_UNDOCK_SOUND -->
<string name="def_car_dock_sound" translatable="false">/product/media/audio/ui/Dock.ogg</string> <!-- 使用车载电源充电时播放的音频文件 Settings.Global.CAR_DOCK_SOUND -->
<string name="def_car_undock_sound" translatable="false">/product/media/audio/ui/Undock.ogg</string> <!-- 当从车载电源拔下时播放的音频文件 Settings.Global.CAR_UNDOCK_SOUND -->
<integer name="def_lockscreen_sounds_enabled">1</integer> <!-- 当解锁或是锁屏时是否播放声音 Settings.System.LOCKSCREEN_SOUNDS_ENABLED -->
<string name="def_lock_sound" translatable="false">/product/media/audio/ui/Lock.ogg</string> <!-- 锁屏时播放的音频文件 Settings.Global.LOCK_SOUND -->
<string name="def_unlock_sound" translatable="false">/product/media/audio/ui/Unlock.ogg</string> <!-- 解锁时播放的音频文件 Settings.Global.UNLOCK_SOUND -->
<string name="def_trusted_sound" translatable="false">/product/media/audio/ui/Trusted.ogg</string> <!-- 在未解锁的情况下设备进入到可信任状态时播放的音频文件 Settings.Global.TRUSTED_SOUND -->
<string name="def_wireless_charging_started_sound" translatable="false">/product/media/audio/ui/WirelessChargingStarted.ogg</string> <!-- 开启无线充电时播放声音 Settings.Global.WIRELESS_CHARGING_STARTED_SOUND -->
<string name="def_charging_started_sound" translatable="false">/product/media/audio/ui/ChargingStarted.ogg</string> <!-- 充电开始时播放声音 -->
<!-- sound trigger detection service default values -->
<integer name="def_max_sound_trigger_detection_service_ops_per_day" translatable="false">1000</integer> <!-- 每天最大声音触发检测服务操作次数 -->
<integer name="def_sound_trigger_detection_service_op_timeout" translatable="false">15000</integer> <!-- 声音触发检测服务操作超时 -->
<bool name="def_lockscreen_disabled">false</bool> <!-- 默认锁屏已禁用 -->
<bool name="def_device_provisioned">false</bool> <!-- 设备是否已经被配置(该参数考虑的时多用户不同时刻使用同一个设备的情况 Settings.Global.DEVICE_PROVISIONED -->
<integer name="def_dock_audio_media_enabled">1</integer> <!-- 使用dock音频输出媒体 Settings.Global.DOCK_AUDIO_MEDIA_ENABLED -->
<!-- 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> <!-- 静音模式下是否允许震动 Settings.System.VIBRATE_IN_SILENT -->
<!-- Default for Settings.Secure.SYNC_PARENT_SOUNDS -->
<bool name="def_sync_parent_sounds">true</bool> <!-- 同步父声音 -->
<!-- Default for Settings.Secure.ACCESSIBILITY_SPEAK_PASSWORD -->
<bool name="def_accessibility_speak_password">true</bool> <!-- 访问模式下是否语音播报密码 Settings.Secure.ACCESSIBILITY_SPEAK_PASSWORD -->
<!-- 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">180</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">400</integer> <!-- 长按超时毫秒 -->
<!-- Default for Settings.Secure.MULTI_PRESS_TIMEOUT -->
<integer name="def_multi_press_timeout_millis">300</integer> <!-- 多按超时毫秒 -->
<!-- Default for Settings.Secure.SHOW_IME_WITH_HARD_KEYBOARD -->
<bool name="def_show_ime_with_hard_keyboard">false</bool> <!-- 默认开启“显示输入法”开关 -->
<!-- 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> <!-- dtmf 音调已启用 -->
<!-- Default for UI touch sounds enabled -->
<bool name="def_sound_effects_enabled">true</bool> <!-- 启用def音效 -->
<!-- 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> <!-- 最大dhcp重试次数 -->
<!-- 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> <!-- 当经过一定时间后,如果低电量提醒为播放声音,则灭屏 Settings.Global.LOW_BATTERY_SOUND_TIMEOUT -->
<!-- Initial value for the Settings.Secure.IMMERSIVE_MODE_CONFIRMATIONS setting,
which is a comma separated list of packages that no longer need confirmation
for immersive mode.
Override to disable immersive mode confirmation for certain packages. -->
<string name="def_immersive_mode_confirmations" translatable="false"></string> <!-- 沉浸式模式确认 -->
<!-- Default for Settings.Global.WIFI_SCAN_ALWAYS_AVAILABLE -->
<integer name="def_wifi_scan_always_available">0</integer> <!-- 设置-wlan-高级-随时扫描开关 -->
<!-- Default for Settings.Secure.LOCK_SCREEN_SHOW_NOTIFICATIONS, 1==on -->
<integer name="def_lock_screen_show_notifications">1</integer> <!-- 是否在锁屏界面显示通知 -->
<!-- Default for Settings.Secure.LOCK_SCREEN_ALLOW_PRIVATE_NOTIFICATIONS -->
<bool name="def_lock_screen_allow_private_notifications">true</bool> <!-- 允许在锁屏界面上显示私有通知,就像是解锁状态下一样 -->
<!-- Default for Settings.Global.HEADS_UP_NOTIFICATIONS_ENABLED, 1==on -->
<integer name="def_heads_up_enabled">1</integer> <!-- 启用抬头 -->
<!-- Default for Settings.Global.DEVICE_NAME $1=MANUFACTURER $2=MODEL-->
<string name="def_device_name">%1$s %2$s</string> <!-- 设备名称 -->
<!-- Default for Settings.Global.DEVICE_NAME $1=MODEL-->
<string name="def_device_name_simple">%1$s</string> <!-- 设备名称简单 -->
<!-- Default for Settings.Secure.WAKE_GESTURE_ENABLED -->
<bool name="def_wake_gesture_enabled">true</bool> <!-- 启用唤醒手势 -->
<!-- Default state of tap to wake -->
<bool name="def_double_tap_to_wake">true</bool> <!-- 双击唤醒 -->
<!-- Default for Settings.Secure.NFC_PAYMENT_COMPONENT -->
<string name="def_nfc_payment_component"></string> <!-- NFC支付组件 -->
<!-- Default setting for ability to add users from the lock screen -->
<bool name="def_add_users_from_lockscreen">false</bool> <!-- 从锁屏添加用户 -->
<!-- default setting for Settings.System.END_BUTTON_BEHAVIOR : END_BUTTON_BEHAVIOR_SLEEP -->
<integer name="def_end_button_behavior">0x2</integer> <!-- 结束按钮行为 -->
<!-- default setting for Settings.Global.DEFAULT_RESTRICT_BACKGROUND_DATA -->
<bool name="def_restrict_background_data">false</bool> <!-- 限制背景数据 -->
<!-- Default for Settings.Secure.BACKUP_MANAGER_CONSTANTS -->
<string name="def_backup_manager_constants"></string> <!-- 备份管理器常量 -->
<!-- Default setting for Settings.Global.MOBILE_DATA_ALWAYS_ON -->
<bool name="def_mobile_data_always_on">true</bool> <!-- 移动数据始终开启 -->
<!-- Default for Settings.Secure.BACKUP_LOCAL_TRANSPORT_PARAMETERS -->
<string name="def_backup_local_transport_parameters"></string> <!-- 备份本地传输参数 -->
<!-- Default for Settings.Global.ZEN_DURATION
If 0, turning on dnd manually will last indefinitely.
Else if non-negative, turning on dnd manually will last for this many minutes.
Else (if negative), turning on dnd manually will surface a dialog that prompts
user to specify a duration.-->
<integer name="def_zen_duration">0</integer> <!-- -->
<!-- Default for Settings.Global.BACKUP_AGENT_TIMEOUT_PARAMETERS -->
<string name="def_backup_agent_timeout_parameters"></string> <!-- 备份代理超时参数 -->
<!-- Default for Settings.System.VIBRATE_WHEN_RINGING -->
<bool name="def_vibrate_when_ringing">false</bool> <!-- 响铃时振动 -->
<!-- Default for Settings.Global.APPLY_RAMPING_RINGER -->
<bool name="def_apply_ramping_ringer">false</bool> <!-- 应用斜坡振铃器 -->
<!-- Default for Settings.Secure.CHARGING_VIBRATION_ENABLED -->
<bool name="def_charging_vibration_enabled">true</bool> <!-- 启用充电振动 -->
<!-- Default for Settings.Secure.CHARGING_SOUNDS_ENABLED -->
<bool name="def_charging_sounds_enabled">true</bool> <!-- 启用充电声音 -->
<!-- Default for Settings.Secure.NOTIFICATION_BUBBLES -->
<bool name="def_notification_bubbles">false</bool> <!-- 通知气泡 -->
<!-- Default for Settings.Secure.AWARE_ENABLED -->
<bool name="def_aware_enabled">false</bool> <!-- 启用默认感知 -->
<!-- Default for Settings.Secure.SKIP_GESTURE -->
<bool name="def_skip_gesture">false</bool> <!-- 跳过手势 -->
<!-- Default for Settings.Secure.SILENCE_GESTURE -->
<bool name="def_silence_gesture">false</bool> <!-- 沉默手势 -->
<!-- Default for Settings.Secure.AWARE_LOCK_ENABLED -->
<bool name="def_aware_lock_enabled">false</bool> <!-- 启用感知锁 -->
</resources>
修改设备成不灭屏状态
欸为什么是0x7fffffff 换算 十进制 是2147483647
ro.rk.screenoff_time 也是2147483647
整形最大取值就是 2147483647 换算成天数也就是24.85
<bool name="def_dim_screen">true</bool>
<integer name="def_screen_off_timeout">0x7fffffff</integer>
<integer name="def_sleep_timeout">-1</integer>
End