Android「Global / Secure / System」三大命名空间全局设置项总结

发布于:2025-09-15 ⋅ 阅读:(21) ⋅ 点赞:(0)

Android「Global / Secure / System」三大命名空间下常见的可写设置项(如动画缩放、屏幕亮度、安装未知来源、输入法、定位、音量、飞行模式、锁屏、字体、DPI、NTP、Wi-Fi 休眠策略等),但尚未找到一份官方、穷尽的「所有全局可设置项」清单。由于 Android 版本碎片化严重,OEM 厂商还会自定义键名,想一次性“全部”列全必须拿到各版本系统源码中的 Settings.javadefaults.xml,再与 /data/system/users/0/settings_*.xml 运行时快照交叉对比,才能确保无遗漏。


一、Global 命名空间(Settings.Global.put*)

key 名 取值示例 备注
airplane_mode_on 0 / 1 飞行模式开关
wifi_on 0 / 1 Wi-Fi 总开关
mobile_data 0 / 1 移动数据总开关
bluetooth_on 0 / 1 蓝牙总开关
ntp_server pool.ntp.org NTP 服务器
auto_time 0 / 1 自动同步网络时间
auto_time_zone 0 / 1 自动同步时区
development_settings_enabled 0 / 1 开发者选项是否可见
adb_enabled 0 / 1 USB 调试开关
window_animation_scale 0.0f 窗口动画缩放
transition_animation_scale 0.0f 过渡动画缩放
animator_duration_scale 0.0f 动画程序时长缩放
wifi_sleep_policy 2 0=关屏休眠 1=关屏保持 2=永不休眠
install_non_market_apps 0 / 1 允许安装未知来源
lockscreen_disabled 0 / 1 禁用锁屏(需 root/系统签)
ota_updates_available 0 / 1 系统更新可用标记
app_data_usage_limit 字节数 后台流量限额
wireless_display_on 0 / 1 无线显示(Miracast)开关

二、Secure 命名空间(Settings.Secure.put*)

key 名 取值示例 备注
location_mode 0 / 1 / 2 / 3 0=关 1=仅设备 2=仅网络 3=高精度
location_providers_allowed +gps / -gps 增减定位提供者
install_non_market_apps 0 / 1 同 Global,优先级更高
default_input_method 包名/类名 默认输入法
enabled_input_methods 同上,分号分隔 已启用输入法列表
spell_checker_enabled 0 / 1 拼写检查
android_id 16 位 hex 设备唯一 ID(只读)
show_ime_with_hard_keyboard 0 / 1 物理键盘弹出软键盘
display_density_forced 440 强制 DPI(需 root)
screenshot_button_show 0 / 1 三指截屏开关(部分 ROM)

三、System 命名空间(Settings.System.put*)

key 名 取值示例 备注
screen_brightness 0-255 手动亮度级别
screen_brightness_mode 0 / 1 0=手动 1=自动
screen_off_timeout 毫秒 休眠时间
accelerometer_rotation 0 / 1 自动旋转
haptic_feedback_enabled 0 / 1 触摸振动
sound_effects_enabled 0 / 1 触摸提示音
notification_light_pulse 0 / 1 通知灯闪烁
font_scale 1.0f 字体缩放(0.85-1.3)
volume_music / ring / alarm / notification 0-15 各通道音量
screenshot_button_show 0 / 1 部分 ROM 放在 System

四、如何自己“补全”官方全量列表

  1. 拉取 AOSP 源码
    repo init -u https://android.googlesource.com/platform/manifest -b android14-release

  2. 检索定义文件

    • frameworks/base/core/java/android/provider/Settings.java

    • frameworks/base/packages/SettingsProvider/res/values/defaults.xml

  3. 查看运行时键值
    adb shell settings list global > g.txt
    adb shell settings list secure > s.txt
    adb shell settings list system > t.txt

  4. 交叉比对即可得到该版本该设备真正支持的全部键名与默认值。


五、使用示例

// Global
Settings.Global.putFloat(resolver, Global.WINDOW_ANIMATION_SCALE, 0.0f);
Settings.Global.putInt(resolver, "install_non_market_apps", 1);

// Secure
Settings.Secure.putInt(resolver, Secure.SHOW_IME_WITH_HARD_KEYBOARD, 1);
Settings.Secure.putInt(resolver, Secure.LOCATION_MODE, 3);

// System
Settings.System.putInt(resolver, System.SCREEN_BRIGHTNESS, 200);
Settings.System.putInt(resolver, "screenshot_button_show", 1);

六、注意事项

  • Android 8.0+ 对非系统应用禁止写 Global/Secure;普通 App 只能写 System,且需 android.permission.WRITE_SETTINGS

  • 部分 OEM 键名(如小米、华为)在 AOSP 里找不到,需抓取其 framework.jar 反编译。

  • 修改前建议 settings get 先备份原值,以便恢复。