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

Commit b4ec8aaa authored by Makoto Onuki's avatar Makoto Onuki Committed by Android (Google) Code Review
Browse files

Merge "Revert "Throw for unknown user restrictions.""

parents 33e0a5f7 2ec157d9
Loading
Loading
Loading
Loading
+0 −3
Original line number Original line Diff line number Diff line
@@ -930,7 +930,6 @@ public class UserManagerService extends IUserManager.Stub {
    /** @return a specific user restriction that's in effect currently. */
    /** @return a specific user restriction that's in effect currently. */
    @Override
    @Override
    public boolean hasUserRestriction(String restrictionKey, int userId) {
    public boolean hasUserRestriction(String restrictionKey, int userId) {
        UserRestrictionsUtils.checkRestriction(restrictionKey);
        Bundle restrictions = getEffectiveUserRestrictions(userId);
        Bundle restrictions = getEffectiveUserRestrictions(userId);
        return restrictions != null && restrictions.getBoolean(restrictionKey);
        return restrictions != null && restrictions.getBoolean(restrictionKey);
    }
    }
@@ -947,7 +946,6 @@ public class UserManagerService extends IUserManager.Stub {
    @Override
    @Override
    public boolean hasBaseUserRestriction(String restrictionKey, int userId) {
    public boolean hasBaseUserRestriction(String restrictionKey, int userId) {
        checkManageUsersPermission("hasBaseUserRestriction");
        checkManageUsersPermission("hasBaseUserRestriction");
        UserRestrictionsUtils.checkRestriction(restrictionKey);
        synchronized (mRestrictionsLock) {
        synchronized (mRestrictionsLock) {
            Bundle bundle = mBaseUserRestrictions.get(userId);
            Bundle bundle = mBaseUserRestrictions.get(userId);
            return (bundle != null && bundle.getBoolean(restrictionKey, false));
            return (bundle != null && bundle.getBoolean(restrictionKey, false));
@@ -957,7 +955,6 @@ public class UserManagerService extends IUserManager.Stub {
    @Override
    @Override
    public void setUserRestriction(String key, boolean value, int userId) {
    public void setUserRestriction(String key, boolean value, int userId) {
        checkManageUsersPermission("setUserRestriction");
        checkManageUsersPermission("setUserRestriction");
        UserRestrictionsUtils.checkRestriction(key);
        synchronized (mRestrictionsLock) {
        synchronized (mRestrictionsLock) {
            // Note we can't modify Bundles stored in mBaseUserRestrictions directly, so create
            // Note we can't modify Bundles stored in mBaseUserRestrictions directly, so create
            // a copy.
            // a copy.
+2 −19
Original line number Original line Diff line number Diff line
@@ -56,15 +56,7 @@ public class UserRestrictionsUtils {
    private UserRestrictionsUtils() {
    private UserRestrictionsUtils() {
    }
    }


    private static Set<String> newSetWithUniqueCheck(String[] strings) {
    public static final Set<String> USER_RESTRICTIONS = Sets.newArraySet(
        final Set<String> ret = Sets.newArraySet(strings);

        // Make sure there's no overlap.
        Preconditions.checkState(ret.size() == strings.length);
        return ret;
    }

    public static final Set<String> USER_RESTRICTIONS = newSetWithUniqueCheck(new String[] {
            UserManager.DISALLOW_CONFIG_WIFI,
            UserManager.DISALLOW_CONFIG_WIFI,
            UserManager.DISALLOW_MODIFY_ACCOUNTS,
            UserManager.DISALLOW_MODIFY_ACCOUNTS,
            UserManager.DISALLOW_INSTALL_APPS,
            UserManager.DISALLOW_INSTALL_APPS,
@@ -102,7 +94,7 @@ public class UserRestrictionsUtils {
            UserManager.DISALLOW_RUN_IN_BACKGROUND,
            UserManager.DISALLOW_RUN_IN_BACKGROUND,
            UserManager.DISALLOW_DATA_ROAMING,
            UserManager.DISALLOW_DATA_ROAMING,
            UserManager.DISALLOW_SET_USER_ICON
            UserManager.DISALLOW_SET_USER_ICON
    });
    );


    /**
    /**
     * Set of user restriction which we don't want to persist.
     * Set of user restriction which we don't want to persist.
@@ -148,15 +140,6 @@ public class UserRestrictionsUtils {
            UserManager.DISALLOW_UNMUTE_MICROPHONE
            UserManager.DISALLOW_UNMUTE_MICROPHONE
    );
    );


    /**
     * Throws {@link IllegalArgumentException} if the given restriction name is invalid.
     */
    public static void checkRestriction(@NonNull String restriction) {
        if (!USER_RESTRICTIONS.contains(restriction)) {
            throw new IllegalArgumentException("Unknown restriction: " + restriction);
        }
    }

    public static void writeRestrictions(@NonNull XmlSerializer serializer,
    public static void writeRestrictions(@NonNull XmlSerializer serializer,
            @Nullable Bundle restrictions, @NonNull String tag) throws IOException {
            @Nullable Bundle restrictions, @NonNull String tag) throws IOException {
        if (restrictions == null) {
        if (restrictions == null) {
+0 −2
Original line number Original line Diff line number Diff line
@@ -6847,8 +6847,6 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub {
    @Override
    @Override
    public void setUserRestriction(ComponentName who, String key, boolean enabledFromThisOwner) {
    public void setUserRestriction(ComponentName who, String key, boolean enabledFromThisOwner) {
        Preconditions.checkNotNull(who, "ComponentName is null");
        Preconditions.checkNotNull(who, "ComponentName is null");
        UserRestrictionsUtils.checkRestriction(key);

        final int userHandle = mInjector.userHandleGetCallingUserId();
        final int userHandle = mInjector.userHandleGetCallingUserId();
        synchronized (this) {
        synchronized (this) {
            ActiveAdmin activeAdmin =
            ActiveAdmin activeAdmin =