Fix a race condition in SyncManager.onAccountsUpdated()
Get the full list of accounts from AccountManagerService in one shot
instead of getting them per user.
Bug: 6263091
Change-Id: I488f24749a96281ef1e2a620820399c97f471024
diff --git a/core/java/android/accounts/AccountManagerService.java b/core/java/android/accounts/AccountManagerService.java
index 197c1bd..241fecb 100644
--- a/core/java/android/accounts/AccountManagerService.java
+++ b/core/java/android/accounts/AccountManagerService.java
@@ -1488,6 +1488,31 @@
}
}
+ /**
+ * Returns all the accounts qualified by user.
+ * @hide
+ */
+ public AccountAndUser[] getAllAccounts() {
+ ArrayList<AccountAndUser> allAccounts = new ArrayList<AccountAndUser>();
+ List<UserInfo> users = getAllUsers();
+ if (users == null) return new AccountAndUser[0];
+
+ synchronized(mUsers) {
+ for (UserInfo user : users) {
+ UserAccounts userAccounts = getUserAccounts(user.id);
+ if (userAccounts == null) continue;
+ synchronized (userAccounts.cacheLock) {
+ Account[] accounts = getAccountsFromCacheLocked(userAccounts, null);
+ for (int a = 0; a < accounts.length; a++) {
+ allAccounts.add(new AccountAndUser(accounts[a], user.id));
+ }
+ }
+ }
+ }
+ AccountAndUser[] accountsArray = new AccountAndUser[allAccounts.size()];
+ return allAccounts.toArray(accountsArray);
+ }
+
public Account[] getAccounts(String type) {
if (Log.isLoggable(TAG, Log.VERBOSE)) {
Log.v(TAG, "getAccounts: accountType " + type