Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit d983c5a0 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Refactor the user restrictions listener to use a set of changes to user restrictions."

parents feccee99 e3696879
Loading
Loading
Loading
Loading
+23 −13
Original line number Diff line number Diff line
@@ -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 + ")");