summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author TreeHugger Robot <treehugger-gerrit@google.com> 2019-01-18 16:57:18 +0000
committer Android (Google) Code Review <android-gerrit@google.com> 2019-01-18 16:57:18 +0000
commitd983c5a06a5515d3ad55b67210bdb2f7de2b303a (patch)
treeb2657191f3e19100a06796b50017e53ef8917170
parentfeccee99fabf0d42564550f2a80463633aabd818 (diff)
parente36968793f88c571dc40497d5223d6f7ab2b9de3 (diff)
Merge "Refactor the user restrictions listener to use a set of changes to user restrictions."
-rw-r--r--packages/SettingsProvider/src/com/android/providers/settings/SettingsProvider.java36
1 files 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 5153f9ea86d1..5105ff46703d 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<String> 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<String> getRestrictionDiff(Bundle prevRestrictions, Bundle newRestrictions) {
+ Set<String> restrictionNames = Sets.newArraySet();
+ restrictionNames.addAll(prevRestrictions.keySet());
+ restrictionNames.addAll(newRestrictions.keySet());
+ Set<String> 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 + ")");