Loading services/core/java/com/android/server/pm/PackageManagerShellCommand.java +1 −6 Original line number Diff line number Diff line Loading @@ -3123,12 +3123,7 @@ class PackageManagerShellCommand extends ShellCommand { translateUserId(userId, UserHandle.USER_NULL, "runSetUserRestriction"); final IUserManager um = IUserManager.Stub.asInterface( ServiceManager.getService(Context.USER_SERVICE)); try { um.setUserRestriction(restriction, value, translatedUserId); } catch (IllegalArgumentException e) { getErrPrintWriter().println(e.getMessage()); return 1; } return 0; } Loading services/core/java/com/android/server/pm/UserManagerService.java +3 −2 Original line number Diff line number Diff line Loading @@ -2810,8 +2810,9 @@ public class UserManagerService extends IUserManager.Stub { } if (!userExists(userId)) { throw new IllegalArgumentException("Cannot set user restriction. " + "User with this id does not exist"); Slogf.w(LOG_TAG, "Cannot set user restriction %s. User with id %d does not exist", key, userId); return; } synchronized (mRestrictionsLock) { // Note we can't modify Bundles stored in mBaseUserRestrictions directly, so create Loading services/tests/servicestests/src/com/android/server/pm/UserManagerServiceTest.java +5 −9 Original line number Diff line number Diff line Loading @@ -16,7 +16,6 @@ package com.android.server.pm; import static android.os.UserManager.DISALLOW_BLUETOOTH; import static android.os.UserManager.DISALLOW_USER_SWITCH; import static com.google.common.truth.Truth.assertThat; Loading @@ -41,7 +40,6 @@ import androidx.test.runner.AndroidJUnit4; import com.android.server.LocalServices; import org.junit.After; import org.junit.Assert; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; Loading Loading @@ -188,13 +186,11 @@ public class UserManagerServiceTest { while (mUserManagerService.userExists(incorrectId)) { incorrectId++; } try { mUserManagerService.setUserRestriction(DISALLOW_BLUETOOTH, true, incorrectId); Assert.fail(); } catch (IllegalArgumentException e) { //Exception is expected to be thrown if user ID does not exist. // IllegalArgumentException thrown means this test is successful. } assertThat(mUserManagerService.hasUserRestriction(DISALLOW_USER_SWITCH, incorrectId)) .isFalse(); mUserManagerService.setUserRestriction(DISALLOW_USER_SWITCH, true, incorrectId); assertThat(mUserManagerService.hasUserRestriction(DISALLOW_USER_SWITCH, incorrectId)) .isFalse(); } @Test Loading Loading
services/core/java/com/android/server/pm/PackageManagerShellCommand.java +1 −6 Original line number Diff line number Diff line Loading @@ -3123,12 +3123,7 @@ class PackageManagerShellCommand extends ShellCommand { translateUserId(userId, UserHandle.USER_NULL, "runSetUserRestriction"); final IUserManager um = IUserManager.Stub.asInterface( ServiceManager.getService(Context.USER_SERVICE)); try { um.setUserRestriction(restriction, value, translatedUserId); } catch (IllegalArgumentException e) { getErrPrintWriter().println(e.getMessage()); return 1; } return 0; } Loading
services/core/java/com/android/server/pm/UserManagerService.java +3 −2 Original line number Diff line number Diff line Loading @@ -2810,8 +2810,9 @@ public class UserManagerService extends IUserManager.Stub { } if (!userExists(userId)) { throw new IllegalArgumentException("Cannot set user restriction. " + "User with this id does not exist"); Slogf.w(LOG_TAG, "Cannot set user restriction %s. User with id %d does not exist", key, userId); return; } synchronized (mRestrictionsLock) { // Note we can't modify Bundles stored in mBaseUserRestrictions directly, so create Loading
services/tests/servicestests/src/com/android/server/pm/UserManagerServiceTest.java +5 −9 Original line number Diff line number Diff line Loading @@ -16,7 +16,6 @@ package com.android.server.pm; import static android.os.UserManager.DISALLOW_BLUETOOTH; import static android.os.UserManager.DISALLOW_USER_SWITCH; import static com.google.common.truth.Truth.assertThat; Loading @@ -41,7 +40,6 @@ import androidx.test.runner.AndroidJUnit4; import com.android.server.LocalServices; import org.junit.After; import org.junit.Assert; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; Loading Loading @@ -188,13 +186,11 @@ public class UserManagerServiceTest { while (mUserManagerService.userExists(incorrectId)) { incorrectId++; } try { mUserManagerService.setUserRestriction(DISALLOW_BLUETOOTH, true, incorrectId); Assert.fail(); } catch (IllegalArgumentException e) { //Exception is expected to be thrown if user ID does not exist. // IllegalArgumentException thrown means this test is successful. } assertThat(mUserManagerService.hasUserRestriction(DISALLOW_USER_SWITCH, incorrectId)) .isFalse(); mUserManagerService.setUserRestriction(DISALLOW_USER_SWITCH, true, incorrectId); assertThat(mUserManagerService.hasUserRestriction(DISALLOW_USER_SWITCH, incorrectId)) .isFalse(); } @Test Loading