Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(321)

Unified Diff: components/background_task_scheduler/android/java/src/org/chromium/components/background_task_scheduler/BackgroundTaskScheduler.java

Issue 2819703002: [Android] Implements OS upgrade check and rescheduling (Closed)
Patch Set: Calling upgrade task from DeferredStartupHandler Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: components/background_task_scheduler/android/java/src/org/chromium/components/background_task_scheduler/BackgroundTaskScheduler.java
diff --git a/components/background_task_scheduler/android/java/src/org/chromium/components/background_task_scheduler/BackgroundTaskScheduler.java b/components/background_task_scheduler/android/java/src/org/chromium/components/background_task_scheduler/BackgroundTaskScheduler.java
index d7570fca637dd1365ba0b07f4f7fea13f1c0f01c..a8b76b74702e6f2f3e3d0a417b64800603c67800 100644
--- a/components/background_task_scheduler/android/java/src/org/chromium/components/background_task_scheduler/BackgroundTaskScheduler.java
+++ b/components/background_task_scheduler/android/java/src/org/chromium/components/background_task_scheduler/BackgroundTaskScheduler.java
@@ -92,6 +92,40 @@ public class BackgroundTaskScheduler {
mSchedulerDelegate.cancel(context, taskId);
}
+ /**
+ * Checks whether OS was upgraded and triggers rescheduling if it is necessary.
+ * Rescheduling is necessary if type of background task scheduler delegate is different for a
+ * new version of the OS.
+ *
+ * @param context the current context.
+ */
+ public void checkForOSUpgrade(Context context) {
+ int oldSdkInt = BackgroundTaskSchedulerPrefs.getLastSdkVersion();
+ int newSdkInt = Build.VERSION.SDK_INT;
+ // No OS upgrade detected.
+ if (oldSdkInt == newSdkInt) return;
+
+ // Save the current SDK version to preferences.
+ BackgroundTaskSchedulerPrefs.setLastSdkVersion(newSdkInt);
+
+ // OS upgrade detected within the same delegate type. No is upgrade necessary.
+ if ((oldSdkInt < Build.VERSION_CODES.M && newSdkInt < Build.VERSION_CODES.M)
nyquist 2017/04/18 22:41:08 Do we want to extract the conditional out to somet
fgorski 2017/04/20 22:36:07 Done.
+ || (oldSdkInt >= Build.VERSION_CODES.M && newSdkInt >= Build.VERSION_CODES.M)) {
nyquist 2017/04/18 22:41:08 Maybe stupid question, but if oldSdkInt was someho
fgorski 2017/04/20 22:36:07 I proposed some changes that work, but I am not ve
nyquist 2017/04/25 20:43:56 Yeah, I'm not sure if that is necessary. It feels
+ return;
+ }
+
+ // Explicitly invoke create old delegate type to cancel all scheduled tasks.
nyquist 2017/04/18 22:41:08 Something seems to be off with this sentence: "inv
fgorski 2017/04/20 22:36:07 Done.
+ // All preference entries are kept until reschedule call, which removes then then.
+ BackgroundTaskSchedulerDelegate oldDelegate =
+ new BackgroundTaskSchedulerGcmNetworkManager();
+ Set<Integer> scheduledTaskIds = BackgroundTaskSchedulerPrefs.getScheduledTaskIds();
+ for (int taskId : scheduledTaskIds) {
+ oldDelegate.cancel(context, taskId);
+ }
+
+ reschedule(context);
+ }
+
public void reschedule(Context context) {
Set<String> scheduledTasksClassNames = BackgroundTaskSchedulerPrefs.getScheduledTasks();
BackgroundTaskSchedulerPrefs.removeAllTasks();

Powered by Google App Engine
This is Rietveld 408576698