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 16:19:59 +00:00
|
|
|
|
import at.bitfire.davdroid.Constants;
|
|
|
|
|
import at.bitfire.davdroid.resource.LocalCalendar;
|
|
|
|
|
import at.bitfire.davdroid.resource.LocalContact;
|
|
|
|
|
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 {
|
|
|
|
|
for (LocalCalendar calendar : (LocalCalendar[])LocalCalendar.findAll(account, provider, LocalCalendar.Factory.INSTANCE)) {
|
|
|
|
|
Constants.log.info("Synchronizing calendar #" + calendar.getId() + ", URL: " + calendar.getName());
|
|
|
|
|
CalendarSyncManager syncManager = new CalendarSyncManager(getContext(), account, extras, provider, syncResult, calendar);
|
|
|
|
|
syncManager.performSync();
|
|
|
|
|
}
|
|
|
|
|
} catch (CalendarStorageException e) {
|
|
|
|
|
Constants.log.error("Couldn't get list of local calendars", e);
|
|
|
|
|
}
|
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
|
|
|
|
|
|
|
|
|
}
|