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

Commit 3cab4d36 authored by Tetiana Meronyk's avatar Tetiana Meronyk Committed by Automerger Merge Worker
Browse files

Truncate user data to a limit of 500 characters am: 46caac64

parents da4914d6 46caac64
Loading
Loading
Loading
Loading
+21 −8
Original line number Diff line number Diff line
@@ -248,6 +248,8 @@ public class UserManagerService extends IUserManager.Stub {

    private static final int USER_VERSION = 9;

    private static final int MAX_USER_STRING_LENGTH = 500;

    private static final long EPOCH_PLUS_30_YEARS = 30L * 365 * 24 * 60 * 60 * 1000L; // ms

    static final int WRITE_USER_MSG = 1;
@@ -3157,15 +3159,17 @@ public class UserManagerService extends IUserManager.Stub {
        // Write seed data
        if (userData.persistSeedData) {
            if (userData.seedAccountName != null) {
                serializer.attribute(null, ATTR_SEED_ACCOUNT_NAME, userData.seedAccountName);
                serializer.attribute(null, ATTR_SEED_ACCOUNT_NAME,
                        truncateString(userData.seedAccountName));
            }
            if (userData.seedAccountType != null) {
                serializer.attribute(null, ATTR_SEED_ACCOUNT_TYPE, userData.seedAccountType);
                serializer.attribute(null, ATTR_SEED_ACCOUNT_TYPE,
                        truncateString(userData.seedAccountType));
            }
        }
        if (userInfo.name != null) {
            serializer.startTag(null, TAG_NAME);
            serializer.text(userInfo.name);
            serializer.text(truncateString(userInfo.name));
            serializer.endTag(null, TAG_NAME);
        }
        synchronized (mRestrictionsLock) {
@@ -3205,6 +3209,13 @@ public class UserManagerService extends IUserManager.Stub {
        serializer.endDocument();
    }

    private String truncateString(String original) {
        if (original == null || original.length() <= MAX_USER_STRING_LENGTH) {
            return original;
        }
        return original.substring(0, MAX_USER_STRING_LENGTH);
    }

    /*
     * Writes the user list file in this format:
     *
@@ -3565,6 +3576,7 @@ public class UserManagerService extends IUserManager.Stub {
            boolean preCreate, @Nullable String[] disallowedPackages,
            @NonNull TimingsTraceAndSlog t, @Nullable Object token)
                    throws UserManager.CheckedUserOperationException {
        String truncatedName = truncateString(name);
        final UserTypeDetails userTypeDetails = mUserTypes.get(userType);
        if (userTypeDetails == null) {
            Slog.e(LOG_TAG, "Cannot create user of invalid user type: " + userType);
@@ -3590,8 +3602,9 @@ public class UserManagerService extends IUserManager.Stub {

        // Try to use a pre-created user (if available).
        if (!preCreate && parentId < 0 && isUserTypeEligibleForPreCreation(userTypeDetails)) {
            final UserInfo preCreatedUser = convertPreCreatedUserIfPossible(userType, flags, name,
                    token);

            final UserInfo preCreatedUser = convertPreCreatedUserIfPossible(userType, flags,
                    truncatedName, token);
            if (preCreatedUser != null) {
                return preCreatedUser;
            }
@@ -3684,7 +3697,7 @@ public class UserManagerService extends IUserManager.Stub {
                        flags &= ~UserInfo.FLAG_EPHEMERAL;
                    }

                    userInfo = new UserInfo(userId, name, null, flags, userType);
                    userInfo = new UserInfo(userId, truncatedName, null, flags, userType);
                    userInfo.serialNumber = mNextSerialNumber++;
                    userInfo.creationTime = getCreationTime();
                    userInfo.partial = true;
@@ -4981,8 +4994,8 @@ public class UserManagerService extends IUserManager.Stub {
                    Slog.e(LOG_TAG, "No such user for settings seed data u=" + userId);
                    return;
                }
                userData.seedAccountName = accountName;
                userData.seedAccountType = accountType;
                userData.seedAccountName = truncateString(accountName);
                userData.seedAccountType = truncateString(accountType);
                userData.seedAccountOptions = accountOptions;
                userData.persistSeedData = persist;
            }