Always delete from CE table in removeAccountInternal

Test: AMSTest passes
Bug: 32660831
Change-Id: Iad40bf151f885a86eb6b4e074e9ec83159277e47
This commit is contained in:
Fyodor Kupolov
2016-12-09 14:58:05 -08:00
parent 655d3dcb49
commit 98e9e85543
3 changed files with 13 additions and 10 deletions

View File

@@ -2136,14 +2136,17 @@ public class AccountManagerService
try {
accountId = accounts.accountsDb.findDeAccountId(account);
if (accountId >= 0) {
accounts.accountsDb.deleteDeAccount(accountId);
if (userUnlocked) {
// Delete from CE table
accounts.accountsDb.deleteCeAccount(accountId);
}
accounts.accountsDb.setTransactionSuccessful();
isChanged = true;
isChanged = accounts.accountsDb.deleteDeAccount(accountId);
}
// always delete from CE table if CE storage is available
// DE account could be removed while CE was locked
if (userUnlocked) {
long ceAccountId = accounts.accountsDb.findCeAccountId(account);
if (ceAccountId >= 0) {
accounts.accountsDb.deleteCeAccount(ceAccountId);
}
}
accounts.accountsDb.setTransactionSuccessful();
} finally {
accounts.accountsDb.endTransaction();
}

View File

@@ -1201,7 +1201,7 @@ class AccountsDb implements AutoCloseable {
}
boolean deleteCeAccount(long accountId) {
SQLiteDatabase db = mDeDatabase.getReadableDatabaseUserIsUnlocked();
SQLiteDatabase db = mDeDatabase.getWritableDatabaseUserIsUnlocked();
return db.delete(
CE_TABLE_ACCOUNTS, ACCOUNTS_ID + "=" + accountId, null) > 0;
}

View File

@@ -254,11 +254,11 @@ public class AccountManagerServiceTest extends AndroidTestCase {
// Unlock the user and verify that db has been updated
ams2.onUserUnlocked(newIntentForUser(UserHandle.USER_SYSTEM));
accountsNumber = readNumberOfAccountsFromDbFile(originalContext, ceDatabaseName);
assertEquals("CE database should now have 1 account", 2, accountsNumber);
accounts = ams2.getAccounts(UserHandle.USER_SYSTEM, mContext.getOpPackageName());
assertEquals(1, accounts.length);
assertEquals("Only a2 should be returned", a2, accounts[0]);
accountsNumber = readNumberOfAccountsFromDbFile(originalContext, ceDatabaseName);
assertEquals("CE database should now have 1 account", 1, accountsNumber);
}
@SmallTest