Android11 通过升级Settings数据强制覆盖用户的设置项

硬件:QCS6125

软件:Android 11

需求:设备通过OTA升级,强制修改用户的settings键值;

直接上改动,通过升级Settings的API level去做处理:

--- a/packages/SettingsProvider/src/com/android/providers/settings/SettingsProvider.java
+++ b/packages/SettingsProvider/src/com/android/providers/settings/SettingsProvider.java
@@ -3513,7 +3513,7 @@ public class SettingsProvider extends ContentProvider {
         }
 
         private final class UpgradeController {
-            private static final int SETTINGS_VERSION = 192;
+            private static final int SETTINGS_VERSION = 193;
 
             private final int mUserId;
 
@@ -4911,6 +4911,25 @@ public class SettingsProvider extends ContentProvider {
                     currentVersion = 192;
                  }
 
+                if (currentVersion == 192) {
+                    final SettingsState globalSettings = getGlobalSettingsLocked();
+                    globalSettings.insertSettingOverrideableByRestoreLocked(
+                            Global.AIRPLANE_MODE_ON,
+                            getContext().getResources().getBoolean(
+                                    R.bool.def_airplane_mode_on) ? "1" : "0",
+                            null, true, SettingsState.SYSTEM_PACKAGE_NAME);
+
+                    globalSettings.insertSettingOverrideableByRestoreLocked(
+                            Global.BLUETOOTH_ON,
+                            getContext().getResources().getBoolean(
+                                    R.bool.def_bluetooth_on) ? "1" : "0",
+                            null, true, SettingsState.SYSTEM_PACKAGE_NAME);
+                    currentVersion = 193;
+                 }
+
                 // vXXX: Add new settings above this point.
 
                 if (currentVersion != newVersion) {

编译SettingsProvider安装验证即可。

你可能感兴趣的:(android,settingsProvide,upgrade,settings,framework)