Exceptions to recurring events are not deleted

If an exception from a recurring event is created
from the server and then the whole event serie is
deleted from the phone client the exceptions will be left
in the calendar database.
This is because it is up to the phone client to delete
the events that is marked to be deleted. No delete
commands will be returned by the exchange server to
the client that orders the deletion of the recurring series.

The problem is that the phone client only deletes the main
recurring event and does nothing to the exceptions, which
lead to ghost events in the calendar database. This fix makes
sure that all events related to the main event are deleted.

Change-Id: Ief5f693cc5d05b28df42a26020c0997a344a5f35
diff --git a/exchange2/src/com/android/exchange/adapter/CalendarSyncAdapter.java b/exchange2/src/com/android/exchange/adapter/CalendarSyncAdapter.java
index c9c3ba2..b1b8411 100644
--- a/exchange2/src/com/android/exchange/adapter/CalendarSyncAdapter.java
+++ b/exchange2/src/com/android/exchange/adapter/CalendarSyncAdapter.java
@@ -101,6 +101,7 @@
         new String[] {Events.ORIGINAL_ID, Events._ID};
     private static final String EVENT_ID_AND_NAME =
         ExtendedProperties.EVENT_ID + "=? AND " + ExtendedProperties.NAME + "=?";
+    private static final String ORIGINAL_EVENT_ID = Events.ORIGINAL_ID + "=?";
 
     // Note that we use LIKE below for its case insensitivity
     private static final String EVENT_AND_EMAIL  =
@@ -1262,6 +1263,13 @@
                                         ContentUris.withAppendedId(Events.CONTENT_URI, eventId),
                                         mEmailAddress, Eas.EXCHANGE_ACCOUNT_MANAGER_TYPE), null,
                                 null);
+                        // If the event is a recurring event we must make sure
+                        // that all exceptions are deleted as well
+                        mContentResolver.delete(
+                                asSyncAdapter(
+                                        Events.CONTENT_URI, mEmailAddress,
+                                        Eas.EXCHANGE_ACCOUNT_MANAGER_TYPE), ORIGINAL_EVENT_ID,
+                                new String[] {Long.toString(eventId)});
                     }
                 }
                 // Send any queued up email (invitations replies, etc.)