Skip to content

Commit c65b81b

Browse files
author
Aseem Kumar
committed
Prevent apps from spamming addAccountExplicitly.
See comment here for the discussion on solution https://b.corp.google.com/issues/169762606#comment14 Change-Id: If212df3a3b7be1de0fb26b8e88b2fcbb8077c253 Bug: 169762606 (cherry picked from commit 11053c1) Change-Id: I3ff7d8f4df086cb4c153e7ec873b85a093810722 Merged-In: If212df3a3b7be1de0fb26b8e88b2fcbb8077c253
1 parent 2ea8873 commit c65b81b

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

core/java/android/accounts/Account.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030

3131
import com.android.internal.annotations.GuardedBy;
3232

33+
import java.util.Objects;
3334
import java.util.Set;
3435

3536
/**
@@ -85,6 +86,12 @@ public Account(String name, String type, String accessId) {
8586
if (TextUtils.isEmpty(type)) {
8687
throw new IllegalArgumentException("the type must not be empty: " + type);
8788
}
89+
if (name.length() > 200) {
90+
throw new IllegalArgumentException("account name is longer than 200 characters");
91+
}
92+
if (type.length() > 200) {
93+
throw new IllegalArgumentException("account type is longer than 200 characters");
94+
}
8895
this.name = name;
8996
this.type = type;
9097
this.accessId = accessId;

services/core/java/com/android/server/accounts/AccountManagerService.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1820,6 +1820,11 @@ private boolean addAccountInternal(UserAccounts accounts, Account account, Strin
18201820
+ ", skipping since the account already exists");
18211821
return false;
18221822
}
1823+
if (accounts.accountsDb.findAllDeAccounts().size() > 100) {
1824+
Log.w(TAG, "insertAccountIntoDatabase: " + account.toSafeString()
1825+
+ ", skipping since more than 50 accounts on device exist");
1826+
return false;
1827+
}
18231828
long accountId = accounts.accountsDb.insertCeAccount(account, password);
18241829
if (accountId < 0) {
18251830
Log.w(TAG, "insertAccountIntoDatabase: " + account.toSafeString()

0 commit comments

Comments
 (0)