From 3b3b5b0f2b65bf7efb9474ece2d8d2821beeadc2 Mon Sep 17 00:00:00 2001 From: Andrew Stadler Date: Wed, 14 Apr 2010 21:58:43 -0700 Subject: [PATCH] Run the account reconciler every time we start SyncManager * This takes care of *some* of the race conditions where the account DB is blown away but the Email app is not running, so we don't get any notification of a change; We have to try and sort this out early. * SyncManager is started by Welcome, so this catches many cases of entering the email app. Bug: 2567986 Change-Id: I76bea5b636802ba5c1677d8b1825fb3c61f7b2d9 --- src/com/android/exchange/SyncManager.java | 46 +++++++++++++++-------- 1 file changed, 30 insertions(+), 16 deletions(-) diff --git a/src/com/android/exchange/SyncManager.java b/src/com/android/exchange/SyncManager.java index 4d33f0f9f..f9554891b 100644 --- a/src/com/android/exchange/SyncManager.java +++ b/src/com/android/exchange/SyncManager.java @@ -921,25 +921,36 @@ public class SyncManager extends Service implements Runnable { */ public class EasAccountsUpdatedListener implements OnAccountsUpdateListener { public void onAccountsUpdated(android.accounts.Account[] accounts) { - new Thread() { - @Override - public void run() { - SyncManager syncManager = INSTANCE; - if (syncManager != null) { - android.accounts.Account[] accountMgrList = AccountManager.get(syncManager) - .getAccountsByType(Email.EXCHANGE_ACCOUNT_MANAGER_TYPE); - synchronized (sAccountList) { - // Make sure we have an up-to-date sAccountList - mAccountObserver.onAccountChanged(); - reconcileAccountsWithAccountManager(syncManager, sAccountList, - accountMgrList, false, mResolver); - } - } - } - }.start(); + SyncManager syncManager = INSTANCE; + if (syncManager != null) { + syncManager.runAccountReconciler(); + } } } + /** + * Non-blocking call to run the account reconciler. + * Launches a worker thread, so it may be called from UI thread. + */ + private void runAccountReconciler() { + final SyncManager syncManager = this; + new Thread() { + @Override + public void run() { + android.accounts.Account[] accountMgrList = AccountManager.get(syncManager) + .getAccountsByType(Email.EXCHANGE_ACCOUNT_MANAGER_TYPE); + synchronized (sAccountList) { + // Make sure we have an up-to-date sAccountList + if (mAccountObserver != null) { + mAccountObserver.onAccountChanged(); + } + reconcileAccountsWithAccountManager(syncManager, sAccountList, + accountMgrList, false, mResolver); + } + } + }.start(); + } + protected static void log(String str) { if (Eas.USER_LOG) { Log.d(TAG, str); @@ -1059,6 +1070,9 @@ public class SyncManager extends Service implements Runnable { throw new RuntimeException(); } } + // Run the reconciler and clean up any mismatched accounts - if we weren't running when + // accounts were deleted, it won't have been called. + runAccountReconciler(); } @Override