try {
accountId = accounts.accountsDb.findDeAccountId(account);
if (accountId >= 0) {
- accounts.accountsDb.deleteDeAccount(accountId);
- if (userUnlocked) {
- // Delete from CE table
- accounts.accountsDb.deleteCeAccount(accountId);
+ 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();
- isChanged = true;
}
+ accounts.accountsDb.setTransactionSuccessful();
} finally {
accounts.accountsDb.endTransaction();
}
}
boolean deleteCeAccount(long accountId) {
- SQLiteDatabase db = mDeDatabase.getReadableDatabaseUserIsUnlocked();
+ SQLiteDatabase db = mDeDatabase.getWritableDatabaseUserIsUnlocked();
return db.delete(
CE_TABLE_ACCOUNTS, ACCOUNTS_ID + "=" + accountId, null) > 0;
}
// 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