From 3296e0da5739d6de5b694a3d2019e19b16ff4588 Mon Sep 17 00:00:00 2001 From: Ciaran Gultnieks Date: Wed, 17 Apr 2013 08:31:45 +0100 Subject: [PATCH 1/2] Get the update interval right --- src/org/fdroid/fdroid/UpdateService.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/org/fdroid/fdroid/UpdateService.java b/src/org/fdroid/fdroid/UpdateService.java index 97c310a9b..3d30dc670 100644 --- a/src/org/fdroid/fdroid/UpdateService.java +++ b/src/org/fdroid/fdroid/UpdateService.java @@ -122,11 +122,13 @@ public class UpdateService extends IntentService implements ProgressListener { return; } long elapsed = System.currentTimeMillis() - lastUpdate; - if (elapsed < interval * 60 * 60) { + if (elapsed < interval * 60 * 60 * 1000) { Log.d("FDroid", "Skipping update - done " + elapsed + "ms ago, interval is " + interval + " hours"); return; } + } else { + Log.d("FDroid", "Unscheduled (manually requested) update"); } boolean notify = prefs.getBoolean("updateNotify", false); From 3ba5c17937b59ee9a12bb825e1fe0e8e547e5a68 Mon Sep 17 00:00:00 2001 From: Ciaran Gultnieks Date: Wed, 17 Apr 2013 08:32:55 +0100 Subject: [PATCH 2/2] Ensure scheduled updates continue after upgrade Previously they would not resume until the next reboot. --- src/org/fdroid/fdroid/FDroidApp.java | 5 ++++- src/org/fdroid/fdroid/UpdateService.java | 9 ++++++--- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/org/fdroid/fdroid/FDroidApp.java b/src/org/fdroid/fdroid/FDroidApp.java index eb8ead6b9..5b6b543fb 100644 --- a/src/org/fdroid/fdroid/FDroidApp.java +++ b/src/org/fdroid/fdroid/FDroidApp.java @@ -25,6 +25,7 @@ import java.util.concurrent.Semaphore; import android.app.Application; import android.util.Log; +import android.content.Context; public class FDroidApp extends Application { @@ -43,7 +44,9 @@ public class FDroidApp extends Application { icon_path.mkdir(); apps = null; - DB.initDB(getApplicationContext()); + Context ctx = getApplicationContext(); + DB.initDB(ctx); + UpdateService.schedule(ctx); } diff --git a/src/org/fdroid/fdroid/UpdateService.java b/src/org/fdroid/fdroid/UpdateService.java index 3d30dc670..4b9f44bba 100644 --- a/src/org/fdroid/fdroid/UpdateService.java +++ b/src/org/fdroid/fdroid/UpdateService.java @@ -56,9 +56,8 @@ public class UpdateService extends IntentService implements ProgressListener { } // Schedule (or cancel schedule for) this service, according to the - // current preferences. Should be called a) at boot, or b) if the preference - // is changed. - // TODO: What if we get upgraded? + // current preferences. Should be called a) at boot, b) if the preference + // is changed, or c) on startup, in case we get upgraded. public static void schedule(Context ctx) { SharedPreferences prefs = PreferenceManager @@ -76,7 +75,11 @@ public class UpdateService extends IntentService implements ProgressListener { alarm.setInexactRepeating(AlarmManager.ELAPSED_REALTIME, SystemClock.elapsedRealtime() + 5000, AlarmManager.INTERVAL_HOUR, pending); + Log.d("FDroid", "Update scheduler alarm set"); + } else { + Log.d("FDroid", "Update scheduler alarm not set"); } + } protected void sendStatus(int statusCode ) {