Merge "Make sure we delete all Events for disabled Calendars"
This commit is contained in:
commit
a5e2aa4057
@ -80,6 +80,7 @@ import android.os.PowerManager.WakeLock;
|
|||||||
import android.provider.Calendar;
|
import android.provider.Calendar;
|
||||||
import android.provider.ContactsContract;
|
import android.provider.ContactsContract;
|
||||||
import android.provider.Calendar.Calendars;
|
import android.provider.Calendar.Calendars;
|
||||||
|
import android.provider.Calendar.Events;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
import java.io.BufferedReader;
|
||||||
@ -154,6 +155,7 @@ public class SyncManager extends Service implements Runnable {
|
|||||||
+ " or " + MailboxColumns.SYNC_INTERVAL + "!=" + Mailbox.CHECK_INTERVAL_NEVER + ')'
|
+ " or " + MailboxColumns.SYNC_INTERVAL + "!=" + Mailbox.CHECK_INTERVAL_NEVER + ')'
|
||||||
+ " and " + MailboxColumns.ACCOUNT_KEY + " in (";
|
+ " and " + MailboxColumns.ACCOUNT_KEY + " in (";
|
||||||
private static final String ACCOUNT_KEY_IN = MailboxColumns.ACCOUNT_KEY + " in (";
|
private static final String ACCOUNT_KEY_IN = MailboxColumns.ACCOUNT_KEY + " in (";
|
||||||
|
private static final String WHERE_CALENDAR_ID = Events.CALENDAR_ID + "=?";
|
||||||
|
|
||||||
// Offsets into the syncStatus data for EAS that indicate type, exit status, and change count
|
// Offsets into the syncStatus data for EAS that indicate type, exit status, and change count
|
||||||
// The format is S<type_char>:<exit_char>:<change_count>
|
// The format is S<type_char>:<exit_char>:<change_count>
|
||||||
@ -685,8 +687,9 @@ public class SyncManager extends Service implements Runnable {
|
|||||||
ContentResolver.setSyncAutomatically(account, Calendar.AUTHORITY,
|
ContentResolver.setSyncAutomatically(account, Calendar.AUTHORITY,
|
||||||
newSyncEvents != 0);
|
newSyncEvents != 0);
|
||||||
if (newSyncEvents == 0) {
|
if (newSyncEvents == 0) {
|
||||||
// For some reason, CalendarProvider deletes all Events in this
|
// When sync of a calendar is disabled, we're supposed to delete
|
||||||
// case; this means that we have to reset our sync key
|
// all events in the calendar; this means we should first reset our
|
||||||
|
// sync key to 0
|
||||||
Mailbox mailbox = Mailbox.restoreMailboxOfType(INSTANCE,
|
Mailbox mailbox = Mailbox.restoreMailboxOfType(INSTANCE,
|
||||||
mAccountId, Mailbox.TYPE_CALENDAR);
|
mAccountId, Mailbox.TYPE_CALENDAR);
|
||||||
EasSyncService service = new EasSyncService(INSTANCE, mailbox);
|
EasSyncService service = new EasSyncService(INSTANCE, mailbox);
|
||||||
@ -697,11 +700,14 @@ public class SyncManager extends Service implements Runnable {
|
|||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
// The provider can't be reached; nothing to be done
|
// The provider can't be reached; nothing to be done
|
||||||
}
|
}
|
||||||
|
// Reset the sync key locally in the Mailbox
|
||||||
ContentValues cv = new ContentValues();
|
ContentValues cv = new ContentValues();
|
||||||
cv.put(Mailbox.SYNC_KEY, "0");
|
cv.put(Mailbox.SYNC_KEY, "0");
|
||||||
mResolver.update(ContentUris.withAppendedId(
|
mResolver.update(ContentUris.withAppendedId(
|
||||||
Mailbox.CONTENT_URI, mailbox.mId), cv, null, null);
|
Mailbox.CONTENT_URI, mailbox.mId), cv, null, null);
|
||||||
|
// Delete all events in this calendar
|
||||||
|
mResolver.delete(Events.CONTENT_URI, WHERE_CALENDAR_ID,
|
||||||
|
new String[] {Long.toString(mCalendarId)});
|
||||||
// TODO Stop sync in progress??
|
// TODO Stop sync in progress??
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user