|
|
|
@ -1,5 +1,7 @@
|
|
|
|
package com.todoroo.astrid.sync;
|
|
|
|
package com.todoroo.astrid.sync;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import java.util.concurrent.atomic.AtomicBoolean;
|
|
|
|
|
|
|
|
|
|
|
|
import android.app.AlarmManager;
|
|
|
|
import android.app.AlarmManager;
|
|
|
|
import android.app.PendingIntent;
|
|
|
|
import android.app.PendingIntent;
|
|
|
|
import android.app.Service;
|
|
|
|
import android.app.Service;
|
|
|
|
@ -45,12 +47,15 @@ abstract public class SyncBackgroundService extends Service {
|
|
|
|
DependencyInjectionService.getInstance().inject(this);
|
|
|
|
DependencyInjectionService.getInstance().inject(this);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private final AtomicBoolean started = new AtomicBoolean(false);
|
|
|
|
|
|
|
|
|
|
|
|
/** Receive the alarm - start the synchronize service! */
|
|
|
|
/** Receive the alarm - start the synchronize service! */
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public void onStart(Intent intent, int startId) {
|
|
|
|
public void onStart(Intent intent, int startId) {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
if(intent != null)
|
|
|
|
if(intent != null && !started.getAndSet(true)) {
|
|
|
|
startSynchronization(this);
|
|
|
|
startSynchronization(this);
|
|
|
|
|
|
|
|
}
|
|
|
|
} catch (Exception e) {
|
|
|
|
} catch (Exception e) {
|
|
|
|
exceptionService.reportError(getSyncUtilities().getIdentifier() + "-bg-sync", e); //$NON-NLS-1$
|
|
|
|
exceptionService.reportError(getSyncUtilities().getIdentifier() + "-bg-sync", e); //$NON-NLS-1$
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@ -67,8 +72,6 @@ abstract public class SyncBackgroundService extends Service {
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
|
|
getSyncProvider().synchronize(context);
|
|
|
|
getSyncProvider().synchronize(context);
|
|
|
|
|
|
|
|
|
|
|
|
stopSelf();
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
@ -76,6 +79,11 @@ abstract public class SyncBackgroundService extends Service {
|
|
|
|
return null;
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public synchronized void stop() {
|
|
|
|
|
|
|
|
started.set(false);
|
|
|
|
|
|
|
|
stopSelf();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// --- alarm management
|
|
|
|
// --- alarm management
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
|