OSDN Git Service

Always delete from CE table in removeAccountInternal
authorFyodor Kupolov <fkupolov@google.com>
Fri, 9 Dec 2016 22:58:05 +0000 (14:58 -0800)
committerFyodor Kupolov <fkupolov@google.com>
Fri, 9 Dec 2016 23:12:51 +0000 (15:12 -0800)
Test: AMSTest passes
Bug: 32660831
Change-Id: Iad40bf151f885a86eb6b4e074e9ec83159277e47

services/core/java/com/android/server/accounts/AccountManagerService.java
services/core/java/com/android/server/accounts/AccountsDb.java
services/tests/servicestests/src/com/android/server/accounts/AccountManagerServiceTest.java

index 8fd1d2f..c65aed7 100644 (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);
+                    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();
             }
index a160b3a..5ca7471 100644 (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;
     }
index 9c241d7..c74cda6 100644 (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