android 11 默认打开app pinning 功能

需要修改settings默认值,主要流程如下:

1,frameworks\base\packages\SettingsProvider\res\values\defaults.xml添加lock_to_app_enabled默认值:

1

2,frameworks\base\packages\SettingsProvider\src\com\android\providers\settings\SettingsProvider.java加入设置默认值的代码:

--- a/frameworks/base/packages/SettingsProvider/src/com/android/providers/settings/SettingsProvider.java
+++ b/frameworks/base/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 = 191;
+            private static final int SETTINGS_VERSION = 192;

             private final int mUserId;

@@ -4881,6 +4881,18 @@ public class SettingsProvider extends ContentProvider {
                     }
                     currentVersion = 191;
                 }
+                if (currentVersion == 191){
+                    SettingsState systemSettings = getSystemSettingsLocked(userId);
+                    final Setting currentSetting = systemSettings.getSettingLocked(
+                              Settings.System.LOCK_TO_APP_ENABLED);
+                    if (currentSetting.isNull()) {
+                        systemSettings.insertSettingOverrideableByRestoreLocked(
+                                    Settings.System.LOCK_TO_APP_ENABLED,
+   Integer.toString(getContext().getResources().
+    getInteger(R.integer.lock_to_app_enabled)),
+                                     null, true, SettingsState.SYSTEM_PACKAGE_NAME);
+                    }
+                    currentVersion = 192;
+                }

                 // vXXX: Add new settings above this point.


PS:需要注意“currentVersion == 191”该项是往上递增的,新增一项就需要往上+1。并且private static final int SETTINGS_VERSION = 192;该项也需要改成现在的最大值,不然会有意想不到的bug出现。

你可能感兴趣的:(android 11 默认打开app pinning 功能)