From 67d7a741cf4585cf09666eb8b8ec12bc26b2b6bf Mon Sep 17 00:00:00 2001 From: Marc Blank Date: Mon, 17 Jan 2011 11:58:30 -0800 Subject: [PATCH] Delete PIM data during folder sync/reset Bug: 3361000 Change-Id: I95305467c17c5c4b75b96dfb06c3c3511eb3f15a --- src/com/android/exchange/ExchangeService.java | 39 +++++++++++-------- .../exchange/adapter/FolderSyncParser.java | 3 ++ 2 files changed, 25 insertions(+), 17 deletions(-) diff --git a/src/com/android/exchange/ExchangeService.java b/src/com/android/exchange/ExchangeService.java index e9e2af7e4..5f7fad803 100644 --- a/src/com/android/exchange/ExchangeService.java +++ b/src/com/android/exchange/ExchangeService.java @@ -462,24 +462,10 @@ public class ExchangeService extends Service implements Runnable { * @throws RemoteException */ public void deleteAccountPIMData(long accountId) throws RemoteException { - ExchangeService exchangeService = INSTANCE; - if (exchangeService == null) return; // Stop any running syncs - exchangeService.stopAccountSyncs(accountId, true); - Mailbox mailbox = - Mailbox.restoreMailboxOfType(exchangeService, accountId, Mailbox.TYPE_CONTACTS); - if (mailbox != null) { - EasSyncService service = new EasSyncService(exchangeService, mailbox); - ContactsSyncAdapter adapter = new ContactsSyncAdapter(service); - adapter.wipe(); - } - mailbox = - Mailbox.restoreMailboxOfType(exchangeService, accountId, Mailbox.TYPE_CALENDAR); - if (mailbox != null) { - EasSyncService service = new EasSyncService(exchangeService, mailbox); - CalendarSyncAdapter adapter = new CalendarSyncAdapter(service); - adapter.wipe(); - } + ExchangeService.stopAccountSyncs(accountId); + // Delete the data + ExchangeService.deleteAccountPIMData(accountId); } }; @@ -514,6 +500,25 @@ public class ExchangeService extends Service implements Runnable { } } + public static void deleteAccountPIMData(long accountId) { + ExchangeService exchangeService = INSTANCE; + if (exchangeService == null) return; + Mailbox mailbox = + Mailbox.restoreMailboxOfType(exchangeService, accountId, Mailbox.TYPE_CONTACTS); + if (mailbox != null) { + EasSyncService service = new EasSyncService(exchangeService, mailbox); + ContactsSyncAdapter adapter = new ContactsSyncAdapter(service); + adapter.wipe(); + } + mailbox = + Mailbox.restoreMailboxOfType(exchangeService, accountId, Mailbox.TYPE_CALENDAR); + if (mailbox != null) { + EasSyncService service = new EasSyncService(exchangeService, mailbox); + CalendarSyncAdapter adapter = new CalendarSyncAdapter(service); + adapter.wipe(); + } + } + class AccountObserver extends ContentObserver { String mSyncableEasMailboxSelector = null; String mEasAccountSelector = null; diff --git a/src/com/android/exchange/adapter/FolderSyncParser.java b/src/com/android/exchange/adapter/FolderSyncParser.java index ae20fd958..84c4be12d 100644 --- a/src/com/android/exchange/adapter/FolderSyncParser.java +++ b/src/com/android/exchange/adapter/FolderSyncParser.java @@ -129,6 +129,9 @@ public class FolderSyncParser extends AbstractSyncParser { if (status == Eas.FOLDER_STATUS_INVALID_KEY) { mAccount.mSyncKey = "0"; mService.errorLog("Bad sync key; RESET and delete all folders"); + // Delete PIM data first + ExchangeService.deleteAccountPIMData(mAccountId); + // Then, delete mailboxes mContentResolver.delete(Mailbox.CONTENT_URI, ALL_BUT_ACCOUNT_MAILBOX, new String[] {Long.toString(mAccountId)}); // Stop existing syncs and reconstruct _main