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

Commit bf9deb25 authored by Yasin Kilicdere's avatar Yasin Kilicdere
Browse files

Fix NPE in UserManagerService when calling isUserInitialized().

Because getUserInfo() may return null.

Fixes: 308194324
Test: presubmit
Change-Id: Iec32181f67eb6ff27e3bd4930fe3b4d7bb003ae6
parent 9481b2b3
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -7177,7 +7177,8 @@ public class UserManagerService extends IUserManager.Stub {

        @Override
        public boolean isUserInitialized(@UserIdInt int userId) {
            return (getUserInfo(userId).flags & UserInfo.FLAG_INITIALIZED) != 0;
            final UserInfo userInfo = getUserInfo(userId);
            return userInfo != null && (userInfo.flags & UserInfo.FLAG_INITIALIZED) != 0;
        }

        @Override
+7 −0
Original line number Diff line number Diff line
@@ -182,6 +182,13 @@ public class UserManagerServiceTest {
                .isFalse();
    }

    @Test
    public void testIsUserInitialized_NonExistentUserReturnsFalse() {
        int nonExistentUserId = UserHandle.USER_NULL;
        assertThat(mUserManagerService.isUserInitialized(nonExistentUserId))
                .isFalse();
    }

    @Test
    public void testSetUserRestrictionWithIncorrectID() throws Exception {
        int incorrectId = 1;