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

Commit 7d2354bd authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Added UserInfo.convertedFromPreCreated" into rvc-qpr-dev

parents 0bf48315 4c0f6907
Loading
Loading
Loading
Loading
+10 −0
Original line number Diff line number Diff line
@@ -220,6 +220,14 @@ public class UserInfo implements Parcelable {
     */
    public boolean preCreated;

    /**
     * When {@code true}, it indicates this user was created by converting a {@link #preCreated}
     * user.
     *
     * <p><b>NOTE: </b>only used for debugging purposes, it's not set when marshalled to a parcel.
     */
    public boolean convertedFromPreCreated;

    /**
     * Creates a UserInfo whose user type is determined automatically by the flags according to
     * {@link #getDefaultUserType}; can only be used for user types handled there.
@@ -413,6 +421,7 @@ public class UserInfo implements Parcelable {
        lastLoggedInFingerprint = orig.lastLoggedInFingerprint;
        partial = orig.partial;
        preCreated = orig.preCreated;
        convertedFromPreCreated = orig.convertedFromPreCreated;
        profileGroupId = orig.profileGroupId;
        restrictedProfileParentId = orig.restrictedProfileParentId;
        guestToRemove = orig.guestToRemove;
@@ -440,6 +449,7 @@ public class UserInfo implements Parcelable {
                + ", type=" + userType
                + ", flags=" + flagsToString(flags)
                + (preCreated ? " (pre-created)" : "")
                + (convertedFromPreCreated ? " (converted)" : "")
                + (partial ? " (partial)" : "")
                + "]";
    }
+15 −0
Original line number Diff line number Diff line
@@ -173,6 +173,7 @@ public class UserManagerService extends IUserManager.Stub {
    private static final String ATTR_NEXT_SERIAL_NO = "nextSerialNumber";
    private static final String ATTR_PARTIAL = "partial";
    private static final String ATTR_PRE_CREATED = "preCreated";
    private static final String ATTR_CONVERTED_FROM_PRE_CREATED = "convertedFromPreCreated";
    private static final String ATTR_GUEST_TO_REMOVE = "guestToRemove";
    private static final String ATTR_USER_VERSION = "version";
    private static final String ATTR_PROFILE_GROUP_ID = "profileGroupId";
@@ -2896,6 +2897,9 @@ public class UserManagerService extends IUserManager.Stub {
        if (userInfo.preCreated) {
            serializer.attribute(null, ATTR_PRE_CREATED, "true");
        }
        if (userInfo.convertedFromPreCreated) {
            serializer.attribute(null, ATTR_CONVERTED_FROM_PRE_CREATED, "true");
        }
        if (userInfo.guestToRemove) {
            serializer.attribute(null, ATTR_GUEST_TO_REMOVE, "true");
        }
@@ -3053,6 +3057,7 @@ public class UserManagerService extends IUserManager.Stub {
        int restrictedProfileParentId = UserInfo.NO_PROFILE_GROUP_ID;
        boolean partial = false;
        boolean preCreated = false;
        boolean converted = false;
        boolean guestToRemove = false;
        boolean persistSeedData = false;
        String seedAccountName = null;
@@ -3104,6 +3109,10 @@ public class UserManagerService extends IUserManager.Stub {
            if ("true".equals(valueString)) {
                preCreated = true;
            }
            valueString = parser.getAttributeValue(null, ATTR_CONVERTED_FROM_PRE_CREATED);
            if ("true".equals(valueString)) {
                converted = true;
            }
            valueString = parser.getAttributeValue(null, ATTR_GUEST_TO_REMOVE);
            if ("true".equals(valueString)) {
                guestToRemove = true;
@@ -3161,6 +3170,7 @@ public class UserManagerService extends IUserManager.Stub {
        userInfo.lastLoggedInFingerprint = lastLoggedInFingerprint;
        userInfo.partial = partial;
        userInfo.preCreated = preCreated;
        userInfo.convertedFromPreCreated = converted;
        userInfo.guestToRemove = guestToRemove;
        userInfo.profileGroupId = profileGroupId;
        userInfo.profileBadge = profileBadge;
@@ -3607,6 +3617,7 @@ public class UserManagerService extends IUserManager.Stub {
        preCreatedUser.name = name;
        preCreatedUser.flags = newFlags;
        preCreatedUser.preCreated = false;
        preCreatedUser.convertedFromPreCreated = true;
        preCreatedUser.creationTime = getCreationTime();

        synchronized (mPackagesLock) {
@@ -4669,6 +4680,7 @@ public class UserManagerService extends IUserManager.Stub {
                            running ? " (running)" : "",
                            user.partial ? " (partial)" : "",
                            user.preCreated ? " (pre-created)" : "",
                            user.convertedFromPreCreated ? " (converted)" : "",
                            current ? " (current)" : "");
                } else {
                    // NOTE: the standard "list users" command is used by integration tests and
@@ -4753,6 +4765,9 @@ public class UserManagerService extends IUserManager.Stub {
                    if (userInfo.preCreated) {
                        pw.print(" <pre-created>");
                    }
                    if (userInfo.convertedFromPreCreated) {
                        pw.print(" <converted>");
                    }
                    pw.println();
                    pw.print("    Type: "); pw.println(userInfo.userType);
                    pw.print("    Flags: "); pw.print(userInfo.flags); pw.print(" (");
+24 −8
Original line number Diff line number Diff line
@@ -105,7 +105,7 @@ public class UserManagerServiceUserInfoTest {
        UserData read = mUserManagerService.readUserLP(
                data.info.id, new ByteArrayInputStream(bytes));

        assertUserInfoEquals(data.info, read.info);
        assertUserInfoEquals(data.info, read.info, /* parcelCopy= */ false);
    }

    @Test
@@ -123,7 +123,16 @@ public class UserManagerServiceUserInfoTest {
        UserInfo read = UserInfo.CREATOR.createFromParcel(in);
        in.recycle();

        assertUserInfoEquals(info, read);
        assertUserInfoEquals(info, read, /* parcelCopy= */ true);
    }

    @Test
    public void testCopyConstructor() throws Exception {
        UserInfo info = createUser();

        UserInfo copy = new UserInfo(info);

        assertUserInfoEquals(info, copy, /* parcelCopy= */ false);
    }

    @Test
@@ -227,10 +236,11 @@ public class UserManagerServiceUserInfoTest {
        user.partial = true;
        user.guestToRemove = true;
        user.preCreated = true;
        user.convertedFromPreCreated = true;
        return user;
    }

    private void assertUserInfoEquals(UserInfo one, UserInfo two) {
    private void assertUserInfoEquals(UserInfo one, UserInfo two, boolean parcelCopy) {
        assertEquals("Id not preserved", one.id, two.id);
        assertEquals("Name not preserved", one.name, two.name);
        assertEquals("Icon path not preserved", one.iconPath, two.iconPath);
@@ -238,11 +248,17 @@ public class UserManagerServiceUserInfoTest {
        assertEquals("UserType not preserved", one.userType, two.userType);
        assertEquals("profile group not preserved", one.profileGroupId,
                two.profileGroupId);
        assertEquals("restricted profile parent not preseved", one.restrictedProfileParentId,
        assertEquals("restricted profile parent not preserved", one.restrictedProfileParentId,
                two.restrictedProfileParentId);
        assertEquals("profile badge not preseved", one.profileBadge, two.profileBadge);
        assertEquals("partial not preseved", one.partial, two.partial);
        assertEquals("guestToRemove not preseved", one.guestToRemove, two.guestToRemove);
        assertEquals("preCreated not preseved", one.preCreated, two.preCreated);
        assertEquals("profile badge not preserved", one.profileBadge, two.profileBadge);
        assertEquals("partial not preserved", one.partial, two.partial);
        assertEquals("guestToRemove not preserved", one.guestToRemove, two.guestToRemove);
        assertEquals("preCreated not preserved", one.preCreated, two.preCreated);
        if (parcelCopy) {
            assertFalse("convertedFromPreCreated should not be set", two.convertedFromPreCreated);
        } else {
            assertEquals("convertedFromPreCreated not preserved", one.convertedFromPreCreated,
                    two.convertedFromPreCreated);
        }
    }
}