Loading services/core/java/com/android/server/pm/UserManagerService.java +9 −0 Original line number Diff line number Diff line Loading @@ -930,6 +930,9 @@ public class UserManagerService extends IUserManager.Stub { /** @return a specific user restriction that's in effect currently. */ @Override public boolean hasUserRestriction(String restrictionKey, int userId) { if (!UserRestrictionsUtils.isValidRestriction(restrictionKey)) { return false; } Bundle restrictions = getEffectiveUserRestrictions(userId); return restrictions != null && restrictions.getBoolean(restrictionKey); } Loading @@ -946,6 +949,9 @@ public class UserManagerService extends IUserManager.Stub { @Override public boolean hasBaseUserRestriction(String restrictionKey, int userId) { checkManageUsersPermission("hasBaseUserRestriction"); if (!UserRestrictionsUtils.isValidRestriction(restrictionKey)) { return false; } synchronized (mRestrictionsLock) { Bundle bundle = mBaseUserRestrictions.get(userId); return (bundle != null && bundle.getBoolean(restrictionKey, false)); Loading @@ -955,6 +961,9 @@ public class UserManagerService extends IUserManager.Stub { @Override public void setUserRestriction(String key, boolean value, int userId) { checkManageUsersPermission("setUserRestriction"); if (!UserRestrictionsUtils.isValidRestriction(key)) { return; } synchronized (mRestrictionsLock) { // Note we can't modify Bundles stored in mBaseUserRestrictions directly, so create // a copy. Loading services/core/java/com/android/server/pm/UserRestrictionsUtils.java +22 −2 Original line number Diff line number Diff line Loading @@ -36,6 +36,7 @@ import android.os.UserManager; import android.telephony.SubscriptionInfo; import android.telephony.SubscriptionManager; import android.util.Log; import android.util.Slog; import org.xmlpull.v1.XmlPullParser; import org.xmlpull.v1.XmlSerializer; Loading @@ -56,7 +57,15 @@ public class UserRestrictionsUtils { private UserRestrictionsUtils() { } public static final Set<String> USER_RESTRICTIONS = Sets.newArraySet( 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[] { UserManager.DISALLOW_CONFIG_WIFI, UserManager.DISALLOW_MODIFY_ACCOUNTS, UserManager.DISALLOW_INSTALL_APPS, Loading Loading @@ -95,7 +104,7 @@ public class UserRestrictionsUtils { UserManager.DISALLOW_DATA_ROAMING, UserManager.DISALLOW_SET_USER_ICON, UserManager.DISALLOW_SET_WALLPAPER ); }); /** * Set of user restriction which we don't want to persist. Loading Loading @@ -141,6 +150,17 @@ public class UserRestrictionsUtils { UserManager.DISALLOW_UNMUTE_MICROPHONE ); /** * Throws {@link IllegalArgumentException} if the given restriction name is invalid. */ public static boolean isValidRestriction(@NonNull String restriction) { if (!USER_RESTRICTIONS.contains(restriction)) { Slog.wtf(TAG, "Unknown restriction: " + restriction); return false; } return true; } public static void writeRestrictions(@NonNull XmlSerializer serializer, @Nullable Bundle restrictions, @NonNull String tag) throws IOException { if (restrictions == null) { Loading services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java +4 −0 Original line number Diff line number Diff line Loading @@ -6867,6 +6867,10 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub { @Override public void setUserRestriction(ComponentName who, String key, boolean enabledFromThisOwner) { Preconditions.checkNotNull(who, "ComponentName is null"); if (!UserRestrictionsUtils.isValidRestriction(key)) { return; } final int userHandle = mInjector.userHandleGetCallingUserId(); synchronized (this) { ActiveAdmin activeAdmin = Loading Loading
services/core/java/com/android/server/pm/UserManagerService.java +9 −0 Original line number Diff line number Diff line Loading @@ -930,6 +930,9 @@ public class UserManagerService extends IUserManager.Stub { /** @return a specific user restriction that's in effect currently. */ @Override public boolean hasUserRestriction(String restrictionKey, int userId) { if (!UserRestrictionsUtils.isValidRestriction(restrictionKey)) { return false; } Bundle restrictions = getEffectiveUserRestrictions(userId); return restrictions != null && restrictions.getBoolean(restrictionKey); } Loading @@ -946,6 +949,9 @@ public class UserManagerService extends IUserManager.Stub { @Override public boolean hasBaseUserRestriction(String restrictionKey, int userId) { checkManageUsersPermission("hasBaseUserRestriction"); if (!UserRestrictionsUtils.isValidRestriction(restrictionKey)) { return false; } synchronized (mRestrictionsLock) { Bundle bundle = mBaseUserRestrictions.get(userId); return (bundle != null && bundle.getBoolean(restrictionKey, false)); Loading @@ -955,6 +961,9 @@ public class UserManagerService extends IUserManager.Stub { @Override public void setUserRestriction(String key, boolean value, int userId) { checkManageUsersPermission("setUserRestriction"); if (!UserRestrictionsUtils.isValidRestriction(key)) { return; } synchronized (mRestrictionsLock) { // Note we can't modify Bundles stored in mBaseUserRestrictions directly, so create // a copy. Loading
services/core/java/com/android/server/pm/UserRestrictionsUtils.java +22 −2 Original line number Diff line number Diff line Loading @@ -36,6 +36,7 @@ import android.os.UserManager; import android.telephony.SubscriptionInfo; import android.telephony.SubscriptionManager; import android.util.Log; import android.util.Slog; import org.xmlpull.v1.XmlPullParser; import org.xmlpull.v1.XmlSerializer; Loading @@ -56,7 +57,15 @@ public class UserRestrictionsUtils { private UserRestrictionsUtils() { } public static final Set<String> USER_RESTRICTIONS = Sets.newArraySet( 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[] { UserManager.DISALLOW_CONFIG_WIFI, UserManager.DISALLOW_MODIFY_ACCOUNTS, UserManager.DISALLOW_INSTALL_APPS, Loading Loading @@ -95,7 +104,7 @@ public class UserRestrictionsUtils { UserManager.DISALLOW_DATA_ROAMING, UserManager.DISALLOW_SET_USER_ICON, UserManager.DISALLOW_SET_WALLPAPER ); }); /** * Set of user restriction which we don't want to persist. Loading Loading @@ -141,6 +150,17 @@ public class UserRestrictionsUtils { UserManager.DISALLOW_UNMUTE_MICROPHONE ); /** * Throws {@link IllegalArgumentException} if the given restriction name is invalid. */ public static boolean isValidRestriction(@NonNull String restriction) { if (!USER_RESTRICTIONS.contains(restriction)) { Slog.wtf(TAG, "Unknown restriction: " + restriction); return false; } return true; } public static void writeRestrictions(@NonNull XmlSerializer serializer, @Nullable Bundle restrictions, @NonNull String tag) throws IOException { if (restrictions == null) { Loading
services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java +4 −0 Original line number Diff line number Diff line Loading @@ -6867,6 +6867,10 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub { @Override public void setUserRestriction(ComponentName who, String key, boolean enabledFromThisOwner) { Preconditions.checkNotNull(who, "ComponentName is null"); if (!UserRestrictionsUtils.isValidRestriction(key)) { return; } final int userHandle = mInjector.userHandleGetCallingUserId(); synchronized (this) { ActiveAdmin activeAdmin = Loading