DO NOT MERGE am: 3f218c9a5e

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/17595878

Change-Id: Ide4ce7536d9637969b483d05f729e6d8c800b49c
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
Aseem Kumar
2022-08-05 18:33:55 +00:00
committed by Automerger Merge Worker
3 changed files with 31 additions and 7 deletions

View File

@@ -30,7 +30,6 @@ import android.util.Log;
import com.android.internal.annotations.GuardedBy;
import java.util.Objects;
import java.util.Set;
/**
@@ -86,12 +85,6 @@ public class Account implements Parcelable {
if (TextUtils.isEmpty(type)) {
throw new IllegalArgumentException("the type must not be empty: " + type);
}
if (name.length() > 200) {
throw new IllegalArgumentException("account name is longer than 200 characters");
}
if (type.length() > 200) {
throw new IllegalArgumentException("account type is longer than 200 characters");
}
this.name = name;
this.type = type;
this.accessId = accessId;

View File

@@ -1801,6 +1801,14 @@ public class AccountManagerService
if (account == null) {
return false;
}
if (account.name != null && account.name.length() > 200) {
Log.w(TAG, "Account cannot be added - Name longer than 200 chars");
return false;
}
if (account.type != null && account.type.length() > 200) {
Log.w(TAG, "Account cannot be added - Name longer than 200 chars");
return false;
}
if (!isLocalUnlockedUser(accounts.userId)) {
Log.w(TAG, "Account " + account.toSafeString() + " cannot be added - user "
+ accounts.userId + " is locked. callingUid=" + callingUid);
@@ -1994,6 +2002,10 @@ public class AccountManagerService
+ ", pid " + Binder.getCallingPid());
}
if (accountToRename == null) throw new IllegalArgumentException("account is null");
if (newName != null && newName.length() > 200) {
Log.e(TAG, "renameAccount failed - account name longer than 200");
throw new IllegalArgumentException("account name longer than 200");
}
int userId = UserHandle.getCallingUserId();
if (!isAccountManagedByCaller(accountToRename.type, callingUid, userId)) {
String msg = String.format(

View File

@@ -240,6 +240,25 @@ public class AccountManagerServiceTest extends AndroidTestCase {
assertEquals(a31, accounts[1]);
}
@SmallTest
public void testCheckAddAccountLongName() throws Exception {
unlockSystemUser();
String longString = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
+ "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
+ "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
+ "aaaaa";
Account a11 = new Account(longString, AccountManagerServiceTestFixtures.ACCOUNT_TYPE_1);
mAms.addAccountExplicitly(a11, /* password= */ "p11", /* extras= */ null);
String[] list = new String[]{AccountManagerServiceTestFixtures.CALLER_PACKAGE};
when(mMockPackageManager.getPackagesForUid(anyInt())).thenReturn(list);
Account[] accounts = mAms.getAccountsAsUser(null,
UserHandle.getCallingUserId(), mContext.getOpPackageName());
assertEquals(0, accounts.length);
}
@SmallTest
public void testPasswords() throws Exception {
unlockSystemUser();