2015-03-08 22:30:03 +00:00
|
|
|
|
/*
|
2015-05-27 08:48:27 +00:00
|
|
|
|
* Copyright © 2013 – 2015 Ricki Hirner (bitfire web engineering).
|
2014-12-20 19:21:46 +00:00
|
|
|
|
* All rights reserved. This program and the accompanying materials
|
|
|
|
|
* are made available under the terms of the GNU Public License v3.0
|
|
|
|
|
* which accompanies this distribution, and is available at
|
|
|
|
|
* http://www.gnu.org/licenses/gpl.html
|
2015-03-08 22:30:03 +00:00
|
|
|
|
*/
|
2014-12-20 19:21:46 +00:00
|
|
|
|
package at.bitfire.davdroid.syncadapter;
|
|
|
|
|
|
|
|
|
|
import android.accounts.Account;
|
|
|
|
|
import android.app.Service;
|
2015-10-14 11:38:18 +00:00
|
|
|
|
import android.content.AbstractThreadedSyncAdapter;
|
2014-12-20 19:21:46 +00:00
|
|
|
|
import android.content.ContentProviderClient;
|
|
|
|
|
import android.content.Context;
|
|
|
|
|
import android.content.Intent;
|
2015-10-14 11:38:18 +00:00
|
|
|
|
import android.content.SyncResult;
|
|
|
|
|
import android.os.Bundle;
|
2014-12-20 19:21:46 +00:00
|
|
|
|
import android.os.IBinder;
|
2015-10-14 19:45:19 +00:00
|
|
|
|
import android.provider.CalendarContract;
|
2014-12-20 19:21:46 +00:00
|
|
|
|
|
2015-10-14 16:19:59 +00:00
|
|
|
|
import at.bitfire.davdroid.Constants;
|
|
|
|
|
import at.bitfire.davdroid.resource.LocalCalendar;
|
|
|
|
|
import at.bitfire.ical4android.CalendarStorageException;
|
|
|
|
|
|
2014-12-20 19:21:46 +00:00
|
|
|
|
public class CalendarsSyncAdapterService extends Service {
|
|
|
|
|
private static SyncAdapter syncAdapter;
|
2015-05-15 21:35:27 +00:00
|
|
|
|
|
2014-12-20 19:21:46 +00:00
|
|
|
|
@Override
|
|
|
|
|
public void onCreate() {
|
|
|
|
|
if (syncAdapter == null)
|
|
|
|
|
syncAdapter = new SyncAdapter(getApplicationContext());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void onDestroy() {
|
|
|
|
|
syncAdapter = null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public IBinder onBind(Intent intent) {
|
|
|
|
|
return syncAdapter.getSyncAdapterBinder();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2015-10-14 11:38:18 +00:00
|
|
|
|
private static class SyncAdapter extends AbstractThreadedSyncAdapter {
|
|
|
|
|
public SyncAdapter(Context context) {
|
|
|
|
|
super(context, false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void onPerformSync(Account account, Bundle extras, String authority, ContentProviderClient provider, SyncResult syncResult) {
|
2015-10-14 16:19:59 +00:00
|
|
|
|
Constants.log.info("Starting calendar sync (" + authority + ")");
|
|
|
|
|
|
|
|
|
|
try {
|
2015-10-14 19:45:19 +00:00
|
|
|
|
for (LocalCalendar calendar : (LocalCalendar[])LocalCalendar.find(account, provider, LocalCalendar.Factory.INSTANCE, CalendarContract.Calendars.SYNC_EVENTS + "!=0", null)) {
|
2015-10-14 16:19:59 +00:00
|
|
|
|
Constants.log.info("Synchronizing calendar #" + calendar.getId() + ", URL: " + calendar.getName());
|
2015-10-17 09:33:35 +00:00
|
|
|
|
CalendarSyncManager syncManager = new CalendarSyncManager(getContext(), account, extras, authority, syncResult, calendar);
|
2015-10-14 16:19:59 +00:00
|
|
|
|
syncManager.performSync();
|
|
|
|
|
}
|
|
|
|
|
} catch (CalendarStorageException e) {
|
2015-10-14 22:49:15 +00:00
|
|
|
|
Constants.log.error("Couldn't enumerate local calendars", e);
|
2015-10-14 16:19:59 +00:00
|
|
|
|
}
|
2015-10-14 11:38:18 +00:00
|
|
|
|
|
2015-10-14 16:19:59 +00:00
|
|
|
|
Constants.log.info("Calendar sync complete");
|
2015-10-14 11:38:18 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2014-12-20 19:21:46 +00:00
|
|
|
|
|
|
|
|
|
}
|