Merge "Prevent apps from spamming addAccountExplicitly. See comment here for the discussion on solution https://b.corp.google.com/issues/169762606#comment14" into rvc-qpr-dev am: 54c29aa710

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

Change-Id: I18503535c0ff31b561a7429881e86779cafaa0d3
This commit is contained in:
TreeHugger Robot
2021-08-31 22:45:39 +00:00
committed by Automerger Merge Worker
2 changed files with 12 additions and 0 deletions

View File

@@ -31,6 +31,7 @@ import android.util.Log;
import com.android.internal.annotations.GuardedBy;
import java.util.Objects;
import java.util.Set;
/**
@@ -86,6 +87,12 @@ 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

@@ -1833,6 +1833,11 @@ public class AccountManagerService
+ ", skipping since the account already exists");
return false;
}
if (accounts.accountsDb.findAllDeAccounts().size() > 100) {
Log.w(TAG, "insertAccountIntoDatabase: " + account.toSafeString()
+ ", skipping since more than 50 accounts on device exist");
return false;
}
long accountId = accounts.accountsDb.insertCeAccount(account, password);
if (accountId < 0) {
Log.w(TAG, "insertAccountIntoDatabase: " + account.toSafeString()