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

Commit 3347c97b authored by Felipe Leme's avatar Felipe Leme Committed by Android (Google) Code Review
Browse files

Merge "Refactored UMS.userWithName() to use getName()" into main

parents 4313baee 2c7894c6
Loading
Loading
Loading
Loading
+15 −15
Original line number Diff line number Diff line
@@ -2386,21 +2386,9 @@ public class UserManagerService extends IUserManager.Stub {
    @Nullable
    UserInfo userWithName(@Nullable UserInfo orig) {
        if (orig != null && orig.name == null) {
            String name = null;
            // TODO(b/407597096): refactor to use getName() instead
            if (orig.id == UserHandle.USER_SYSTEM) {
                if (DBG_ALLOCATION) {
                    final int number = mUser0Allocations.incrementAndGet();
                    Slog.w(LOG_TAG, "System user instantiated at least " + number + " times");
                }
                name = getOwnerName();
            } else if (orig.isMain()) {
                name = getOwnerName();
            } else if (orig.isGuest()) {
                name = getGuestName();
            }
            String name = getName(orig, /* logUser0Allocations= */ true);
            if (name != null) {
                final UserInfo withName = new UserInfo(orig);
                UserInfo withName = new UserInfo(orig);
                withName.name = name;
                return withName;
            }
@@ -2410,10 +2398,22 @@ public class UserManagerService extends IUserManager.Stub {

    @Nullable
    String getName(UserInfo user) {
        return getName(user, /* logUser0Allocations= */ false);
    }

    @Nullable
    private String getName(UserInfo user, boolean logUser0Allocations) {
        if (user.name != null) {
            return user.name;
        }
        if (user.id == UserHandle.USER_SYSTEM || user.isMain()) {
        if (user.id == UserHandle.USER_SYSTEM) {
            if (DBG_ALLOCATION && logUser0Allocations) {
                int number = mUser0Allocations.incrementAndGet();
                Slog.w(LOG_TAG, "System user instantiated at least " + number + " times");
            }
            return getOwnerName();
        }
        if (user.isMain()) {
            return getOwnerName();
        }
        if (user.isGuest()) {