Commit febaa87f authored by Mugdha Lakhani's avatar Mugdha Lakhani Committed by Commit Bot

[Background Sync] Fix Chrome wake up time window.

Per the documentation, setting windowEndTime as min_delay will run the task
after min_delay has passed, without respecting network type constraints:
https://cs.chromium.org/chromium/src/third_party/android_tools/sdk/sources/android-25/android/app/job/JobParameters.java?rcl=347a7c8078a009e98995985b7ab6ec6b35696dea&l=89

This change sets the start time as min_delay for the Chrome wake up task
for Background Sync, and sets the end of the window to Integer.MAX, so
that network connectivity constraints are always respected.

Bug: 924490
Change-Id: I2888127ce1133d5ae262f507180c5aa067e102aa
Reviewed-on: https://chromium-review.googlesource.com/c/1480528Reviewed-by: default avatarDavid Trainor <dtrainor@chromium.org>
Commit-Queue: Mugdha Lakhani <nator@chromium.org>
Cr-Commit-Position: refs/heads/master@{#634611}
parent 506f7f59
......@@ -71,13 +71,14 @@ public class BackgroundSyncBackgroundTaskScheduler {
Bundle taskExtras = new Bundle();
taskExtras.putLong(SOONEST_EXPECTED_WAKETIME, System.currentTimeMillis() + minDelayMs);
TaskInfo taskInfo = TaskInfo.createOneOffTask(TaskIds.BACKGROUND_SYNC_ONE_SHOT_JOB_ID,
BackgroundSyncBackgroundTask.class, minDelayMs)
.setRequiredNetworkType(TaskInfo.NetworkType.ANY)
.setUpdateCurrent(true)
.setIsPersisted(true)
.setExtras(taskExtras)
.build();
TaskInfo taskInfo =
TaskInfo.createOneOffTask(TaskIds.BACKGROUND_SYNC_ONE_SHOT_JOB_ID,
BackgroundSyncBackgroundTask.class, minDelayMs, Integer.MAX_VALUE)
.setRequiredNetworkType(TaskInfo.NetworkType.ANY)
.setUpdateCurrent(true)
.setIsPersisted(true)
.setExtras(taskExtras)
.build();
// This will overwrite any existing task with this ID.
return BackgroundTaskSchedulerFactory.getScheduler().schedule(
ContextUtils.getApplicationContext(), taskInfo);
......
......@@ -87,7 +87,7 @@ public class BackgroundSyncBackgroundTaskSchedulerTest {
TaskInfo taskInfo = mTaskInfo.getValue();
verifyFixedTaskInfoValues(taskInfo);
assertEquals(ONE_DAY_IN_MILLISECONDS, taskInfo.getOneOffInfo().getWindowEndTimeMs());
assertEquals(ONE_DAY_IN_MILLISECONDS, taskInfo.getOneOffInfo().getWindowStartTimeMs());
}
@Test
......@@ -120,7 +120,7 @@ public class BackgroundSyncBackgroundTaskSchedulerTest {
.schedule(eq(RuntimeEnvironment.application), eq(mTaskInfo.getValue()));
TaskInfo taskInfo = mTaskInfo.getValue();
assertEquals(ONE_DAY_IN_MILLISECONDS, taskInfo.getOneOffInfo().getWindowEndTimeMs());
assertEquals(ONE_DAY_IN_MILLISECONDS, taskInfo.getOneOffInfo().getWindowStartTimeMs());
BackgroundSyncBackgroundTaskScheduler.getInstance().launchBrowserIfStopped(
/* shouldLaunch= */ true,
......@@ -129,7 +129,7 @@ public class BackgroundSyncBackgroundTaskSchedulerTest {
.schedule(eq(RuntimeEnvironment.application), eq(mTaskInfo.getValue()));
taskInfo = mTaskInfo.getValue();
assertEquals(ONE_WEEK_IN_MILLISECONDS, taskInfo.getOneOffInfo().getWindowEndTimeMs());
assertEquals(ONE_WEEK_IN_MILLISECONDS, taskInfo.getOneOffInfo().getWindowStartTimeMs());
}
@Test
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment