From bf5ccd26b937a06eac73f7c70bbedbb1a7decbca Mon Sep 17 00:00:00 2001 From: Adam Bookatz Date: Fri, 10 Feb 2023 16:46:45 -0800 Subject: Various createUsers don't sometimes return null Previously, UserManagerService.createUserInternalUncheckedNoTracing would usually throw on failure, but could instead return null in certain circumstances (namely, bad input). This lead to ambiguity over whether the various createUser methods were able to return null. Here, we throw instead in these previously-null situations. This way, all of the createUser methods are @NonNull, unless they specifically catch errors and return null instead. The methods are now all self-consistent. In particular, this fixes the previously not-always-correct annotation of @NonNull that is on UserManager.preCreateUser. Bug: 219942927 Test: atest com.android.server.pm.UserManagerTest Test: atest com.android.server.pm.UserManagerServiceTest Test: atest android.multiuser.cts.UserManagerTest Change-Id: I7a63b4e684d03b4d2ef76046d0cf277ba2d5744d --- services/java/com/android/server/HsumBootUserInitializer.java | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) (limited to 'services/java') diff --git a/services/java/com/android/server/HsumBootUserInitializer.java b/services/java/com/android/server/HsumBootUserInitializer.java index c4ad80e4c2c6..4e649150e6f1 100644 --- a/services/java/com/android/server/HsumBootUserInitializer.java +++ b/services/java/com/android/server/HsumBootUserInitializer.java @@ -112,11 +112,7 @@ final class HsumBootUserInitializer { UserInfo.FLAG_ADMIN | UserInfo.FLAG_MAIN, /* disallowedPackages= */ null, /* token= */ null); - if (newInitialUser == null) { - Slogf.wtf(TAG, "Initial bootable MainUser creation failed: returned null"); - } else { - Slogf.i(TAG, "Successfully created MainUser, userId=%d", newInitialUser.id); - } + Slogf.i(TAG, "Successfully created MainUser, userId=%d", newInitialUser.id); } catch (UserManager.CheckedUserOperationException e) { Slogf.wtf(TAG, "Initial bootable MainUser creation failed", e); } -- cgit v1.2.3-59-g8ed1b