From e36968793f88c571dc40497d5223d6f7ab2b9de3 Mon Sep 17 00:00:00 2001 From: Irina Dumitrescu Date: Wed, 9 Jan 2019 16:07:59 +0000 Subject: Refactor the user restrictions listener to use a set of changes to user restrictions. Change-Id: I75eabfd4ca3654bb2ac9f1cf164865105400bce5 Fixes: 117104028 Test: manual. --- .../providers/settings/SettingsProvider.java | 36 ++++++++++++++-------- 1 file changed, 23 insertions(+), 13 deletions(-) diff --git a/packages/SettingsProvider/src/com/android/providers/settings/SettingsProvider.java b/packages/SettingsProvider/src/com/android/providers/settings/SettingsProvider.java index bce559396ddd..87ecb7ddb211 100644 --- a/packages/SettingsProvider/src/com/android/providers/settings/SettingsProvider.java +++ b/packages/SettingsProvider/src/com/android/providers/settings/SettingsProvider.java @@ -84,6 +84,8 @@ import com.android.providers.settings.SettingsState.Setting; import com.android.server.LocalServices; import com.android.server.SystemConfig; +import com.google.android.collect.Sets; + import java.io.File; import java.io.FileDescriptor; import java.io.FileNotFoundException; @@ -957,12 +959,12 @@ public class SettingsProvider extends ContentProvider { UserManagerInternal userManager = LocalServices.getService(UserManagerInternal.class); userManager.addUserRestrictionsListener((int userId, Bundle newRestrictions, Bundle prevRestrictions) -> { + Set changedRestrictions = getRestrictionDiff(prevRestrictions, newRestrictions); // We are changing the settings affected by restrictions to their current // value with a forced update to ensure that all cross profile dependencies // are taken into account. Also make sure the settings update to.. the same // value passes the security checks, so clear binder calling id. - if (newRestrictions.getBoolean(UserManager.DISALLOW_SHARE_LOCATION) - != prevRestrictions.getBoolean(UserManager.DISALLOW_SHARE_LOCATION)) { + if (changedRestrictions.contains(UserManager.DISALLOW_SHARE_LOCATION)) { final long identity = Binder.clearCallingIdentity(); try { synchronized (mLock) { @@ -976,11 +978,8 @@ public class SettingsProvider extends ContentProvider { Binder.restoreCallingIdentity(identity); } } - if (newRestrictions.getBoolean(UserManager.DISALLOW_INSTALL_UNKNOWN_SOURCES) - != prevRestrictions.getBoolean(UserManager.DISALLOW_INSTALL_UNKNOWN_SOURCES) || - newRestrictions.getBoolean( - UserManager.DISALLOW_INSTALL_UNKNOWN_SOURCES_GLOBALLY) - != prevRestrictions.getBoolean( + if (changedRestrictions.contains(UserManager.DISALLOW_INSTALL_UNKNOWN_SOURCES) + || changedRestrictions.contains( UserManager.DISALLOW_INSTALL_UNKNOWN_SOURCES_GLOBALLY)) { final long identity = Binder.clearCallingIdentity(); try { @@ -994,8 +993,7 @@ public class SettingsProvider extends ContentProvider { Binder.restoreCallingIdentity(identity); } } - if (newRestrictions.getBoolean(UserManager.DISALLOW_DEBUGGING_FEATURES) - != prevRestrictions.getBoolean(UserManager.DISALLOW_DEBUGGING_FEATURES)) { + if (changedRestrictions.contains(UserManager.DISALLOW_DEBUGGING_FEATURES)) { final long identity = Binder.clearCallingIdentity(); try { synchronized (mLock) { @@ -1008,8 +1006,7 @@ public class SettingsProvider extends ContentProvider { Binder.restoreCallingIdentity(identity); } } - if (newRestrictions.getBoolean(UserManager.ENSURE_VERIFY_APPS) - != prevRestrictions.getBoolean(UserManager.ENSURE_VERIFY_APPS)) { + if (changedRestrictions.contains(UserManager.ENSURE_VERIFY_APPS)) { final long identity = Binder.clearCallingIdentity(); try { synchronized (mLock) { @@ -1028,8 +1025,7 @@ public class SettingsProvider extends ContentProvider { Binder.restoreCallingIdentity(identity); } } - if (newRestrictions.getBoolean(UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS) - != prevRestrictions.getBoolean(UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) { + if (changedRestrictions.contains(UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) { final long identity = Binder.clearCallingIdentity(); try { synchronized (mLock) { @@ -1046,6 +1042,20 @@ public class SettingsProvider extends ContentProvider { }); } + private static Set getRestrictionDiff(Bundle prevRestrictions, Bundle newRestrictions) { + Set restrictionNames = Sets.newArraySet(); + restrictionNames.addAll(prevRestrictions.keySet()); + restrictionNames.addAll(newRestrictions.keySet()); + Set diff = Sets.newArraySet(); + for (String restrictionName : restrictionNames) { + if (prevRestrictions.getBoolean(restrictionName) != newRestrictions.getBoolean( + restrictionName)) { + diff.add(restrictionName); + } + } + return diff; + } + private Setting getConfigSetting(String name) { if (DEBUG) { Slog.v(LOG_TAG, "getConfigSetting(" + name + ")"); -- cgit v1.2.3-59-g8ed1b