/** @return a specific user restriction that's in effect currently. */
@Override
public boolean hasUserRestriction(String restrictionKey, int userId) {
- UserRestrictionsUtils.checkRestriction(restrictionKey);
Bundle restrictions = getEffectiveUserRestrictions(userId);
return restrictions != null && restrictions.getBoolean(restrictionKey);
}
@Override
public boolean hasBaseUserRestriction(String restrictionKey, int userId) {
checkManageUsersPermission("hasBaseUserRestriction");
- UserRestrictionsUtils.checkRestriction(restrictionKey);
synchronized (mRestrictionsLock) {
Bundle bundle = mBaseUserRestrictions.get(userId);
return (bundle != null && bundle.getBoolean(restrictionKey, false));
@Override
public void setUserRestriction(String key, boolean value, int userId) {
checkManageUsersPermission("setUserRestriction");
- UserRestrictionsUtils.checkRestriction(key);
synchronized (mRestrictionsLock) {
// Note we can't modify Bundles stored in mBaseUserRestrictions directly, so create
// a copy.
private UserRestrictionsUtils() {
}
- private static Set<String> newSetWithUniqueCheck(String[] strings) {
- 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[] {
+ public static final Set<String> USER_RESTRICTIONS = Sets.newArraySet(
UserManager.DISALLOW_CONFIG_WIFI,
UserManager.DISALLOW_MODIFY_ACCOUNTS,
UserManager.DISALLOW_INSTALL_APPS,
UserManager.DISALLOW_RUN_IN_BACKGROUND,
UserManager.DISALLOW_DATA_ROAMING,
UserManager.DISALLOW_SET_USER_ICON
- });
+ );
/**
* Set of user restriction which we don't want to persist.
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,
@Nullable Bundle restrictions, @NonNull String tag) throws IOException {
if (restrictions == null) {
@Override
public void setUserRestriction(ComponentName who, String key, boolean enabledFromThisOwner) {
Preconditions.checkNotNull(who, "ComponentName is null");
- UserRestrictionsUtils.checkRestriction(key);
-
final int userHandle = mInjector.userHandleGetCallingUserId();
synchronized (this) {
ActiveAdmin activeAdmin =