1.1 --- a/src/org/gege/caldavsyncadapter/syncadapter/SyncAdapter.java Tue Feb 10 21:55:00 2015 +0100 1.2 +++ b/src/org/gege/caldavsyncadapter/syncadapter/SyncAdapter.java Tue Feb 10 22:40:00 2015 +0100 1.3 @@ -1,6 +1,6 @@ 1.4 /** 1.5 * Copyright (c) 2012-2013, Gerald Garcia, David Wiesner, Timo Berger 1.6 - * 1.7 + * 1.8 * This file is part of Andoid Caldav Sync Adapter Free. 1.9 * 1.10 * Andoid Caldav Sync Adapter Free is free software: you can redistribute 1.11 @@ -16,36 +16,11 @@ 1.12 * You should have received a copy of the GNU General Public License 1.13 * along with Andoid Caldav Sync Adapter Free. 1.14 * If not, see <http://www.gnu.org/licenses/>. 1.15 - * 1.16 + * 1.17 */ 1.18 1.19 package org.gege.caldavsyncadapter.syncadapter; 1.20 1.21 -import java.io.IOException; 1.22 -import java.net.URI; 1.23 -//import java.net.MalformedURLException; 1.24 -import java.net.URISyntaxException; 1.25 -import java.util.ArrayList; 1.26 -//import java.security.GeneralSecurityException; 1.27 - 1.28 -import javax.xml.parsers.ParserConfigurationException; 1.29 - 1.30 -import net.fortuna.ical4j.data.ParserException; 1.31 - 1.32 -import org.apache.http.ParseException; 1.33 -import org.apache.http.client.ClientProtocolException; 1.34 -import org.gege.caldavsyncadapter.Event; 1.35 -import org.gege.caldavsyncadapter.android.entities.AndroidEvent; 1.36 -import org.gege.caldavsyncadapter.authenticator.AuthenticatorActivity; 1.37 -import org.gege.caldavsyncadapter.caldav.CaldavFacade; 1.38 -import org.gege.caldavsyncadapter.caldav.CaldavProtocolException; 1.39 -import org.gege.caldavsyncadapter.caldav.entities.DavCalendar; 1.40 -import org.gege.caldavsyncadapter.caldav.entities.CalendarEvent; 1.41 -import org.gege.caldavsyncadapter.caldav.entities.CalendarList; 1.42 -import org.gege.caldavsyncadapter.caldav.entities.DavCalendar.CalendarSource; 1.43 -import org.gege.caldavsyncadapter.syncadapter.notifications.NotificationsHelper; 1.44 -import org.xml.sax.SAXException; 1.45 - 1.46 import android.accounts.Account; 1.47 import android.accounts.AccountManager; 1.48 import android.content.AbstractThreadedSyncAdapter; 1.49 @@ -66,18 +41,45 @@ 1.50 import android.provider.CalendarContract.Reminders; 1.51 import android.util.Log; 1.52 1.53 +import net.fortuna.ical4j.data.ParserException; 1.54 + 1.55 +import org.apache.http.ParseException; 1.56 +import org.apache.http.client.ClientProtocolException; 1.57 +import org.gege.caldavsyncadapter.Constants; 1.58 +import org.gege.caldavsyncadapter.Event; 1.59 +import org.gege.caldavsyncadapter.android.entities.AndroidEvent; 1.60 +import org.gege.caldavsyncadapter.authenticator.AuthenticatorActivity; 1.61 +import org.gege.caldavsyncadapter.caldav.CaldavFacade; 1.62 +import org.gege.caldavsyncadapter.caldav.CaldavProtocolException; 1.63 +import org.gege.caldavsyncadapter.caldav.entities.CalendarEvent; 1.64 +import org.gege.caldavsyncadapter.caldav.entities.CalendarList; 1.65 +import org.gege.caldavsyncadapter.caldav.entities.DavCalendar; 1.66 +import org.gege.caldavsyncadapter.caldav.entities.DavCalendar.CalendarSource; 1.67 +import org.gege.caldavsyncadapter.syncadapter.notifications.NotificationsHelper; 1.68 +import org.xml.sax.SAXException; 1.69 + 1.70 +import java.io.IOException; 1.71 +import java.net.URI; 1.72 +import java.net.URISyntaxException; 1.73 +import java.util.ArrayList; 1.74 + 1.75 +import javax.xml.parsers.ParserConfigurationException; 1.76 + 1.77 +//import java.net.MalformedURLException; 1.78 +//import java.security.GeneralSecurityException; 1.79 + 1.80 public class SyncAdapter extends AbstractThreadedSyncAdapter { 1.81 1.82 - private static final String TAG = "SyncAdapter"; 1.83 - private AccountManager mAccountManager; 1.84 - private String mVersion = ""; 1.85 - private int mCountPerformSync = 0; 1.86 - private int mCountSyncCanceled = 0; 1.87 - private int mCountProviderFailed = 0; 1.88 - 1.89 - private int mCountProviderFailedMax = 3; 1.90 + private static final String TAG = "SyncAdapter"; 1.91 + private AccountManager mAccountManager; 1.92 + private String mVersion = ""; 1.93 + private int mCountPerformSync = 0; 1.94 + private int mCountSyncCanceled = 0; 1.95 + private int mCountProviderFailed = 0; 1.96 + 1.97 + private int mCountProviderFailedMax = 3; 1.98 // private Context mContext; 1.99 - 1.100 + 1.101 1.102 /* private static final String[] CALENDAR_PROJECTION = new String[] { 1.103 Calendars._ID, // 0 1.104 @@ -102,81 +104,87 @@ 1.105 Events.CALENDAR_ID 1.106 }; 1.107 */ 1.108 - 1.109 - // ignore same CTag 1.110 - //private static final boolean FORCE_SYNCHRONIZE = false; 1.111 - // drop all calendar before synchro 1.112 - //private static final boolean DROP_CALENDAR_EVENTS = false; 1.113 - 1.114 - public SyncAdapter(Context context, boolean autoInitialize) { 1.115 - super(context, autoInitialize); 1.116 - //android.os.Debug.waitForDebugger(); 1.117 - mAccountManager = AccountManager.get(context); 1.118 - try { 1.119 - mVersion = context.getPackageManager().getPackageInfo(context.getPackageName(), 0).versionName; 1.120 - } catch (NameNotFoundException e) { 1.121 - e.printStackTrace(); 1.122 - } 1.123 + 1.124 + // ignore same CTag 1.125 + //private static final boolean FORCE_SYNCHRONIZE = false; 1.126 + // drop all calendar before synchro 1.127 + //private static final boolean DROP_CALENDAR_EVENTS = false; 1.128 + 1.129 + public SyncAdapter(Context context, boolean autoInitialize) { 1.130 + super(context, autoInitialize); 1.131 + //android.os.Debug.waitForDebugger(); 1.132 + mAccountManager = AccountManager.get(context); 1.133 + try { 1.134 + mVersion = context.getPackageManager() 1.135 + .getPackageInfo(context.getPackageName(), 0).versionName; 1.136 + } catch (NameNotFoundException e) { 1.137 + e.printStackTrace(); 1.138 + } 1.139 // mContext = context; 1.140 - } 1.141 + } 1.142 1.143 - @Override 1.144 - public void onPerformSync(Account account, Bundle extras, String authority, 1.145 - ContentProviderClient provider, SyncResult syncResult) { 1.146 - boolean bolError = false; 1.147 - 1.148 - String url = mAccountManager.getUserData(account, AuthenticatorActivity.USER_DATA_URL_KEY); 1.149 - this.mCountPerformSync += 1; 1.150 - Log.v(TAG, "onPerformSync() count:" + String.valueOf(this.mCountPerformSync) + " on " + account.name + " with URL " + url); 1.151 + @Override 1.152 + public void onPerformSync(Account account, Bundle extras, String authority, 1.153 + ContentProviderClient provider, SyncResult syncResult) { 1.154 + boolean bolError = false; 1.155 1.156 - CalendarList serverCalList; 1.157 - 1.158 - CalendarList androidCalList = new CalendarList(account, provider, CalendarSource.Android, url); 1.159 - androidCalList.readCalendarFromClient(); 1.160 - ArrayList<Uri> notifyList = new ArrayList<Uri>(); 1.161 + String url = mAccountManager.getUserData(account, AuthenticatorActivity.USER_DATA_URL_KEY); 1.162 + String trust = mAccountManager.getUserData(account, Constants.USER_DATA_TRUST_ALL_KEY); 1.163 + this.mCountPerformSync += 1; 1.164 + Log.v(TAG, "onPerformSync() count:" + String.valueOf(this.mCountPerformSync) + " on " + account.name + " with URL " + url); 1.165 1.166 - try { 1.167 - String Username = ""; 1.168 - String UserDataVersion = mAccountManager.getUserData(account, AuthenticatorActivity.USER_DATA_VERSION); 1.169 - if (UserDataVersion == null) { 1.170 - Username = account.name; 1.171 - } else { 1.172 - Username = mAccountManager.getUserData(account, AuthenticatorActivity.USER_DATA_USERNAME); 1.173 - } 1.174 + CalendarList serverCalList; 1.175 1.176 - CaldavFacade facade = new CaldavFacade(Username, mAccountManager.getPassword(account), url); 1.177 - facade.setAccount(account); 1.178 - facade.setProvider(provider); 1.179 - facade.setVersion(mVersion); 1.180 - serverCalList = facade.getCalendarList(this.getContext()); 1.181 - //String davProperties = facade.getLastDav(); 1.182 - Log.i(TAG, String.valueOf(androidCalList.getCalendarList().size()) + " calendars found at android"); 1.183 - 1.184 - for (DavCalendar serverCalendar : serverCalList.getCalendarList()) { 1.185 - Log.i(TAG, "Detected calendar name=" + serverCalendar.getCalendarDisplayName() + " URI=" + serverCalendar.getURI()); 1.186 + CalendarList androidCalList = new CalendarList(account, provider, CalendarSource.Android, url); 1.187 + androidCalList.readCalendarFromClient(); 1.188 + ArrayList<Uri> notifyList = new ArrayList<Uri>(); 1.189 1.190 - Uri androidCalendarUri = serverCalendar.checkAndroidCalendarList(androidCalList, this.getContext()); 1.191 + try { 1.192 + String Username = ""; 1.193 + String UserDataVersion = mAccountManager.getUserData(account, AuthenticatorActivity.USER_DATA_VERSION); 1.194 + if (UserDataVersion == null) { 1.195 + Username = account.name; 1.196 + } else { 1.197 + Username = mAccountManager.getUserData(account, AuthenticatorActivity.USER_DATA_USERNAME); 1.198 + } 1.199 1.200 - // check if the adapter was able to get an existing calendar or create a new one 1.201 - if (androidCalendarUri != null) { 1.202 - // the provider seems to work correct, reset the counter 1.203 - mCountProviderFailed = 0; 1.204 - DavCalendar androidCalendar = androidCalList.getCalendarByAndroidUri(androidCalendarUri); 1.205 - 1.206 - //if ((FORCE_SYNCHRONIZE) || (androidCalendar.getcTag() == null) || (!androidCalendar.getcTag().equals(serverCalendar.getcTag()))) { 1.207 - if ((androidCalendar.getcTag() == null) || (!androidCalendar.getcTag().equals(serverCalendar.getcTag()))) { 1.208 - Log.d(TAG, "CTag has changed, something to synchronise"); 1.209 - if (serverCalendar.readCalendarEvents(facade)) { 1.210 - this.synchroniseEvents(androidCalendar, serverCalendar, syncResult.stats, notifyList); 1.211 + CaldavFacade facade = new CaldavFacade(Username, mAccountManager.getPassword(account), url, trust); 1.212 + facade.setAccount(account); 1.213 + facade.setProvider(provider); 1.214 + facade.setVersion(mVersion); 1.215 + serverCalList = facade.getCalendarList(this.getContext()); 1.216 + //String davProperties = facade.getLastDav(); 1.217 + Log.i(TAG, String.valueOf(androidCalList.getCalendarList() 1.218 + .size()) + " calendars found at android"); 1.219 1.220 - Log.d(TAG, "Updating stored CTag"); 1.221 - //serverCalendar.updateAndroidCalendar(androidCalendarUri, Calendar.CTAG, serverCalendar.getcTag()); 1.222 - androidCalendar.setCTag(serverCalendar.getcTag(), true); 1.223 - } else { 1.224 - Log.d(TAG, "unable to read events from server calendar"); 1.225 - } 1.226 - } else { 1.227 - Log.d(TAG, "CTag has not changed, nothing to do"); 1.228 + for (DavCalendar serverCalendar : serverCalList.getCalendarList()) { 1.229 + Log.i(TAG, "Detected calendar name=" + serverCalendar.getCalendarDisplayName() + " URI=" + serverCalendar 1.230 + .getURI()); 1.231 + 1.232 + Uri androidCalendarUri = serverCalendar.checkAndroidCalendarList(androidCalList, this 1.233 + .getContext()); 1.234 + 1.235 + // check if the adapter was able to get an existing calendar or create a new one 1.236 + if (androidCalendarUri != null) { 1.237 + // the provider seems to work correct, reset the counter 1.238 + mCountProviderFailed = 0; 1.239 + DavCalendar androidCalendar = androidCalList.getCalendarByAndroidUri(androidCalendarUri); 1.240 + 1.241 + //if ((FORCE_SYNCHRONIZE) || (androidCalendar.getcTag() == null) || (!androidCalendar.getcTag().equals(serverCalendar.getcTag()))) { 1.242 + if ((androidCalendar.getcTag() == null) || (!androidCalendar.getcTag() 1.243 + .equals(serverCalendar.getcTag()))) { 1.244 + Log.d(TAG, "CTag has changed, something to synchronise"); 1.245 + if (serverCalendar.readCalendarEvents(facade)) { 1.246 + this.synchroniseEvents(androidCalendar, serverCalendar, syncResult.stats, notifyList); 1.247 + 1.248 + Log.d(TAG, "Updating stored CTag"); 1.249 + //serverCalendar.updateAndroidCalendar(androidCalendarUri, Calendar.CTAG, serverCalendar.getcTag()); 1.250 + androidCalendar.setCTag(serverCalendar.getcTag(), true); 1.251 + } else { 1.252 + Log.d(TAG, "unable to read events from server calendar"); 1.253 + } 1.254 + } else { 1.255 + Log.d(TAG, "CTag has not changed, nothing to do"); 1.256 1.257 /* this is unnecessary. "SkippedEntries" are: 1.258 * Counter for tracking how many entries, either from the server or the local store, 1.259 @@ -196,52 +204,53 @@ 1.260 int count = countCursor.getInt(0); 1.261 syncResult.stats.numSkippedEntries += count; 1.262 countCursor.close();*/ 1.263 - 1.264 - } 1.265 - 1.266 - this.checkDirtyAndroidEvents(provider, account, androidCalendarUri, facade, serverCalendar.getURI(), syncResult.stats, notifyList); 1.267 - } else { 1.268 - // this happens if the data provider failes to get an existing or create a new calendar 1.269 - mCountProviderFailed += 1; 1.270 - Log.e(TAG, "failed to get an existing or create a new calendar"); 1.271 - syncResult.stats.numIoExceptions += 1; 1.272 - if (mCountProviderFailed >= mCountProviderFailedMax) { 1.273 - // see issue #96 1.274 - NotificationsHelper.signalSyncErrors(this.getContext(), "Caldav sync error (provider failed)", "are you using CyanogenMod in Incognito Mode?"); 1.275 - } else { 1.276 - NotificationsHelper.signalSyncErrors(this.getContext(), "Caldav sync error (provider failed)", "the provider failed to get an existing or create a new calendar"); 1.277 - } 1.278 - bolError = true; 1.279 - } 1.280 - } 1.281 - 1.282 - if (!bolError) { 1.283 - // check whether a calendar is not synced -> delete it at android 1.284 - androidCalList.deleteCalendarOnClientSideOnly(this.getContext()); 1.285 - } 1.286 - 1.287 - // notify the ContentResolver 1.288 - for (Uri uri : androidCalList.getNotifyList()) { 1.289 - this.getContext().getContentResolver().notifyChange(uri, null); 1.290 - } 1.291 - for (Uri uri : serverCalList.getNotifyList()) { 1.292 - this.getContext().getContentResolver().notifyChange(uri, null); 1.293 - } 1.294 - for (Uri uri : notifyList) { 1.295 - this.getContext().getContentResolver().notifyChange(uri, null); 1.296 - } 1.297 - 1.298 - //Log.i(TAG,"Statistiks for Calendar: " + serverCalendar.getURI().toString()); 1.299 - //Log.i(TAG,"Statistiks for AndroidCalendar: " + androidCalendar.getAndroidCalendarUri().toString()); 1.300 - Log.i(TAG,"Entries: " + String.valueOf(syncResult.stats.numEntries)); 1.301 - Log.i(TAG,"Rows inserted: " + String.valueOf(syncResult.stats.numInserts)); 1.302 - Log.i(TAG,"Rows updated: " + String.valueOf(syncResult.stats.numUpdates)); 1.303 - Log.i(TAG,"Rows deleted: " + String.valueOf(syncResult.stats.numDeletes)); 1.304 - Log.i(TAG,"Rows skipped: " + String.valueOf(syncResult.stats.numSkippedEntries)); 1.305 - Log.i(TAG,"Io Exceptions: " + String.valueOf(syncResult.stats.numIoExceptions)); 1.306 - Log.i(TAG,"Parse Exceptions: " + String.valueOf(syncResult.stats.numParseExceptions)); 1.307 - Log.i(TAG,"Auth Exceptions: " + String.valueOf(syncResult.stats.numAuthExceptions)); 1.308 - Log.i(TAG,"Conflict Detected Exceptions: " + String.valueOf(syncResult.stats.numConflictDetectedExceptions)); 1.309 + 1.310 + } 1.311 + 1.312 + this.checkDirtyAndroidEvents(provider, account, androidCalendarUri, facade, serverCalendar 1.313 + .getURI(), syncResult.stats, notifyList); 1.314 + } else { 1.315 + // this happens if the data provider failes to get an existing or create a new calendar 1.316 + mCountProviderFailed += 1; 1.317 + Log.e(TAG, "failed to get an existing or create a new calendar"); 1.318 + syncResult.stats.numIoExceptions += 1; 1.319 + if (mCountProviderFailed >= mCountProviderFailedMax) { 1.320 + // see issue #96 1.321 + NotificationsHelper.signalSyncErrors(this.getContext(), "Caldav sync error (provider failed)", "are you using CyanogenMod in Incognito Mode?"); 1.322 + } else { 1.323 + NotificationsHelper.signalSyncErrors(this.getContext(), "Caldav sync error (provider failed)", "the provider failed to get an existing or create a new calendar"); 1.324 + } 1.325 + bolError = true; 1.326 + } 1.327 + } 1.328 + 1.329 + if (!bolError) { 1.330 + // check whether a calendar is not synced -> delete it at android 1.331 + androidCalList.deleteCalendarOnClientSideOnly(this.getContext()); 1.332 + } 1.333 + 1.334 + // notify the ContentResolver 1.335 + for (Uri uri : androidCalList.getNotifyList()) { 1.336 + this.getContext().getContentResolver().notifyChange(uri, null); 1.337 + } 1.338 + for (Uri uri : serverCalList.getNotifyList()) { 1.339 + this.getContext().getContentResolver().notifyChange(uri, null); 1.340 + } 1.341 + for (Uri uri : notifyList) { 1.342 + this.getContext().getContentResolver().notifyChange(uri, null); 1.343 + } 1.344 + 1.345 + //Log.i(TAG,"Statistiks for Calendar: " + serverCalendar.getURI().toString()); 1.346 + //Log.i(TAG,"Statistiks for AndroidCalendar: " + androidCalendar.getAndroidCalendarUri().toString()); 1.347 + Log.i(TAG, "Entries: " + String.valueOf(syncResult.stats.numEntries)); 1.348 + Log.i(TAG, "Rows inserted: " + String.valueOf(syncResult.stats.numInserts)); 1.349 + Log.i(TAG, "Rows updated: " + String.valueOf(syncResult.stats.numUpdates)); 1.350 + Log.i(TAG, "Rows deleted: " + String.valueOf(syncResult.stats.numDeletes)); 1.351 + Log.i(TAG, "Rows skipped: " + String.valueOf(syncResult.stats.numSkippedEntries)); 1.352 + Log.i(TAG, "Io Exceptions: " + String.valueOf(syncResult.stats.numIoExceptions)); 1.353 + Log.i(TAG, "Parse Exceptions: " + String.valueOf(syncResult.stats.numParseExceptions)); 1.354 + Log.i(TAG, "Auth Exceptions: " + String.valueOf(syncResult.stats.numAuthExceptions)); 1.355 + Log.i(TAG, "Conflict Detected Exceptions: " + String.valueOf(syncResult.stats.numConflictDetectedExceptions)); 1.356 1.357 /*} catch (final AuthenticatorException e) { 1.358 syncResult.stats.numParseExceptions++; 1.359 @@ -260,119 +269,125 @@ 1.360 } catch (final ParseException e) { 1.361 syncResult.stats.numParseExceptions++; 1.362 Log.e(TAG, "ParseException", e); 1.363 - NotificationsHelper.signalSyncErrors(this.getContext(), "Caldav sync error (parsing)", e.getMessage()); 1.364 + NotificationsHelper.signalSyncErrors(this.getContext(), "Caldav sync error (parsing)", e 1.365 + .getMessage()); 1.366 //NotificationsHelper.getCurrentSyncLog().addException(e); 1.367 /*} catch (final JSONException e) { 1.368 syncResult.stats.numParseExceptions++; 1.369 Log.e(TAG, "JSONException", e);*/ 1.370 - } catch (Exception e) { 1.371 - Log.e(TAG, "Updating calendar exception " + e.getClass().getName(), e); 1.372 + } catch (Exception e) { 1.373 + Log.e(TAG, "Updating calendar exception " + e.getClass().getName(), e); 1.374 syncResult.stats.numParseExceptions++; 1.375 - NotificationsHelper.signalSyncErrors(this.getContext(), "Caldav sync error (general)", e.getMessage()); 1.376 + NotificationsHelper.signalSyncErrors(this.getContext(), "Caldav sync error (general)", e 1.377 + .getMessage()); 1.378 //NotificationsHelper.getCurrentSyncLog().addException(e); 1.379 - //throw new RuntimeException(e); 1.380 - } 1.381 - } 1.382 + //throw new RuntimeException(e); 1.383 + } 1.384 + } 1.385 1.386 - public void onSyncCanceled () { 1.387 - //TODO: implement SyncCanceled 1.388 - this.mCountSyncCanceled += 1; 1.389 - Log.v(TAG, "onSyncCanceled() count:" + String.valueOf(this.mCountSyncCanceled)); 1.390 - } 1.391 + public void onSyncCanceled() { 1.392 + //TODO: implement SyncCanceled 1.393 + this.mCountSyncCanceled += 1; 1.394 + Log.v(TAG, "onSyncCanceled() count:" + String.valueOf(this.mCountSyncCanceled)); 1.395 + } 1.396 1.397 - 1.398 - /** 1.399 - * both calender event and android event have been found. 1.400 - * server wins always at the moment. 1.401 - * @param androidCalendar 1.402 - * @param serverCalendar 1.403 - * @param stats 1.404 - * @param notifyList 1.405 - * @throws ClientProtocolException 1.406 - * @throws URISyntaxException 1.407 - * @throws IOException 1.408 - * @throws ParserConfigurationException 1.409 - * @throws SAXException 1.410 - * @throws RemoteException 1.411 - * @throws CaldavProtocolException 1.412 - * @throws ParserException 1.413 - * @see SyncAdapter#updateAndroidEvent(ContentProviderClient, Account, AndroidEvent, CalendarEvent) 1.414 - * @see SyncAdapter#tagAndroidEvent(ContentProviderClient, Account, AndroidEvent) 1.415 - * @see SyncAdapter#untagAndroidEvents(ContentProviderClient, Account, Uri) 1.416 - * @see SyncAdapter#deleteUntaggedEvents(ContentProviderClient, Account, Uri) 1.417 - */ 1.418 - private void synchroniseEvents( 1.419 - DavCalendar androidCalendar, 1.420 - DavCalendar serverCalendar, 1.421 - SyncStats stats, 1.422 - ArrayList<Uri> notifyList 1.423 - ) throws ClientProtocolException, URISyntaxException, IOException, ParserConfigurationException, SAXException, RemoteException, CaldavProtocolException, ParserException { 1.424 + 1.425 + /** 1.426 + * both calender event and android event have been found. 1.427 + * server wins always at the moment. 1.428 + * 1.429 + * @param androidCalendar 1.430 + * @param serverCalendar 1.431 + * @param stats 1.432 + * @param notifyList 1.433 + * @throws ClientProtocolException 1.434 + * @throws URISyntaxException 1.435 + * @throws IOException 1.436 + * @throws ParserConfigurationException 1.437 + * @throws SAXException 1.438 + * @throws RemoteException 1.439 + * @throws CaldavProtocolException 1.440 + * @throws ParserException 1.441 + * @see SyncAdapter#updateAndroidEvent(ContentProviderClient, Account, AndroidEvent, CalendarEvent) 1.442 + * @see SyncAdapter#tagAndroidEvent(ContentProviderClient, Account, AndroidEvent) 1.443 + * @see SyncAdapter#untagAndroidEvents(ContentProviderClient, Account, Uri) 1.444 + * @see SyncAdapter#deleteUntaggedEvents(ContentProviderClient, Account, Uri) 1.445 + */ 1.446 + private void synchroniseEvents( 1.447 + DavCalendar androidCalendar, 1.448 + DavCalendar serverCalendar, 1.449 + SyncStats stats, 1.450 + ArrayList<Uri> notifyList 1.451 + ) throws ClientProtocolException, URISyntaxException, IOException, ParserConfigurationException, SAXException, RemoteException, CaldavProtocolException, ParserException { 1.452 1.453 /*if (DROP_CALENDAR_EVENTS) { 1.454 dropAllEvents(account, provider, androidCalendar.getAndroidCalendarUri()); 1.455 }*/ 1.456 - 1.457 - int rowInsert = 0; 1.458 - int rowUpdate = 0; 1.459 - int rowTag = 0; 1.460 - int rowDelete = 0; 1.461 - int rowUntag = 0; 1.462 - int rowSkip = 0; 1.463 - 1.464 - for (CalendarEvent calendarEvent : serverCalendar.getCalendarEvents()) { 1.465 - try { 1.466 - AndroidEvent androidEvent = calendarEvent.getAndroidEvent(androidCalendar); 1.467 - 1.468 - Log.i(TAG, "Event " + calendarEvent.getUri().toString()+ " androidUri="+androidEvent); 1.469 - 1.470 - if (androidEvent == null) { 1.471 + 1.472 + int rowInsert = 0; 1.473 + int rowUpdate = 0; 1.474 + int rowTag = 0; 1.475 + int rowDelete = 0; 1.476 + int rowUntag = 0; 1.477 + int rowSkip = 0; 1.478 + 1.479 + for (CalendarEvent calendarEvent : serverCalendar.getCalendarEvents()) { 1.480 + try { 1.481 + AndroidEvent androidEvent = calendarEvent.getAndroidEvent(androidCalendar); 1.482 + 1.483 + Log.i(TAG, "Event " + calendarEvent.getUri() 1.484 + .toString() + " androidUri=" + androidEvent); 1.485 + 1.486 + if (androidEvent == null) { 1.487 /* new android event */ 1.488 - if (calendarEvent.createAndroidEvent(androidCalendar)) { 1.489 - rowInsert += 1; 1.490 - androidEvent = calendarEvent.getAndroidEvent(androidCalendar); 1.491 - notifyList.add(androidEvent.getUri()); 1.492 - } else { 1.493 - rowSkip += 1; 1.494 - } 1.495 - } else { 1.496 + if (calendarEvent.createAndroidEvent(androidCalendar)) { 1.497 + rowInsert += 1; 1.498 + androidEvent = calendarEvent.getAndroidEvent(androidCalendar); 1.499 + notifyList.add(androidEvent.getUri()); 1.500 + } else { 1.501 + rowSkip += 1; 1.502 + } 1.503 + } else { 1.504 /* the android exists */ 1.505 - String androidETag = androidEvent.getETag(); 1.506 - if (androidETag == null) 1.507 - androidETag = ""; 1.508 - Log.d(TAG, "Event compare: " + androidETag + " <> " + calendarEvent.getETag().toString()); 1.509 - if ((androidEvent.getETag() == null) || (!androidETag.equals(calendarEvent.getETag()))) { 1.510 + String androidETag = androidEvent.getETag(); 1.511 + if (androidETag == null) 1.512 + androidETag = ""; 1.513 + Log.d(TAG, "Event compare: " + androidETag + " <> " + calendarEvent.getETag() 1.514 + .toString()); 1.515 + if ((androidEvent.getETag() == null) || (!androidETag.equals(calendarEvent.getETag()))) { 1.516 /* the android event is getting updated */ 1.517 - if (calendarEvent.updateAndroidEvent(androidEvent)) { 1.518 - rowUpdate += 1; 1.519 - notifyList.add(androidEvent.getUri()); 1.520 - } else { 1.521 - rowSkip += 1; 1.522 - } 1.523 - } 1.524 - } 1.525 - if (androidEvent != null) 1.526 - //if (androidEvent.tagAndroidEvent()) 1.527 - if (androidCalendar.tagAndroidEvent(androidEvent)) 1.528 - rowTag += 1; 1.529 - 1.530 - 1.531 - } catch (ParserException ex) { 1.532 - Log.e(TAG, "Parser exception", ex); 1.533 - stats.numParseExceptions++; 1.534 + if (calendarEvent.updateAndroidEvent(androidEvent)) { 1.535 + rowUpdate += 1; 1.536 + notifyList.add(androidEvent.getUri()); 1.537 + } else { 1.538 + rowSkip += 1; 1.539 + } 1.540 + } 1.541 + } 1.542 + if (androidEvent != null) 1.543 + //if (androidEvent.tagAndroidEvent()) 1.544 + if (androidCalendar.tagAndroidEvent(androidEvent)) 1.545 + rowTag += 1; 1.546 1.547 - NotificationsHelper.signalSyncErrors(getContext(), "Caldav sync error (parsing)", ex.getMessage()); 1.548 - //NotificationsHelper.getCurrentSyncLog().addException(ex); 1.549 - } catch (CaldavProtocolException ex) { 1.550 - Log.e(TAG, "Caldav exception", ex); 1.551 - stats.numParseExceptions++; 1.552 1.553 - NotificationsHelper.signalSyncErrors(getContext(), "Caldav sync error (caldav)", ex.getMessage()); 1.554 - //NotificationsHelper.getCurrentSyncLog().addException(ex); 1.555 - } 1.556 - } 1.557 - 1.558 - rowDelete = androidCalendar.deleteUntaggedEvents(); 1.559 - rowUntag = androidCalendar.untagAndroidEvents(); 1.560 + } catch (ParserException ex) { 1.561 + Log.e(TAG, "Parser exception", ex); 1.562 + stats.numParseExceptions++; 1.563 + 1.564 + NotificationsHelper.signalSyncErrors(getContext(), "Caldav sync error (parsing)", ex 1.565 + .getMessage()); 1.566 + //NotificationsHelper.getCurrentSyncLog().addException(ex); 1.567 + } catch (CaldavProtocolException ex) { 1.568 + Log.e(TAG, "Caldav exception", ex); 1.569 + stats.numParseExceptions++; 1.570 + 1.571 + NotificationsHelper.signalSyncErrors(getContext(), "Caldav sync error (caldav)", ex.getMessage()); 1.572 + //NotificationsHelper.getCurrentSyncLog().addException(ex); 1.573 + } 1.574 + } 1.575 + 1.576 + rowDelete = androidCalendar.deleteUntaggedEvents(); 1.577 + rowUntag = androidCalendar.untagAndroidEvents(); 1.578 1.579 /*Log.i(TAG,"Statistiks for Calendar: " + serverCalendar.getURI().toString()); 1.580 Log.i(TAG,"Statistiks for AndroidCalendar: " + androidCalendar.getAndroidCalendarUri().toString()); 1.581 @@ -380,188 +395,192 @@ 1.582 Log.i(TAG,"Rows updated: " + String.valueOf(rowUpdate)); 1.583 Log.i(TAG,"Rows deleted: " + String.valueOf(rowDelete)); 1.584 Log.i(TAG,"Rows skipped: " + String.valueOf(rowSkip));*/ 1.585 - Log.i(TAG,"Rows tagged: " + String.valueOf(rowTag)); 1.586 - Log.i(TAG,"Rows untagged: " + String.valueOf(rowUntag)); 1.587 - 1.588 - stats.numInserts += rowInsert; 1.589 - stats.numUpdates += rowUpdate; 1.590 - stats.numDeletes += rowDelete; 1.591 - stats.numSkippedEntries += rowSkip; 1.592 - stats.numEntries += rowInsert + rowUpdate + rowDelete; 1.593 + Log.i(TAG, "Rows tagged: " + String.valueOf(rowTag)); 1.594 + Log.i(TAG, "Rows untagged: " + String.valueOf(rowUntag)); 1.595 1.596 - } 1.597 - 1.598 - /** 1.599 - * checks the android events for the dirty flag. 1.600 - * the flag is set by android when the event has been changed. 1.601 - * the dirty flag is removed when an android event has been updated from calendar event 1.602 - * @param provider 1.603 - * @param account 1.604 - * @param calendarUri 1.605 - * @param facade 1.606 - * @param caldavCalendarUri 1.607 - * @param stats 1.608 - * @param notifyList 1.609 - * @return count of dirty events 1.610 - */ 1.611 - private int checkDirtyAndroidEvents( 1.612 - ContentProviderClient provider, 1.613 - Account account, 1.614 - Uri calendarUri, 1.615 - CaldavFacade facade, 1.616 - URI caldavCalendarUri, 1.617 - SyncStats stats, 1.618 - ArrayList<Uri> notifyList 1.619 - ) { 1.620 - Cursor curEvent = null; 1.621 - Cursor curAttendee = null; 1.622 - Cursor curReminder = null; 1.623 - Long EventID; 1.624 - Long CalendarID; 1.625 - AndroidEvent androidEvent = null; 1.626 - int rowDirty = 0; 1.627 - int rowInsert = 0; 1.628 - int rowUpdate = 0; 1.629 - int rowDelete = 0; 1.630 - 1.631 - try { 1.632 - CalendarID = ContentUris.parseId(calendarUri); 1.633 - String selection = "(" + Events.DIRTY + " = ?) AND (" + Events.CALENDAR_ID + " = ?)"; 1.634 - String[] selectionArgs = new String[] {"1", CalendarID.toString()}; 1.635 - curEvent = provider.query(Events.CONTENT_URI, null, selection, selectionArgs, null); 1.636 - 1.637 - while (curEvent.moveToNext()) { 1.638 - EventID = curEvent.getLong(curEvent.getColumnIndex(Events._ID)); 1.639 - Uri returnedUri = ContentUris.withAppendedId(Events.CONTENT_URI, EventID); 1.640 - 1.641 - //androidEvent = new AndroidEvent(account, provider, returnedUri, calendarUri); 1.642 - androidEvent = new AndroidEvent(returnedUri, calendarUri); 1.643 - androidEvent.readContentValues(curEvent); 1.644 - 1.645 - selection = "(" + Attendees.EVENT_ID + " = ?)"; 1.646 - selectionArgs = new String[] {String.valueOf(EventID)}; 1.647 - curAttendee = provider.query(Attendees.CONTENT_URI, null, selection, selectionArgs, null); 1.648 - selection = "(" + Reminders.EVENT_ID + " = ?)"; 1.649 - selectionArgs = new String[] {String.valueOf(EventID)}; 1.650 - curReminder = provider.query(Reminders.CONTENT_URI, null, selection, selectionArgs, null); 1.651 - androidEvent.readAttendees(curAttendee); 1.652 - androidEvent.readReminder(curReminder); 1.653 - curAttendee.close(); 1.654 - curReminder.close(); 1.655 - 1.656 - String SyncID = androidEvent.ContentValues.getAsString(Events._SYNC_ID); 1.657 - 1.658 - boolean Deleted = false; 1.659 - int intDeleted = 0; 1.660 - intDeleted = curEvent.getInt(curEvent.getColumnIndex(Events.DELETED)); 1.661 - Deleted = (intDeleted == 1); 1.662 + stats.numInserts += rowInsert; 1.663 + stats.numUpdates += rowUpdate; 1.664 + stats.numDeletes += rowDelete; 1.665 + stats.numSkippedEntries += rowSkip; 1.666 + stats.numEntries += rowInsert + rowUpdate + rowDelete; 1.667 1.668 - if (SyncID == null) { 1.669 - // new Android event 1.670 - String newGUID = java.util.UUID.randomUUID().toString() + "-caldavsyncadapter"; 1.671 - String calendarPath = caldavCalendarUri.getPath(); 1.672 - if (!calendarPath.endsWith("/")) 1.673 - calendarPath += "/"; 1.674 + } 1.675 1.676 - SyncID = calendarPath + newGUID + ".ics"; 1.677 - 1.678 - androidEvent.createIcs(newGUID); 1.679 - 1.680 - if (facade.createEvent(URI.create(SyncID), androidEvent.getIcsEvent().toString())) { 1.681 - //HINT: bugfix for google calendar replace("@", "%40") 1.682 - if (SyncID.contains("@")) 1.683 - SyncID = SyncID.replace("@", "%40"); 1.684 - ContentValues values = new ContentValues(); 1.685 - values.put(Events._SYNC_ID, SyncID); 1.686 + /** 1.687 + * checks the android events for the dirty flag. 1.688 + * the flag is set by android when the event has been changed. 1.689 + * the dirty flag is removed when an android event has been updated from calendar event 1.690 + * 1.691 + * @param provider 1.692 + * @param account 1.693 + * @param calendarUri 1.694 + * @param facade 1.695 + * @param caldavCalendarUri 1.696 + * @param stats 1.697 + * @param notifyList 1.698 + * @return count of dirty events 1.699 + */ 1.700 + private int checkDirtyAndroidEvents( 1.701 + ContentProviderClient provider, 1.702 + Account account, 1.703 + Uri calendarUri, 1.704 + CaldavFacade facade, 1.705 + URI caldavCalendarUri, 1.706 + SyncStats stats, 1.707 + ArrayList<Uri> notifyList 1.708 + ) { 1.709 + Cursor curEvent = null; 1.710 + Cursor curAttendee = null; 1.711 + Cursor curReminder = null; 1.712 + Long EventID; 1.713 + Long CalendarID; 1.714 + AndroidEvent androidEvent = null; 1.715 + int rowDirty = 0; 1.716 + int rowInsert = 0; 1.717 + int rowUpdate = 0; 1.718 + int rowDelete = 0; 1.719 1.720 - //google doesn't send the etag after creation 1.721 - //HINT: my SabreDAV send always the same etag after putting a new event 1.722 - //String LastETag = facade.getLastETag(); 1.723 - //if (!LastETag.equals("")) { 1.724 - // values.put(Event.ETAG, LastETag); 1.725 - //} else { 1.726 - //so get the etag with a new REPORT 1.727 - CalendarEvent calendarEvent = new CalendarEvent(account, provider); 1.728 - calendarEvent.calendarURL = caldavCalendarUri.toURL(); 1.729 - URI SyncURI = new URI(SyncID); 1.730 - calendarEvent.setUri(SyncURI); 1.731 - CaldavFacade.getEvent(calendarEvent); 1.732 - values.put(Event.ETAG, calendarEvent.getETag()); 1.733 - //} 1.734 - values.put(Event.UID, newGUID); 1.735 - values.put(Events.DIRTY, 0); 1.736 - values.put(Event.RAWDATA, androidEvent.getIcsEvent().toString()); 1.737 - 1.738 - int rowCount = provider.update(asSyncAdapter(androidEvent.getUri(), account.name, account.type), values, null, null); 1.739 - if (rowCount == 1) { 1.740 - rowInsert += 1; 1.741 - notifyList.add(androidEvent.getUri()); 1.742 - } 1.743 - } 1.744 - } else if (Deleted) { 1.745 - // deleted Android event 1.746 - if (facade.deleteEvent(URI.create(SyncID), androidEvent.getETag())) { 1.747 - String mSelectionClause = "(" + Events._ID + "= ?)"; 1.748 - String[] mSelectionArgs = {String.valueOf(EventID)}; 1.749 - 1.750 - int countDeleted = provider.delete(asSyncAdapter(Events.CONTENT_URI, account.name, account.type), mSelectionClause, mSelectionArgs); 1.751 - 1.752 - if (countDeleted == 1) { 1.753 - rowDelete += 1; 1.754 - notifyList.add(androidEvent.getUri()); 1.755 - } 1.756 - } 1.757 - } else { 1.758 - //update the android event to the server 1.759 - String uid = androidEvent.getUID(); 1.760 - if ((uid == null) || (uid.equals(""))) { 1.761 - //COMPAT: this is needed because in the past, the UID was not stored in the android event 1.762 - CalendarEvent calendarEvent = new CalendarEvent(account, provider); 1.763 - URI syncURI = new URI(SyncID); 1.764 - calendarEvent.setUri(syncURI); 1.765 - calendarEvent.calendarURL = caldavCalendarUri.toURL(); 1.766 - if (calendarEvent.fetchBody()) { 1.767 - calendarEvent.readContentValues(); 1.768 - uid = calendarEvent.getUID(); 1.769 - } 1.770 - } 1.771 - if (uid != null) { 1.772 - androidEvent.createIcs(uid); 1.773 - 1.774 - if (facade.updateEvent(URI.create(SyncID), androidEvent.getIcsEvent().toString(), androidEvent.getETag())) { 1.775 - selection = "(" + Events._ID + "= ?)"; 1.776 - selectionArgs = new String[] {EventID.toString()}; 1.777 - androidEvent.ContentValues.put(Events.DIRTY, 0); 1.778 + try { 1.779 + CalendarID = ContentUris.parseId(calendarUri); 1.780 + String selection = "(" + Events.DIRTY + " = ?) AND (" + Events.CALENDAR_ID + " = ?)"; 1.781 + String[] selectionArgs = new String[]{"1", CalendarID.toString()}; 1.782 + curEvent = provider.query(Events.CONTENT_URI, null, selection, selectionArgs, null); 1.783 1.784 - //google doesn't send the etag after update 1.785 - String LastETag = facade.getLastETag(); 1.786 - if (!LastETag.equals("")) { 1.787 - androidEvent.ContentValues.put(Event.ETAG, LastETag); 1.788 - } else { 1.789 - //so get the etag with a new REPORT 1.790 - CalendarEvent calendarEvent = new CalendarEvent(account, provider); 1.791 - calendarEvent.calendarURL = caldavCalendarUri.toURL(); 1.792 - URI SyncURI = new URI(SyncID); 1.793 - calendarEvent.setUri(SyncURI); 1.794 - CaldavFacade.getEvent(calendarEvent); 1.795 - androidEvent.ContentValues.put(Event.ETAG, calendarEvent.getETag()); 1.796 - } 1.797 - androidEvent.ContentValues.put(Event.RAWDATA, androidEvent.getIcsEvent().toString()); 1.798 - int RowCount = provider.update(asSyncAdapter(androidEvent.getUri(), account.name, account.type), androidEvent.ContentValues, null, null); 1.799 - 1.800 - if (RowCount == 1) { 1.801 - rowUpdate += 1; 1.802 - notifyList.add(androidEvent.getUri()); 1.803 - } 1.804 - } else { 1.805 - rowDirty += 1; 1.806 - } 1.807 - } else { 1.808 - rowDirty += 1; 1.809 - } 1.810 - } 1.811 - } 1.812 - curEvent.close(); 1.813 + while (curEvent.moveToNext()) { 1.814 + EventID = curEvent.getLong(curEvent.getColumnIndex(Events._ID)); 1.815 + Uri returnedUri = ContentUris.withAppendedId(Events.CONTENT_URI, EventID); 1.816 + 1.817 + //androidEvent = new AndroidEvent(account, provider, returnedUri, calendarUri); 1.818 + androidEvent = new AndroidEvent(returnedUri, calendarUri); 1.819 + androidEvent.readContentValues(curEvent); 1.820 + 1.821 + selection = "(" + Attendees.EVENT_ID + " = ?)"; 1.822 + selectionArgs = new String[]{String.valueOf(EventID)}; 1.823 + curAttendee = provider.query(Attendees.CONTENT_URI, null, selection, selectionArgs, null); 1.824 + selection = "(" + Reminders.EVENT_ID + " = ?)"; 1.825 + selectionArgs = new String[]{String.valueOf(EventID)}; 1.826 + curReminder = provider.query(Reminders.CONTENT_URI, null, selection, selectionArgs, null); 1.827 + androidEvent.readAttendees(curAttendee); 1.828 + androidEvent.readReminder(curReminder); 1.829 + curAttendee.close(); 1.830 + curReminder.close(); 1.831 + 1.832 + String SyncID = androidEvent.ContentValues.getAsString(Events._SYNC_ID); 1.833 + 1.834 + boolean Deleted = false; 1.835 + int intDeleted = 0; 1.836 + intDeleted = curEvent.getInt(curEvent.getColumnIndex(Events.DELETED)); 1.837 + Deleted = (intDeleted == 1); 1.838 + 1.839 + if (SyncID == null) { 1.840 + // new Android event 1.841 + String newGUID = java.util.UUID.randomUUID().toString() + "-caldavsyncadapter"; 1.842 + String calendarPath = caldavCalendarUri.getPath(); 1.843 + if (!calendarPath.endsWith("/")) 1.844 + calendarPath += "/"; 1.845 + 1.846 + SyncID = calendarPath + newGUID + ".ics"; 1.847 + 1.848 + androidEvent.createIcs(newGUID); 1.849 + 1.850 + if (facade.createEvent(URI.create(SyncID), androidEvent.getIcsEvent() 1.851 + .toString())) { 1.852 + //HINT: bugfix for google calendar replace("@", "%40") 1.853 + if (SyncID.contains("@")) 1.854 + SyncID = SyncID.replace("@", "%40"); 1.855 + ContentValues values = new ContentValues(); 1.856 + values.put(Events._SYNC_ID, SyncID); 1.857 + 1.858 + //google doesn't send the etag after creation 1.859 + //HINT: my SabreDAV send always the same etag after putting a new event 1.860 + //String LastETag = facade.getLastETag(); 1.861 + //if (!LastETag.equals("")) { 1.862 + // values.put(Event.ETAG, LastETag); 1.863 + //} else { 1.864 + //so get the etag with a new REPORT 1.865 + CalendarEvent calendarEvent = new CalendarEvent(account, provider); 1.866 + calendarEvent.calendarURL = caldavCalendarUri.toURL(); 1.867 + URI SyncURI = new URI(SyncID); 1.868 + calendarEvent.setUri(SyncURI); 1.869 + CaldavFacade.getEvent(calendarEvent); 1.870 + values.put(Event.ETAG, calendarEvent.getETag()); 1.871 + //} 1.872 + values.put(Event.UID, newGUID); 1.873 + values.put(Events.DIRTY, 0); 1.874 + values.put(Event.RAWDATA, androidEvent.getIcsEvent().toString()); 1.875 + 1.876 + int rowCount = provider.update(asSyncAdapter(androidEvent.getUri(), account.name, account.type), values, null, null); 1.877 + if (rowCount == 1) { 1.878 + rowInsert += 1; 1.879 + notifyList.add(androidEvent.getUri()); 1.880 + } 1.881 + } 1.882 + } else if (Deleted) { 1.883 + // deleted Android event 1.884 + if (facade.deleteEvent(URI.create(SyncID), androidEvent.getETag())) { 1.885 + String mSelectionClause = "(" + Events._ID + "= ?)"; 1.886 + String[] mSelectionArgs = {String.valueOf(EventID)}; 1.887 + 1.888 + int countDeleted = provider.delete(asSyncAdapter(Events.CONTENT_URI, account.name, account.type), mSelectionClause, mSelectionArgs); 1.889 + 1.890 + if (countDeleted == 1) { 1.891 + rowDelete += 1; 1.892 + notifyList.add(androidEvent.getUri()); 1.893 + } 1.894 + } 1.895 + } else { 1.896 + //update the android event to the server 1.897 + String uid = androidEvent.getUID(); 1.898 + if ((uid == null) || (uid.equals(""))) { 1.899 + //COMPAT: this is needed because in the past, the UID was not stored in the android event 1.900 + CalendarEvent calendarEvent = new CalendarEvent(account, provider); 1.901 + URI syncURI = new URI(SyncID); 1.902 + calendarEvent.setUri(syncURI); 1.903 + calendarEvent.calendarURL = caldavCalendarUri.toURL(); 1.904 + if (calendarEvent.fetchBody()) { 1.905 + calendarEvent.readContentValues(); 1.906 + uid = calendarEvent.getUID(); 1.907 + } 1.908 + } 1.909 + if (uid != null) { 1.910 + androidEvent.createIcs(uid); 1.911 + 1.912 + if (facade.updateEvent(URI.create(SyncID), androidEvent.getIcsEvent() 1.913 + .toString(), androidEvent.getETag())) { 1.914 + selection = "(" + Events._ID + "= ?)"; 1.915 + selectionArgs = new String[]{EventID.toString()}; 1.916 + androidEvent.ContentValues.put(Events.DIRTY, 0); 1.917 + 1.918 + //google doesn't send the etag after update 1.919 + String LastETag = facade.getLastETag(); 1.920 + if (!LastETag.equals("")) { 1.921 + androidEvent.ContentValues.put(Event.ETAG, LastETag); 1.922 + } else { 1.923 + //so get the etag with a new REPORT 1.924 + CalendarEvent calendarEvent = new CalendarEvent(account, provider); 1.925 + calendarEvent.calendarURL = caldavCalendarUri.toURL(); 1.926 + URI SyncURI = new URI(SyncID); 1.927 + calendarEvent.setUri(SyncURI); 1.928 + CaldavFacade.getEvent(calendarEvent); 1.929 + androidEvent.ContentValues.put(Event.ETAG, calendarEvent.getETag()); 1.930 + } 1.931 + androidEvent.ContentValues.put(Event.RAWDATA, androidEvent.getIcsEvent() 1.932 + .toString()); 1.933 + int RowCount = provider.update(asSyncAdapter(androidEvent.getUri(), account.name, account.type), androidEvent.ContentValues, null, null); 1.934 + 1.935 + if (RowCount == 1) { 1.936 + rowUpdate += 1; 1.937 + notifyList.add(androidEvent.getUri()); 1.938 + } 1.939 + } else { 1.940 + rowDirty += 1; 1.941 + } 1.942 + } else { 1.943 + rowDirty += 1; 1.944 + } 1.945 + } 1.946 + } 1.947 + curEvent.close(); 1.948 1.949 /*if ((rowInsert > 0) || (rowUpdate > 0) || (rowDelete > 0) || (rowDirty > 0)) { 1.950 Log.i(TAG,"Android Rows inserted: " + String.valueOf(rowInsert)); 1.951 @@ -569,33 +588,33 @@ 1.952 Log.i(TAG,"Android Rows deleted: " + String.valueOf(rowDelete)); 1.953 Log.i(TAG,"Android Rows dirty: " + String.valueOf(rowDirty)); 1.954 }*/ 1.955 - 1.956 - stats.numInserts += rowInsert; 1.957 - stats.numUpdates += rowUpdate; 1.958 - stats.numDeletes += rowDelete; 1.959 - stats.numSkippedEntries += rowDirty; 1.960 - stats.numEntries += rowInsert + rowUpdate + rowDelete; 1.961 - } catch (RemoteException e) { 1.962 - e.printStackTrace(); 1.963 - } catch (URISyntaxException e) { 1.964 - // TODO Automatisch generierter Erfassungsblock 1.965 - e.printStackTrace(); 1.966 - } catch (ClientProtocolException e) { 1.967 - // TODO Automatisch generierter Erfassungsblock 1.968 - e.printStackTrace(); 1.969 - } catch (IOException e) { 1.970 - // TODO Automatisch generierter Erfassungsblock 1.971 - e.printStackTrace(); 1.972 - } catch (CaldavProtocolException e) { 1.973 - // TODO Automatisch generierter Erfassungsblock 1.974 - e.printStackTrace(); 1.975 - } catch (ParserException e) { 1.976 - // TODO Automatisch generierter Erfassungsblock 1.977 - e.printStackTrace(); 1.978 - } 1.979 - 1.980 - return rowDirty; 1.981 - } 1.982 + 1.983 + stats.numInserts += rowInsert; 1.984 + stats.numUpdates += rowUpdate; 1.985 + stats.numDeletes += rowDelete; 1.986 + stats.numSkippedEntries += rowDirty; 1.987 + stats.numEntries += rowInsert + rowUpdate + rowDelete; 1.988 + } catch (RemoteException e) { 1.989 + e.printStackTrace(); 1.990 + } catch (URISyntaxException e) { 1.991 + // TODO Automatisch generierter Erfassungsblock 1.992 + e.printStackTrace(); 1.993 + } catch (ClientProtocolException e) { 1.994 + // TODO Automatisch generierter Erfassungsblock 1.995 + e.printStackTrace(); 1.996 + } catch (IOException e) { 1.997 + // TODO Automatisch generierter Erfassungsblock 1.998 + e.printStackTrace(); 1.999 + } catch (CaldavProtocolException e) { 1.1000 + // TODO Automatisch generierter Erfassungsblock 1.1001 + e.printStackTrace(); 1.1002 + } catch (ParserException e) { 1.1003 + // TODO Automatisch generierter Erfassungsblock 1.1004 + e.printStackTrace(); 1.1005 + } 1.1006 + 1.1007 + return rowDirty; 1.1008 + } 1.1009 1.1010 /* private Account UpgradeAccount(Account OldAccount) { 1.1011 String Username = OldAccount.name; 1.1012 @@ -624,13 +643,13 @@ 1.1013 selection, selectionArgs); 1.1014 1.1015 }*/ 1.1016 - 1.1017 - private static Uri asSyncAdapter(Uri uri, String account, String accountType) { 1.1018 - return uri.buildUpon() 1.1019 - .appendQueryParameter(android.provider.CalendarContract.CALLER_IS_SYNCADAPTER,"true") 1.1020 - .appendQueryParameter(Calendars.ACCOUNT_NAME, account) 1.1021 - .appendQueryParameter(Calendars.ACCOUNT_TYPE, accountType).build(); 1.1022 - } 1.1023 + 1.1024 + private static Uri asSyncAdapter(Uri uri, String account, String accountType) { 1.1025 + return uri.buildUpon() 1.1026 + .appendQueryParameter(android.provider.CalendarContract.CALLER_IS_SYNCADAPTER, "true") 1.1027 + .appendQueryParameter(Calendars.ACCOUNT_NAME, account) 1.1028 + .appendQueryParameter(Calendars.ACCOUNT_TYPE, accountType).build(); 1.1029 + } 1.1030 1.1031 } 1.1032