Merge "Fix some nasty bugs w/ Exchange calendar upsync"

This commit is contained in:
Marc Blank 2010-02-25 11:59:39 -08:00 committed by Android (Google) Code Review
commit 1270218f32

View File

@ -70,10 +70,12 @@ public class CalendarSyncAdapter extends AbstractSyncAdapter {
// there's no original event when finding an item by _SYNC_ID // there's no original event when finding an item by _SYNC_ID
private static final String SERVER_ID = Events._SYNC_ID + "=? AND " + private static final String SERVER_ID = Events._SYNC_ID + "=? AND " +
Events.ORIGINAL_EVENT + " ISNULL"; Events.ORIGINAL_EVENT + " ISNULL";
private static final String DIRTY_TOP_LEVEL = private static final String DIRTY_TOP_LEVEL_IN_CALENDAR =
Events._SYNC_DIRTY + "=1 AND " + Events.ORIGINAL_EVENT + " ISNULL"; Events._SYNC_DIRTY + "=1 AND " + Events.ORIGINAL_EVENT + " ISNULL AND " +
private static final String DIRTY_EXCEPTION = Events.CALENDAR_ID + "=?";
Events._SYNC_DIRTY + "=1 AND " + Events.ORIGINAL_EVENT + " NOTNULL"; private static final String DIRTY_EXCEPTION_IN_CALENDAR =
Events._SYNC_DIRTY + "=1 AND " + Events.ORIGINAL_EVENT + " NOTNULL AND " +
Events.CALENDAR_ID + "=?";
private static final String DIRTY_IN_CALENDAR = private static final String DIRTY_IN_CALENDAR =
Events._SYNC_DIRTY + "=1 AND " + Events.CALENDAR_ID + "=?"; Events._SYNC_DIRTY + "=1 AND " + Events.CALENDAR_ID + "=?";
private static final String CLIENT_ID_SELECTION = Events._SYNC_LOCAL_ID + "=?"; private static final String CLIENT_ID_SELECTION = Events._SYNC_LOCAL_ID + "=?";
@ -102,6 +104,8 @@ public class CalendarSyncAdapter extends AbstractSyncAdapter {
private ArrayList<Long> mDeletedIdList = new ArrayList<Long>(); private ArrayList<Long> mDeletedIdList = new ArrayList<Long>();
private ArrayList<Long> mUpdatedIdList = new ArrayList<Long>(); private ArrayList<Long> mUpdatedIdList = new ArrayList<Long>();
private String[] mCalendarIdArgument;
public CalendarSyncAdapter(Mailbox mailbox, EasSyncService service) { public CalendarSyncAdapter(Mailbox mailbox, EasSyncService service) {
super(mailbox, service); super(mailbox, service);
@ -114,6 +118,7 @@ public class CalendarSyncAdapter extends AbstractSyncAdapter {
} else { } else {
mCalendarId = CalendarUtilities.createCalendar(mService, mAccount, mMailbox); mCalendarId = CalendarUtilities.createCalendar(mService, mAccount, mMailbox);
} }
mCalendarIdArgument = new String[] {Long.toString(mCalendarId)};
} finally { } finally {
c.close(); c.close();
} }
@ -976,6 +981,24 @@ public class CalendarSyncAdapter extends AbstractSyncAdapter {
boolean isException = (clientId == null); boolean isException = (clientId == null);
boolean hasAttendees = false; boolean hasAttendees = false;
if (!isException) {
// A time zone is required in all EAS events; we'll use the default if none is set
// Exchange 2003 seems to require this first... :-)
String timeZoneName = entityValues.getAsString(Events.EVENT_TIMEZONE);
if (timeZoneName == null) {
timeZoneName = TimeZone.getDefault().getID();
}
String timeZone = CalendarUtilities.timeZoneToTziString(
TimeZone.getTimeZone(timeZoneName));
s.data(Tags.CALENDAR_TIME_ZONE, timeZone);
}
if (mService.mProtocolVersionDouble < 12.0) {
// We need BusyStatus for 2.5, so we'll send "busy", which is what OWA does.
// Calendar doesn't support free/busy yet
s.data(Tags.CALENDAR_BUSY_STATUS, "2");
}
if (entityValues.containsKey(Events.ALL_DAY)) { if (entityValues.containsKey(Events.ALL_DAY)) {
Integer ade = entityValues.getAsInteger(Events.ALL_DAY); Integer ade = entityValues.getAsInteger(Events.ALL_DAY);
s.data(Tags.CALENDAR_ALL_DAY_EVENT, ade.toString()); s.data(Tags.CALENDAR_ALL_DAY_EVENT, ade.toString());
@ -1018,15 +1041,6 @@ public class CalendarSyncAdapter extends AbstractSyncAdapter {
} }
if (!isException) { if (!isException) {
// A time zone is required in all EAS events; we'll use the default if none is set
String timeZoneName = entityValues.getAsString(Events.EVENT_TIMEZONE);
if (timeZoneName == null) {
timeZoneName = TimeZone.getDefault().getID();
}
String timeZone = CalendarUtilities.timeZoneToTziString(
TimeZone.getTimeZone(timeZoneName));
s.data(Tags.CALENDAR_TIME_ZONE, timeZone);
String desc = entityValues.getAsString(Events.DESCRIPTION); String desc = entityValues.getAsString(Events.DESCRIPTION);
if (desc != null) { if (desc != null) {
if (mService.mProtocolVersionDouble >= 12.0) { if (mService.mProtocolVersionDouble >= 12.0) {
@ -1105,7 +1119,9 @@ public class CalendarSyncAdapter extends AbstractSyncAdapter {
} }
s.data(Tags.CALENDAR_ATTENDEE_NAME, attendeeName); s.data(Tags.CALENDAR_ATTENDEE_NAME, attendeeName);
s.data(Tags.CALENDAR_ATTENDEE_EMAIL, attendeeEmail); s.data(Tags.CALENDAR_ATTENDEE_EMAIL, attendeeEmail);
s.data(Tags.CALENDAR_ATTENDEE_TYPE, "1"); // Required if (mService.mProtocolVersionDouble >= 12.0) {
s.data(Tags.CALENDAR_ATTENDEE_TYPE, "1"); // Required
}
s.end(); // Attendee s.end(); // Attendee
} }
} }
@ -1144,8 +1160,8 @@ public class CalendarSyncAdapter extends AbstractSyncAdapter {
try { try {
// We've got to handle exceptions as part of the parent when changes occur, so we need // We've got to handle exceptions as part of the parent when changes occur, so we need
// to find new/changed exceptions and mark the parent dirty // to find new/changed exceptions and mark the parent dirty
Cursor c = cr.query(Events.CONTENT_URI, ORIGINAL_EVENT_PROJECTION, DIRTY_EXCEPTION, Cursor c = cr.query(Events.CONTENT_URI, ORIGINAL_EVENT_PROJECTION,
null, null); DIRTY_EXCEPTION_IN_CALENDAR, mCalendarIdArgument, null);
try { try {
ContentValues cv = new ContentValues(); ContentValues cv = new ContentValues();
cv.put(Events._SYNC_DIRTY, 1); cv.put(Events._SYNC_DIRTY, 1);
@ -1161,14 +1177,14 @@ public class CalendarSyncAdapter extends AbstractSyncAdapter {
// Now we can go through dirty top-level events and send them back to the server // Now we can go through dirty top-level events and send them back to the server
EntityIterator eventIterator = EventsEntity.newEntityIterator( EntityIterator eventIterator = EventsEntity.newEntityIterator(
cr.query(uri, null, DIRTY_TOP_LEVEL, null, null), cr); cr.query(uri, null, DIRTY_TOP_LEVEL_IN_CALENDAR,
mCalendarIdArgument, null), cr);
ContentValues cidValues = new ContentValues(); ContentValues cidValues = new ContentValues();
try { try {
boolean first = true; boolean first = true;
while (eventIterator.hasNext()) { while (eventIterator.hasNext()) {
Entity entity = eventIterator.next(); Entity entity = eventIterator.next();
String clientId = UUID.randomUUID().toString(); String clientId = UUID.randomUUID().toString();
// For each of these entities, create the change commands // For each of these entities, create the change commands
ContentValues entityValues = entity.getEntityValues(); ContentValues entityValues = entity.getEntityValues();
String serverId = entityValues.getAsString(Events._SYNC_ID); String serverId = entityValues.getAsString(Events._SYNC_ID);
@ -1182,8 +1198,6 @@ public class CalendarSyncAdapter extends AbstractSyncAdapter {
|| organizerEmail == null) { || organizerEmail == null) {
continue; continue;
} }
// TODO Handle BusyStatus for EAS 2.5
// What should it be??
if (first) { if (first) {
s.start(Tags.SYNC_COMMANDS); s.start(Tags.SYNC_COMMANDS);