Loading services/core/java/com/android/server/pm/UserManagerService.java +4 −3 Original line number Diff line number Diff line Loading @@ -2665,7 +2665,8 @@ public class UserManagerService extends IUserManager.Stub { } } private void setUserRestrictionInner(int userId, @NonNull String key, boolean value) { @VisibleForTesting void setUserRestrictionInner(int userId, @NonNull String key, boolean value) { if (!UserRestrictionsUtils.isValidRestriction(key)) { Slog.e(LOG_TAG, "Setting invalid restriction " + key); return; Loading Loading @@ -4273,11 +4274,11 @@ public class UserManagerService extends IUserManager.Stub { UserRestrictionsUtils.writeRestrictions(serializer, mDevicePolicyUserRestrictions.getRestrictions(UserHandle.USER_ALL), TAG_DEVICE_POLICY_RESTRICTIONS); TAG_DEVICE_POLICY_GLOBAL_RESTRICTIONS); UserRestrictionsUtils.writeRestrictions(serializer, mDevicePolicyUserRestrictions.getRestrictions(userInfo.id), TAG_DEVICE_POLICY_RESTRICTIONS); TAG_DEVICE_POLICY_LOCAL_RESTRICTIONS); } if (userData.account != null) { Loading services/tests/servicestests/src/com/android/server/pm/UserManagerServiceUserInfoTest.java +36 −0 Original line number Diff line number Diff line Loading @@ -113,6 +113,42 @@ public class UserManagerServiceUserInfoTest { assertUserInfoEquals(data.info, read.info, /* parcelCopy= */ false); } /** Tests that device policy restrictions are written/read properly. */ @Test public void testWriteReadDevicePolicyUserRestrictions() throws Exception { final String globalRestriction = UserManager.DISALLOW_FACTORY_RESET; final String localRestriction = UserManager.DISALLOW_CONFIG_DATE_TIME; UserData data = new UserData(); data.info = createUser(100, FLAG_FULL, "A type"); mUserManagerService.putUserInfo(data.info); // Set a global and user restriction so they get written out to the user file. setUserRestrictions(data.info.id, globalRestriction, localRestriction, true); ByteArrayOutputStream baos = new ByteArrayOutputStream(); DataOutputStream out = new DataOutputStream(baos); mUserManagerService.writeUserLP(data, out); byte[] bytes = baos.toByteArray(); // Clear the restrictions to see if they are properly read in from the user file. setUserRestrictions(data.info.id, globalRestriction, localRestriction, false); mUserManagerService.readUserLP(data.info.id, new ByteArrayInputStream(bytes)); assertTrue(mUserManagerService.hasUserRestrictionOnAnyUser(globalRestriction)); assertTrue(mUserManagerService.hasUserRestrictionOnAnyUser(localRestriction)); } /** Sets a global and local restriction and verifies they were set properly **/ private void setUserRestrictions(int id, String global, String local, boolean enabled) { mUserManagerService.setUserRestrictionInner(UserHandle.USER_ALL, global, enabled); assertEquals(mUserManagerService.hasUserRestrictionOnAnyUser(global), enabled); mUserManagerService.setUserRestrictionInner(id, local, enabled); assertEquals(mUserManagerService.hasUserRestrictionOnAnyUser(local), enabled); } @Test public void testParcelUnparcelUserInfo() throws Exception { UserInfo info = createUser(); Loading Loading
services/core/java/com/android/server/pm/UserManagerService.java +4 −3 Original line number Diff line number Diff line Loading @@ -2665,7 +2665,8 @@ public class UserManagerService extends IUserManager.Stub { } } private void setUserRestrictionInner(int userId, @NonNull String key, boolean value) { @VisibleForTesting void setUserRestrictionInner(int userId, @NonNull String key, boolean value) { if (!UserRestrictionsUtils.isValidRestriction(key)) { Slog.e(LOG_TAG, "Setting invalid restriction " + key); return; Loading Loading @@ -4273,11 +4274,11 @@ public class UserManagerService extends IUserManager.Stub { UserRestrictionsUtils.writeRestrictions(serializer, mDevicePolicyUserRestrictions.getRestrictions(UserHandle.USER_ALL), TAG_DEVICE_POLICY_RESTRICTIONS); TAG_DEVICE_POLICY_GLOBAL_RESTRICTIONS); UserRestrictionsUtils.writeRestrictions(serializer, mDevicePolicyUserRestrictions.getRestrictions(userInfo.id), TAG_DEVICE_POLICY_RESTRICTIONS); TAG_DEVICE_POLICY_LOCAL_RESTRICTIONS); } if (userData.account != null) { Loading
services/tests/servicestests/src/com/android/server/pm/UserManagerServiceUserInfoTest.java +36 −0 Original line number Diff line number Diff line Loading @@ -113,6 +113,42 @@ public class UserManagerServiceUserInfoTest { assertUserInfoEquals(data.info, read.info, /* parcelCopy= */ false); } /** Tests that device policy restrictions are written/read properly. */ @Test public void testWriteReadDevicePolicyUserRestrictions() throws Exception { final String globalRestriction = UserManager.DISALLOW_FACTORY_RESET; final String localRestriction = UserManager.DISALLOW_CONFIG_DATE_TIME; UserData data = new UserData(); data.info = createUser(100, FLAG_FULL, "A type"); mUserManagerService.putUserInfo(data.info); // Set a global and user restriction so they get written out to the user file. setUserRestrictions(data.info.id, globalRestriction, localRestriction, true); ByteArrayOutputStream baos = new ByteArrayOutputStream(); DataOutputStream out = new DataOutputStream(baos); mUserManagerService.writeUserLP(data, out); byte[] bytes = baos.toByteArray(); // Clear the restrictions to see if they are properly read in from the user file. setUserRestrictions(data.info.id, globalRestriction, localRestriction, false); mUserManagerService.readUserLP(data.info.id, new ByteArrayInputStream(bytes)); assertTrue(mUserManagerService.hasUserRestrictionOnAnyUser(globalRestriction)); assertTrue(mUserManagerService.hasUserRestrictionOnAnyUser(localRestriction)); } /** Sets a global and local restriction and verifies they were set properly **/ private void setUserRestrictions(int id, String global, String local, boolean enabled) { mUserManagerService.setUserRestrictionInner(UserHandle.USER_ALL, global, enabled); assertEquals(mUserManagerService.hasUserRestrictionOnAnyUser(global), enabled); mUserManagerService.setUserRestrictionInner(id, local, enabled); assertEquals(mUserManagerService.hasUserRestrictionOnAnyUser(local), enabled); } @Test public void testParcelUnparcelUserInfo() throws Exception { UserInfo info = createUser(); Loading