Remove StartupService

pull/795/head
Alex Baker 5 years ago
parent 54b5cd31c9
commit 2fbc356e84

@ -371,14 +371,6 @@
</intent-filter> </intent-filter>
</receiver> </receiver>
<service
android:exported="false"
android:name=".scheduling.GeofenceSchedulingIntentService"
android:permission="android.permission.BIND_JOB_SERVICE"/>
<service
android:exported="false"
android:name=".scheduling.BackgroundScheduler"
android:permission="android.permission.BIND_JOB_SERVICE"/>
<service <service
android:exported="false" android:exported="false"
android:name=".scheduling.NotificationSchedulerIntentService" android:name=".scheduling.NotificationSchedulerIntentService"

@ -1,52 +0,0 @@
/*
* Copyright (c) 2012 Todoroo Inc
*
* See the file "LICENSE" for the full license governing this code.
*/
package com.todoroo.astrid.service;
import android.content.Context;
import dagger.Lazy;
import javax.inject.Inject;
import org.tasks.BuildConfig;
import org.tasks.analytics.Tracker;
import org.tasks.injection.ForApplication;
import org.tasks.preferences.Preferences;
import org.tasks.scheduling.BackgroundScheduler;
import timber.log.Timber;
public class StartupService {
private final Preferences preferences;
private final Context context;
private final Lazy<Upgrader> upgrader;
@Inject
public StartupService(
Preferences preferences,
Tracker tracker,
@ForApplication Context context,
Lazy<Upgrader> upgrader) {
this.preferences = preferences;
this.context = context;
this.upgrader = upgrader;
}
/** Called when this application is started up */
public synchronized void onStartupApplication() {
// read current version
final int lastVersion = preferences.getLastSetVersion();
final int currentVersion = BuildConfig.VERSION_CODE;
Timber.i("Astrid Startup. %s => %s", lastVersion, currentVersion);
// invoke upgrade service
if (lastVersion != currentVersion) {
upgrader.get().upgrade(lastVersion, currentVersion);
preferences.setDefaults();
}
BackgroundScheduler.enqueueWork(context);
}
}

@ -22,7 +22,6 @@ import com.todoroo.astrid.tags.TagService;
import java.io.File; import java.io.File;
import java.util.List; import java.util.List;
import javax.inject.Inject; import javax.inject.Inject;
import org.tasks.LocalBroadcastManager;
import org.tasks.R; import org.tasks.R;
import org.tasks.analytics.Tracker; import org.tasks.analytics.Tracker;
import org.tasks.analytics.Tracking; import org.tasks.analytics.Tracking;
@ -55,7 +54,6 @@ public class Upgrader {
private final Tracker tracker; private final Tracker tracker;
private final TagDataDao tagDataDao; private final TagDataDao tagDataDao;
private final TagService tagService; private final TagService tagService;
private final LocalBroadcastManager localBroadcastManager;
private final TagDao tagDao; private final TagDao tagDao;
private final FilterDao filterDao; private final FilterDao filterDao;
private final DefaultFilterProvider defaultFilterProvider; private final DefaultFilterProvider defaultFilterProvider;
@ -71,7 +69,6 @@ public class Upgrader {
Tracker tracker, Tracker tracker,
TagDataDao tagDataDao, TagDataDao tagDataDao,
TagService tagService, TagService tagService,
LocalBroadcastManager localBroadcastManager,
TagDao tagDao, TagDao tagDao,
FilterDao filterDao, FilterDao filterDao,
DefaultFilterProvider defaultFilterProvider, DefaultFilterProvider defaultFilterProvider,
@ -83,7 +80,6 @@ public class Upgrader {
this.tracker = tracker; this.tracker = tracker;
this.tagDataDao = tagDataDao; this.tagDataDao = tagDataDao;
this.tagService = tagService; this.tagService = tagService;
this.localBroadcastManager = localBroadcastManager;
this.tagDao = tagDao; this.tagDao = tagDao;
this.filterDao = filterDao; this.filterDao = filterDao;
this.defaultFilterProvider = defaultFilterProvider; this.defaultFilterProvider = defaultFilterProvider;
@ -93,33 +89,29 @@ public class Upgrader {
} }
public void upgrade(int from, int to) { public void upgrade(int from, int to) {
try { if (from > 0) {
if (from > 0) { if (from < V4_8_0) {
if (from < V4_8_0) { performMarshmallowMigration();
performMarshmallowMigration(); }
} if (from < V4_9_5) {
if (from < V4_9_5) { removeDuplicateTags();
removeDuplicateTags(); }
} if (from < V5_3_0) {
if (from < V5_3_0) { migrateFilters();
migrateFilters(); }
} if (from < V6_0_beta_1) {
if (from < V6_0_beta_1) { migrateDefaultSyncList();
migrateDefaultSyncList(); }
} if (from < V6_0_beta_2) {
if (from < V6_0_beta_2) { migrateGoogleTaskAccount();
migrateGoogleTaskAccount(); }
} if (from < V6_4) {
if (from < V6_4) { migrateUris();
migrateUris();
}
tracker.reportEvent(Tracking.Events.UPGRADE, Integer.toString(from));
} }
createNotificationChannels(); tracker.reportEvent(Tracking.Events.UPGRADE, Integer.toString(from));
preferences.setCurrentVersion(to);
} finally {
localBroadcastManager.broadcastRefresh();
} }
createNotificationChannels();
preferences.setCurrentVersion(to);
} }
private void createNotificationChannels() { private void createNotificationChannels() {
@ -180,7 +172,6 @@ public class Upgrader {
removeDuplicateTagData(tagsByUuid.get(uuid)); removeDuplicateTagData(tagsByUuid.get(uuid));
removeDuplicateTagMetadata(uuid); removeDuplicateTagMetadata(uuid);
} }
localBroadcastManager.broadcastRefresh();
} }
private void migrateFilters() { private void migrateFilters() {

@ -1,25 +1,39 @@
package org.tasks; package org.tasks;
import android.content.Context;
import com.jakewharton.processphoenix.ProcessPhoenix; import com.jakewharton.processphoenix.ProcessPhoenix;
import com.jakewharton.threetenabp.AndroidThreeTen; import com.jakewharton.threetenabp.AndroidThreeTen;
import com.todoroo.astrid.service.StartupService; import com.todoroo.astrid.service.Upgrader;
import dagger.Lazy;
import io.reactivex.Completable;
import io.reactivex.schedulers.Schedulers;
import javax.inject.Inject; import javax.inject.Inject;
import org.tasks.files.FileHelper;
import org.tasks.injection.ApplicationComponent; import org.tasks.injection.ApplicationComponent;
import org.tasks.injection.ForApplication;
import org.tasks.injection.InjectingApplication; import org.tasks.injection.InjectingApplication;
import org.tasks.jobs.WorkManager; import org.tasks.jobs.WorkManager;
import org.tasks.location.GeofenceService;
import org.tasks.preferences.Preferences; import org.tasks.preferences.Preferences;
import org.tasks.receivers.Badger; import org.tasks.receivers.Badger;
import org.tasks.scheduling.CalendarNotificationIntentService;
import org.tasks.scheduling.NotificationSchedulerIntentService;
import org.tasks.scheduling.RefreshScheduler;
import org.tasks.themes.ThemeCache; import org.tasks.themes.ThemeCache;
import timber.log.Timber;
public class Tasks extends InjectingApplication { public class Tasks extends InjectingApplication {
@Inject StartupService startupService; @Inject @ForApplication Context context;
@Inject Lazy<Upgrader> upgrader;
@Inject Preferences preferences; @Inject Preferences preferences;
@Inject FlavorSetup flavorSetup; @Inject FlavorSetup flavorSetup;
@Inject BuildSetup buildSetup; @Inject BuildSetup buildSetup;
@Inject ThemeCache themeCache; @Inject ThemeCache themeCache;
@Inject Badger badger; @Inject Badger badger;
@Inject WorkManager workManager; @Inject WorkManager workManager;
@Inject RefreshScheduler refreshScheduler;
@Inject GeofenceService geofenceService;
@Override @Override
public void onCreate() { public void onCreate() {
@ -29,6 +43,8 @@ public class Tasks extends InjectingApplication {
return; return;
} }
upgrade();
workManager.init(); workManager.init();
AndroidThreeTen.init(this); AndroidThreeTen.init(this);
@ -41,9 +57,31 @@ public class Tasks extends InjectingApplication {
themeCache.getThemeBase(preferences.getInt(R.string.p_theme, 0)).setDefaultNightMode(); themeCache.getThemeBase(preferences.getInt(R.string.p_theme, 0)).setDefaultNightMode();
startupService.onStartupApplication(); Completable.fromAction(this::doInBackground).subscribeOn(Schedulers.io()).subscribe();
}
private void upgrade() {
final int lastVersion = preferences.getLastSetVersion();
final int currentVersion = BuildConfig.VERSION_CODE;
Timber.i("Astrid Startup. %s => %s", lastVersion, currentVersion);
// invoke upgrade service
if (lastVersion != currentVersion) {
upgrader.get().upgrade(lastVersion, currentVersion);
preferences.setDefaults();
}
}
workManager.onStartup(); private void doInBackground() {
NotificationSchedulerIntentService.enqueueWork(context, false);
CalendarNotificationIntentService.enqueueWork(context);
refreshScheduler.scheduleAll();
workManager.updateBackgroundSync();
workManager.scheduleMidnightRefresh();
workManager.scheduleBackup();
geofenceService.setupGeofences();
FileHelper.delete(context, preferences.getCacheDirectory());
} }
@Override @Override

@ -8,7 +8,6 @@ import timber.log.Timber;
public abstract class InjectingJobIntentService extends JobIntentService { public abstract class InjectingJobIntentService extends JobIntentService {
public static final int JOB_ID_BACKGROUND_SCHEDULER = 1080;
public static final int JOB_ID_GEOFENCE_TRANSITION = 1081; public static final int JOB_ID_GEOFENCE_TRANSITION = 1081;
public static final int JOB_ID_GEOFENCE_SCHEDULING = 1082; public static final int JOB_ID_GEOFENCE_SCHEDULING = 1082;
public static final int JOB_ID_NOTIFICATION_SCHEDULER = 1084; public static final int JOB_ID_NOTIFICATION_SCHEDULER = 1084;

@ -4,24 +4,18 @@ import dagger.Subcomponent;
import org.tasks.jobs.NotificationService; import org.tasks.jobs.NotificationService;
import org.tasks.locale.receiver.TaskerIntentService; import org.tasks.locale.receiver.TaskerIntentService;
import org.tasks.location.GeofenceTransitionsIntentService; import org.tasks.location.GeofenceTransitionsIntentService;
import org.tasks.scheduling.BackgroundScheduler;
import org.tasks.scheduling.CalendarNotificationIntentService; import org.tasks.scheduling.CalendarNotificationIntentService;
import org.tasks.scheduling.GeofenceSchedulingIntentService;
import org.tasks.scheduling.NotificationSchedulerIntentService; import org.tasks.scheduling.NotificationSchedulerIntentService;
@Subcomponent(modules = ServiceModule.class) @Subcomponent(modules = ServiceModule.class)
public interface ServiceComponent { public interface ServiceComponent {
void inject(GeofenceSchedulingIntentService geofenceSchedulingIntentService);
void inject(CalendarNotificationIntentService calendarNotificationIntentService); void inject(CalendarNotificationIntentService calendarNotificationIntentService);
void inject(GeofenceTransitionsIntentService geofenceTransitionsIntentService); void inject(GeofenceTransitionsIntentService geofenceTransitionsIntentService);
void inject(NotificationSchedulerIntentService notificationSchedulerIntentService); void inject(NotificationSchedulerIntentService notificationSchedulerIntentService);
void inject(BackgroundScheduler backgroundScheduler);
void inject(TaskerIntentService taskerIntentService); void inject(TaskerIntentService taskerIntentService);
void inject(NotificationService notificationService); void inject(NotificationService notificationService);

@ -161,7 +161,7 @@ public class WorkManager {
enqueueUnique(TAG_REFRESH, RefreshWork.class, time); enqueueUnique(TAG_REFRESH, RefreshWork.class, time);
} }
void scheduleMidnightRefresh() { public void scheduleMidnightRefresh() {
enqueueUnique(TAG_MIDNIGHT_REFRESH, MidnightRefreshWork.class, midnight()); enqueueUnique(TAG_MIDNIGHT_REFRESH, MidnightRefreshWork.class, midnight());
} }
@ -186,7 +186,7 @@ public class WorkManager {
} }
} }
void scheduleBackup() { public void scheduleBackup() {
long lastBackup = preferences.getLong(R.string.p_last_backup, 0L); long lastBackup = preferences.getLong(R.string.p_last_backup, 0L);
enqueueUnique( enqueueUnique(
TAG_BACKUP, TAG_BACKUP,
@ -236,12 +236,6 @@ public class WorkManager {
alarmManager.cancel(getNotificationPendingIntent()); alarmManager.cancel(getNotificationPendingIntent());
} }
public void onStartup() {
updateBackgroundSync();
scheduleMidnightRefresh();
scheduleBackup();
}
private Intent getNotificationIntent() { private Intent getNotificationIntent() {
return new Intent(context, NotificationService.class); return new Intent(context, NotificationService.class);
} }

@ -33,10 +33,6 @@ public class GeofenceService {
geofenceApi.register(getGeofencesForTask(taskId)); geofenceApi.register(getGeofencesForTask(taskId));
} }
public void cancelGeofences() {
geofenceApi.cancel(getActiveGeofences());
}
public void cancelGeofences(long taskId) { public void cancelGeofences(long taskId) {
for (Location location : getGeofences(taskId)) { for (Location location : getGeofences(taskId)) {
geofenceApi.cancel(location); geofenceApi.cancel(location);

@ -1,52 +0,0 @@
package org.tasks.scheduling;
import android.content.Context;
import android.content.Intent;
import androidx.annotation.NonNull;
import com.todoroo.astrid.dao.TaskDao;
import com.todoroo.astrid.data.Task;
import javax.inject.Inject;
import org.tasks.files.FileHelper;
import org.tasks.injection.ForApplication;
import org.tasks.injection.InjectingJobIntentService;
import org.tasks.injection.ServiceComponent;
import org.tasks.jobs.WorkManager;
import org.tasks.preferences.Preferences;
import timber.log.Timber;
public class BackgroundScheduler extends InjectingJobIntentService {
@Inject @ForApplication Context context;
@Inject TaskDao taskDao;
@Inject WorkManager jobManager;
@Inject RefreshScheduler refreshScheduler;
@Inject Preferences preferences;
public static void enqueueWork(Context context) {
BackgroundScheduler.enqueueWork(
context,
BackgroundScheduler.class,
InjectingJobIntentService.JOB_ID_BACKGROUND_SCHEDULER,
new Intent(context, BackgroundScheduler.class));
}
@Override
protected void doWork(@NonNull Intent intent) {
Timber.d("onHandleWork(%s)", intent);
NotificationSchedulerIntentService.enqueueWork(context, false);
CalendarNotificationIntentService.enqueueWork(context);
GeofenceSchedulingIntentService.enqueueWork(context);
for (Task task : taskDao.needsRefresh()) {
refreshScheduler.scheduleRefresh(task);
}
FileHelper.delete(context, preferences.getCacheDirectory());
}
@Override
protected void inject(ServiceComponent component) {
component.inject(this);
}
}

@ -1,36 +0,0 @@
package org.tasks.scheduling;
import android.content.Context;
import android.content.Intent;
import androidx.core.app.JobIntentService;
import javax.inject.Inject;
import org.tasks.injection.InjectingJobIntentService;
import org.tasks.injection.ServiceComponent;
import org.tasks.location.GeofenceService;
import timber.log.Timber;
public class GeofenceSchedulingIntentService extends InjectingJobIntentService {
@Inject GeofenceService geofenceService;
public static void enqueueWork(Context context) {
JobIntentService.enqueueWork(
context,
GeofenceSchedulingIntentService.class,
InjectingJobIntentService.JOB_ID_GEOFENCE_SCHEDULING,
new Intent(context, GeofenceSchedulingIntentService.class));
}
@Override
protected void doWork(Intent intent) {
Timber.d("onHandleWork(%s)", intent);
geofenceService.cancelGeofences();
geofenceService.setupGeofences();
}
@Override
protected void inject(ServiceComponent component) {
component.inject(this);
}
}

@ -4,6 +4,7 @@ import static com.todoroo.andlib.utility.DateUtilities.ONE_MINUTE;
import static org.tasks.time.DateTimeUtils.currentTimeMillis; import static org.tasks.time.DateTimeUtils.currentTimeMillis;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import com.todoroo.astrid.dao.TaskDao;
import com.todoroo.astrid.data.Task; import com.todoroo.astrid.data.Task;
import java.util.List; import java.util.List;
import java.util.SortedSet; import java.util.SortedSet;
@ -16,11 +17,19 @@ import org.tasks.jobs.WorkManager;
public class RefreshScheduler { public class RefreshScheduler {
private final WorkManager workManager; private final WorkManager workManager;
private final TaskDao taskDao;
private final SortedSet<Long> jobs = new TreeSet<>(); private final SortedSet<Long> jobs = new TreeSet<>();
@Inject @Inject
public RefreshScheduler(WorkManager workManager) { public RefreshScheduler(WorkManager workManager, TaskDao taskDao) {
this.workManager = workManager; this.workManager = workManager;
this.taskDao = taskDao;
}
public synchronized void scheduleAll() {
for (Task task : taskDao.needsRefresh()) {
scheduleRefresh(task);
}
} }
public synchronized void scheduleRefresh(Task task) { public synchronized void scheduleRefresh(Task task) {

Loading…
Cancel
Save