Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 327c7e4c authored by Carlos Valdivia's avatar Carlos Valdivia Committed by Android (Google) Code Review
Browse files

Merge "Only broadcast LOGIN_ACCOUNTS_CHANGED when changes occur." into nyc-mr1-dev

parents 94673f0b 98b5f9da
Loading
Loading
Loading
Loading
+81 −61
Original line number Diff line number Diff line
@@ -1225,11 +1225,13 @@ public class AccountManagerService
            } finally {
                db.endTransaction();
            }
            sendAccountsChangedBroadcast(accounts.userId);
        }
        if (getUserManager().getUserInfo(accounts.userId).canHaveProfile()) {
            addAccountToLinkedRestrictedUsers(account, accounts.userId);
        }

        // Only send LOGIN_ACCOUNTS_CHANGED when the database changed.
        sendAccountsChangedBroadcast(accounts.userId);
        return true;
    }

@@ -1412,7 +1414,6 @@ public class AccountManagerService
        synchronized (accounts.cacheLock) {
            final SQLiteDatabase db = accounts.openHelper.getWritableDatabaseUserIsUnlocked();
            db.beginTransaction();
            boolean isSuccessful = false;
            Account renamedAccount = new Account(newName, accountToRename.type);
            try {
                final long accountId = getAccountIdLocked(db, accountToRename);
@@ -1425,13 +1426,12 @@ public class AccountManagerService
                    values.put(ACCOUNTS_PREVIOUS_NAME, accountToRename.name);
                    db.update(TABLE_ACCOUNTS, values, ACCOUNTS_ID + "=?", argsAccountId);
                    db.setTransactionSuccessful();
                    isSuccessful = true;
                    logRecord(db, DebugDbHelper.ACTION_ACCOUNT_RENAME, TABLE_ACCOUNTS, accountId,
                            accounts);
                }
            } finally {
                db.endTransaction();
                if (isSuccessful) {
            }
            /*
             * Database transaction was successful. Clean up cached
             * data associated with the account in the user profile.
@@ -1472,8 +1472,6 @@ public class AccountManagerService
            }
            sendAccountsChangedBroadcast(accounts.userId);
        }
            }
        }
        return resultAccount;
    }

@@ -1653,7 +1651,7 @@ public class AccountManagerService
    }

    private boolean removeAccountInternal(UserAccounts accounts, Account account, int callingUid) {
        int deleted;
        boolean isChanged = false;
        boolean userUnlocked = isLocalUnlockedUser(accounts.userId);
        if (!userUnlocked) {
            Slog.i(TAG, "Removing account " + account + " while user "+ accounts.userId
@@ -1663,26 +1661,39 @@ public class AccountManagerService
            final SQLiteDatabase db = userUnlocked
                    ? accounts.openHelper.getWritableDatabaseUserIsUnlocked()
                    : accounts.openHelper.getWritableDatabase();
            final long accountId = getAccountIdLocked(db, account);
            db.beginTransaction();
            // Set to a dummy value, this will only be used if the database
            // transaction succeeds.
            long accountId = -1;
            try {
                deleted = db.delete(TABLE_ACCOUNTS, ACCOUNTS_NAME + "=? AND " + ACCOUNTS_TYPE
                                + "=?", new String[]{account.name, account.type});
                accountId = getAccountIdLocked(db, account);
                if (accountId >= 0) {
                    db.delete(
                            TABLE_ACCOUNTS,
                            ACCOUNTS_NAME + "=? AND " + ACCOUNTS_TYPE + "=?",
                            new String[]{ account.name, account.type });
                    if (userUnlocked) {
                        // Delete from CE table
                    deleted = db.delete(CE_TABLE_ACCOUNTS, ACCOUNTS_NAME + "=? AND " + ACCOUNTS_TYPE
                            + "=?", new String[]{account.name, account.type});
                        db.delete(
                                CE_TABLE_ACCOUNTS,
                                ACCOUNTS_NAME + "=? AND " + ACCOUNTS_TYPE + "=?",
                                new String[]{ account.name, account.type });
                    }
                    db.setTransactionSuccessful();
                    isChanged = true;
                }
            } finally {
                db.endTransaction();
            }
            if (isChanged) {
                removeAccountFromCacheLocked(accounts, account);
                // Only broadcast LOGIN_ACCOUNTS_CHANGED if a change occured.
                sendAccountsChangedBroadcast(accounts.userId);
                String action = userUnlocked ? DebugDbHelper.ACTION_ACCOUNT_REMOVE
                        : DebugDbHelper.ACTION_ACCOUNT_REMOVE_DE;
                logRecord(db, action, TABLE_ACCOUNTS, accountId, accounts);
            }
        }
        long id = Binder.clearCallingIdentity();
        try {
            int parentUserId = accounts.userId;
@@ -1698,7 +1709,7 @@ public class AccountManagerService
        } finally {
            Binder.restoreCallingIdentity(id);
        }
        return (deleted > 0);
        return isChanged;
    }

    @Override
@@ -1922,6 +1933,7 @@ public class AccountManagerService
        if (account == null) {
            return;
        }
        boolean isChanged = false;
        synchronized (accounts.cacheLock) {
            final SQLiteDatabase db = accounts.openHelper.getWritableDatabaseUserIsUnlocked();
            db.beginTransaction();
@@ -1931,12 +1943,17 @@ public class AccountManagerService
                final long accountId = getAccountIdLocked(db, account);
                if (accountId >= 0) {
                    final String[] argsAccountId = {String.valueOf(accountId)};
                    db.update(CE_TABLE_ACCOUNTS, values, ACCOUNTS_ID + "=?", argsAccountId);
                    db.delete(CE_TABLE_AUTHTOKENS, AUTHTOKENS_ACCOUNTS_ID + "=?", argsAccountId);
                    db.update(
                            CE_TABLE_ACCOUNTS, values, ACCOUNTS_ID + "=?", argsAccountId);
                    db.delete(
                            CE_TABLE_AUTHTOKENS, AUTHTOKENS_ACCOUNTS_ID + "=?", argsAccountId);
                    accounts.authTokenCache.remove(account);
                    accounts.accountTokenCaches.remove(account);
                    db.setTransactionSuccessful();

                    // If there is an account whose password will be updated and the database
                    // transactions succeed, then we say that a change has occured. Even if the
                    // new password is the same as the old and there were no authtokens to delete.
                    isChanged = true;
                    String action = (password == null || password.length() == 0) ?
                            DebugDbHelper.ACTION_CLEAR_PASSWORD
                            : DebugDbHelper.ACTION_SET_PASSWORD;
@@ -1944,10 +1961,13 @@ public class AccountManagerService
                }
            } finally {
                db.endTransaction();
            }
                if (isChanged) {
                    // Send LOGIN_ACCOUNTS_CHANGED only if the something changed.
                    sendAccountsChangedBroadcast(accounts.userId);
                }
            }
        }
    }

    private void sendAccountsChangedBroadcast(int userId) {
        Log.i(TAG, "the accounts changed, sending broadcast of "