diff --git a/services/core/java/com/android/server/accounts/AccountManagerService.java b/services/core/java/com/android/server/accounts/AccountManagerService.java index d14364d25ea68..caeb0c6380d5b 100644 --- a/services/core/java/com/android/server/accounts/AccountManagerService.java +++ b/services/core/java/com/android/server/accounts/AccountManagerService.java @@ -660,12 +660,7 @@ public class AccountManagerService long identityToken = clearCallingIdentity(); try { UserAccounts accounts = getUserAccounts(userId); - synchronized (accounts.cacheLock) { - if (!accountExistsCacheLocked(accounts, account)) { - return null; - } - return readUserDataInternalLocked(accounts, account, key); - } + return readUserDataInternal(accounts, account, key); } finally { restoreCallingIdentity(identityToken); } @@ -1717,58 +1712,44 @@ public class AccountManagerService long identityToken = clearCallingIdentity(); try { UserAccounts accounts = getUserAccounts(userId); - synchronized (accounts.cacheLock) { - if (!accountExistsCacheLocked(accounts, account)) { - return; - } - setUserdataInternalLocked(accounts, account, key, value); - } + setUserdataInternal(accounts, account, key, value); } finally { restoreCallingIdentity(identityToken); } } - private boolean accountExistsCacheLocked(UserAccounts accounts, Account account) { - if (accounts.accountCache.containsKey(account.type)) { - for (Account acc : accounts.accountCache.get(account.type)) { - if (acc.name.equals(account.name)) { - return true; - } - } - } - return false; - } - - private void setUserdataInternalLocked(UserAccounts accounts, Account account, String key, + private void setUserdataInternal(UserAccounts accounts, Account account, String key, String value) { if (account == null || key == null) { return; } - final SQLiteDatabase db = accounts.openHelper.getWritableDatabase(); - db.beginTransaction(); - try { - long accountId = getAccountIdLocked(db, account); - if (accountId < 0) { - return; - } - long extrasId = getExtrasIdLocked(db, accountId, key); - if (extrasId < 0) { - extrasId = insertExtraLocked(db, accountId, key, value); - if (extrasId < 0) { - return; - } - } else { - ContentValues values = new ContentValues(); - values.put(EXTRAS_VALUE, value); - if (1 != db.update(TABLE_EXTRAS, values, EXTRAS_ID + "=" + extrasId, null)) { + synchronized (accounts.cacheLock) { + final SQLiteDatabase db = accounts.openHelper.getWritableDatabase(); + db.beginTransaction(); + try { + long accountId = getAccountIdLocked(db, account); + if (accountId < 0) { return; } + long extrasId = getExtrasIdLocked(db, accountId, key); + if (extrasId < 0 ) { + extrasId = insertExtraLocked(db, accountId, key, value); + if (extrasId < 0) { + return; + } + } else { + ContentValues values = new ContentValues(); + values.put(EXTRAS_VALUE, value); + if (1 != db.update(TABLE_EXTRAS, values, EXTRAS_ID + "=" + extrasId, null)) { + return; + } + } + writeUserDataIntoCacheLocked(accounts, db, account, key, value); + db.setTransactionSuccessful(); + } finally { + db.endTransaction(); } - writeUserDataIntoCacheLocked(accounts, db, account, key, value); - db.setTransactionSuccessful(); - } finally { - db.endTransaction(); } } @@ -4803,16 +4784,17 @@ public class AccountManagerService } } - protected String readUserDataInternalLocked( - UserAccounts accounts, Account account, String key) { - HashMap userDataForAccount = accounts.userDataCache.get(account); - if (userDataForAccount == null) { - // need to populate the cache for this account - final SQLiteDatabase db = accounts.openHelper.getReadableDatabase(); - userDataForAccount = readUserDataForAccountFromDatabaseLocked(db, account); - accounts.userDataCache.put(account, userDataForAccount); + protected String readUserDataInternal(UserAccounts accounts, Account account, String key) { + synchronized (accounts.cacheLock) { + HashMap userDataForAccount = accounts.userDataCache.get(account); + if (userDataForAccount == null) { + // need to populate the cache for this account + final SQLiteDatabase db = accounts.openHelper.getReadableDatabase(); + userDataForAccount = readUserDataForAccountFromDatabaseLocked(db, account); + accounts.userDataCache.put(account, userDataForAccount); + } + return userDataForAccount.get(key); } - return userDataForAccount.get(key); } protected HashMap readUserDataForAccountFromDatabaseLocked(