Delete PIM data during folder sync/reset

Bug: 3361000
Change-Id: I95305467c17c5c4b75b96dfb06c3c3511eb3f15a
This commit is contained in:
Marc Blank 2011-01-17 11:58:30 -08:00
parent d0e795af73
commit 67d7a741cf
2 changed files with 25 additions and 17 deletions

View File

@ -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;

View File

@ -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