From 998709ea4f47078c7532dba208b4cc818fe35463 Mon Sep 17 00:00:00 2001 From: Marc Blank Date: Thu, 11 Mar 2010 10:53:11 -0800 Subject: [PATCH] Fix #2507421 related to disabling Exchange calendars * The bug is that we shut off sync of the adapter when a calendar is disabled by the user. * Instead, we should change the sync interval to never (and set it back to push when the calendar is re-enabled) Bug: 2507421 Change-Id: Ieb61e458a0372e40e402691fc4d20b1b85b3a664 --- src/com/android/exchange/SyncManager.java | 27 ++++++++++++----------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/src/com/android/exchange/SyncManager.java b/src/com/android/exchange/SyncManager.java index bc97ebc5f..3cd8190b2 100644 --- a/src/com/android/exchange/SyncManager.java +++ b/src/com/android/exchange/SyncManager.java @@ -681,17 +681,15 @@ public class SyncManager extends Service implements Runnable { if (c.moveToFirst()) { long newSyncEvents = c.getLong(0); if (newSyncEvents != mSyncEvents) { - // The user has changed sync state; let SyncManager know - android.accounts.Account account = new android.accounts.Account( - mAccountName, Email.EXCHANGE_ACCOUNT_MANAGER_TYPE); - ContentResolver.setSyncAutomatically(account, Calendar.AUTHORITY, - newSyncEvents != 0); + Mailbox mailbox = Mailbox.restoreMailboxOfType(INSTANCE, + mAccountId, Mailbox.TYPE_CALENDAR); + // Sanity check for mailbox deletion + if (mailbox == null) return; + ContentValues cv = new ContentValues(); if (newSyncEvents == 0) { // When sync of a calendar is disabled, we're supposed to delete // all events in the calendar; this means we should first reset our // sync key to 0 - Mailbox mailbox = Mailbox.restoreMailboxOfType(INSTANCE, - mAccountId, Mailbox.TYPE_CALENDAR); EasSyncService service = new EasSyncService(INSTANCE, mailbox); CalendarSyncAdapter adapter = new CalendarSyncAdapter(mailbox, service); @@ -700,17 +698,22 @@ public class SyncManager extends Service implements Runnable { } catch (IOException e) { // The provider can't be reached; nothing to be done } - // Reset the sync key locally in the Mailbox - ContentValues cv = new ContentValues(); + // Reset the sync key locally in the Mailbox and set it not to sync cv.put(Mailbox.SYNC_KEY, "0"); - mResolver.update(ContentUris.withAppendedId( - Mailbox.CONTENT_URI, mailbox.mId), cv, null, null); + cv.put(Mailbox.SYNC_INTERVAL, Mailbox.CHECK_INTERVAL_NEVER); // Delete all events in this calendar mResolver.delete(Events.CONTENT_URI, WHERE_CALENDAR_ID, new String[] {Long.toString(mCalendarId)}); // TODO Stop sync in progress?? + } else { + // Set sync back to push + cv.put(Mailbox.SYNC_INTERVAL, Mailbox.CHECK_INTERVAL_PUSH); } + // Update the calendar mailbox with new settings + mResolver.update(ContentUris.withAppendedId( + Mailbox.CONTENT_URI, mailbox.mId), cv, null, null); + // Save away the new value mSyncEvents = newSyncEvents; } @@ -1812,8 +1815,6 @@ public class SyncManager extends Service implements Runnable { // Contacts/Calendar obey this setting from ContentResolver // Mail is on its own schedule boolean masterAutoSync = ContentResolver.getMasterSyncAutomatically(); - ConnectivityManager cm = - (ConnectivityManager)getSystemService(Context.CONNECTIVITY_SERVICE); try { while (c.moveToNext()) { long mid = c.getLong(Mailbox.CONTENT_ID_COLUMN);