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

Commit 2c7894c6 authored by Felipe Leme's avatar Felipe Leme
Browse files

Refactored UMS.userWithName() to use getName()

Fixes: 407597096
Test: atest FrameworksMockingServicesTests:UserManagerServiceMockedTest
Flag: EXEMPT refactor

Change-Id: I502f0b037e2d44ec6c90e7736a2950bc0dbfa223
parent e01e46dc
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()) {