public static void reloadFolderList(Context context, long accountId, boolean force) { SyncManager exchangeService = INSTANCE; if (exchangeService == null) return; Cursor c = context .getContentResolver() .query( Mailbox.CONTENT_URI, Mailbox.CONTENT_PROJECTION, MailboxColumns.ACCOUNT_KEY + "=? AND " + MailboxColumns.TYPE + "=?", new String[] { Long.toString(accountId), Long.toString(Mailbox.TYPE_EAS_ACCOUNT_MAILBOX) }, null); try { if (c.moveToFirst()) { synchronized (sSyncLock) { Mailbox mailbox = new Mailbox(); mailbox.restore(c); Account acct = Account.restoreAccountWithId(context, accountId); if (acct == null) { reloadFolderListFailed(accountId); return; } String syncKey = acct.mSyncKey; // No need to reload the list if we don't have one if (!force && (syncKey == null || syncKey.equals("0"))) { reloadFolderListFailed(accountId); return; } // Change all ping/push boxes to push/hold ContentValues cv = new ContentValues(); cv.put(Mailbox.SYNC_INTERVAL, Mailbox.CHECK_INTERVAL_PUSH_HOLD); context .getContentResolver() .update( Mailbox.CONTENT_URI, cv, WHERE_PUSH_OR_PING_NOT_ACCOUNT_MAILBOX, new String[] {Long.toString(accountId)}); log("Set push/ping boxes to push/hold"); long id = mailbox.mId; AbstractSyncService svc = exchangeService.mServiceMap.get(id); // Tell the service we're done if (svc != null) { synchronized (svc.getSynchronizer()) { svc.stop(); // Interrupt the thread so that it can stop Thread thread = svc.mThread; if (thread != null) { thread.setName(thread.getName() + " (Stopped)"); thread.interrupt(); } } // Abandon the service exchangeService.releaseMailbox(id); // And have it start naturally kick("reload folder list"); } } } } finally { c.close(); } }