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

Commit 00e664d2 authored by Tetiana Meronyk's avatar Tetiana Meronyk Committed by Android (Google) Code Review
Browse files

Merge "Log warning when setting restriction on non existent user instead of throwing exception"

parents c458d475 f28d6f48
Loading
Loading
Loading
Loading
+1 −6
Original line number Diff line number Diff line
@@ -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;
    }

+3 −2
Original line number Diff line number Diff line
@@ -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
+5 −9
Original line number Diff line number Diff line
@@ -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;
@@ -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;
@@ -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