diff options
Diffstat (limited to 'chromium/components/background_task_scheduler')
9 files changed, 29 insertions, 27 deletions
diff --git a/chromium/components/background_task_scheduler/BUILD.gn b/chromium/components/background_task_scheduler/BUILD.gn index 8a71072bceb..7c4436d9e68 100644 --- a/chromium/components/background_task_scheduler/BUILD.gn +++ b/chromium/components/background_task_scheduler/BUILD.gn @@ -119,6 +119,7 @@ if (is_android) { ] deps = [ + ":background_task_scheduler_task_ids_java", "$google_play_services_package:google_play_services_auth_base_java", "$google_play_services_package:google_play_services_base_java", "$google_play_services_package:google_play_services_basement_java", @@ -130,7 +131,9 @@ if (is_android) { "//base:base_java_test_support", "//base:base_junit_test_support", "//components/background_task_scheduler:public_java", + "//third_party/android_deps:robolectric_all_java", "//third_party/junit", + "//third_party/mockito:mockito_java", ] } } diff --git a/chromium/components/background_task_scheduler/android/java/src/org/chromium/components/background_task_scheduler/BackgroundTaskSchedulerExternalUma.java b/chromium/components/background_task_scheduler/android/java/src/org/chromium/components/background_task_scheduler/BackgroundTaskSchedulerExternalUma.java index b09fdbccfa7..086c81110cb 100644 --- a/chromium/components/background_task_scheduler/android/java/src/org/chromium/components/background_task_scheduler/BackgroundTaskSchedulerExternalUma.java +++ b/chromium/components/background_task_scheduler/android/java/src/org/chromium/components/background_task_scheduler/BackgroundTaskSchedulerExternalUma.java @@ -37,8 +37,9 @@ public abstract class BackgroundTaskSchedulerExternalUma { public static final int BACKGROUND_TASK_PERIODIC_SYNC_WAKE_UP = 22; public static final int BACKGROUND_TASK_QUERY_TILE = 23; public static final int BACKGROUND_TASK_FEEDV2_REFRESH = 24; + public static final int BACKGROUND_TASK_DOWNLOAD_LATER = 25; // Keep this one at the end and increment appropriately when adding new tasks. - public static final int BACKGROUND_TASK_COUNT = 25; + public static final int BACKGROUND_TASK_COUNT = 26; protected BackgroundTaskSchedulerExternalUma() {} @@ -119,6 +120,8 @@ public abstract class BackgroundTaskSchedulerExternalUma { return BACKGROUND_TASK_DOWNLOAD_CLEANUP; case TaskIds.DOWNLOAD_AUTO_RESUMPTION_JOB_ID: return BACKGROUND_TASK_DOWNLOAD_AUTO_RESUMPTION; + case TaskIds.DOWNLOAD_LATER_JOB_ID: + return BACKGROUND_TASK_DOWNLOAD_LATER; case TaskIds.WEBVIEW_VARIATIONS_SEED_FETCH_JOB_ID: return BACKGROUND_TASK_WEBVIEW_VARIATIONS; case TaskIds.OFFLINE_PAGES_PREFETCH_NOTIFICATION_JOB_ID: diff --git a/chromium/components/background_task_scheduler/android/java/src/org/chromium/components/background_task_scheduler/TaskInfo.java b/chromium/components/background_task_scheduler/android/java/src/org/chromium/components/background_task_scheduler/TaskInfo.java index 4e144a6772c..c31b6515905 100644 --- a/chromium/components/background_task_scheduler/android/java/src/org/chromium/components/background_task_scheduler/TaskInfo.java +++ b/chromium/components/background_task_scheduler/android/java/src/org/chromium/components/background_task_scheduler/TaskInfo.java @@ -566,11 +566,9 @@ public class TaskInfo { /** * Schedule a one-off task to execute within a deadline. If windowEndTimeMs is 0, the task will * run as soon as possible. For executing a task within a time window, see - * {@link #createOneOffTask(int, Class, long, long)}. + * {@link #createOneOffTask(int, long, long)}. * * @param taskId the unique task ID for this task. Should be listed in {@link TaskIds}. - * @param backgroundTaskClass the {@link BackgroundTask} class that will be instantiated for - * this task. * @param windowEndTimeMs the end of the window that the task can begin executing as a delta in * milliseconds from now. Note that the task begins executing at this point even if the * prerequisite conditions are not met. @@ -582,19 +580,16 @@ public class TaskInfo { * {@link TimingInfo} object with the wanted properties. */ @Deprecated - public static Builder createOneOffTask( - int taskId, Class<? extends BackgroundTask> backgroundTaskClass, long windowEndTimeMs) { + public static Builder createOneOffTask(int taskId, long windowEndTimeMs) { TimingInfo oneOffInfo = OneOffInfo.create().setWindowEndTimeMs(windowEndTimeMs).build(); return new Builder(taskId).setTimingInfo(oneOffInfo); } /** * Schedule a one-off task to execute within a time window. For executing a task within a - * deadline, see {@link #createOneOffTask(int, Class, long)}, + * deadline, see {@link #createOneOffTask(int, long)}, * * @param taskId the unique task ID for this task. Should be listed in {@link TaskIds}. - * @param backgroundTaskClass the {@link BackgroundTask} class that will be instantiated for - * this task. * @param windowStartTimeMs the start of the window that the task can begin executing as a delta * in milliseconds from now. * @param windowEndTimeMs the end of the window that the task can begin executing as a delta in @@ -608,9 +603,8 @@ public class TaskInfo { * {@link TimingInfo} object with the wanted properties. */ @Deprecated - public static Builder createOneOffTask(int taskId, - Class<? extends BackgroundTask> backgroundTaskClass, long windowStartTimeMs, - long windowEndTimeMs) { + public static Builder createOneOffTask( + int taskId, long windowStartTimeMs, long windowEndTimeMs) { TimingInfo oneOffInfo = OneOffInfo.create() .setWindowStartTimeMs(windowStartTimeMs) .setWindowEndTimeMs(windowEndTimeMs) @@ -628,8 +622,6 @@ public class TaskInfo { * flex milliseconds before. * * @param taskId the unique task ID for this task. Should be listed in {@link TaskIds}. - * @param backgroundTaskClass the {@link BackgroundTask} class that will be instantiated for - * this task. * @param intervalMs the interval between occurrences of this task in milliseconds. * @param flexMs the flex time for this task. The task can execute at any time in a window of * flex @@ -637,13 +629,12 @@ public class TaskInfo { * @return the builder which can be used to continue configuration and {@link Builder#build()}. * @see TaskIds * - * @deprecated the {@see #createTask(int, Class, TimingInfo)} method should be used instead. + * @deprecated the {@see #createTask(int, TimingInfo)} method should be used instead. * This method requires an additional step for the caller: the creation of the specific * {@link TimingInfo} object with the wanted properties. */ @Deprecated - public static Builder createPeriodicTask(int taskId, - Class<? extends BackgroundTask> backgroundTaskClass, long intervalMs, long flexMs) { + public static Builder createPeriodicTask(int taskId, long intervalMs, long flexMs) { TimingInfo periodicInfo = PeriodicInfo.create().setIntervalMs(intervalMs).setFlexMs(flexMs).build(); return new Builder(taskId).setTimingInfo(periodicInfo); diff --git a/chromium/components/background_task_scheduler/internal/android/java/src/org/chromium/components/background_task_scheduler/internal/BackgroundTaskSchedulerJobService.java b/chromium/components/background_task_scheduler/internal/android/java/src/org/chromium/components/background_task_scheduler/internal/BackgroundTaskSchedulerJobService.java index 85cb5208e7c..a013c1c4d22 100644 --- a/chromium/components/background_task_scheduler/internal/android/java/src/org/chromium/components/background_task_scheduler/internal/BackgroundTaskSchedulerJobService.java +++ b/chromium/components/background_task_scheduler/internal/android/java/src/org/chromium/components/background_task_scheduler/internal/BackgroundTaskSchedulerJobService.java @@ -64,6 +64,12 @@ class BackgroundTaskSchedulerJobService implements BackgroundTaskSchedulerDelega return TaskInfo.OneOffInfo.getExpirationStatus( scheduleTimeMs, endTimeMs, currentTimeMs); } else { + if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N) { + // Before Android N, there was no control over when the job will execute within + // the given interval. This makes it impossible to check for an expiration time. + return false; + } + long intervalTimeMs = extras.getLong(BACKGROUND_TASK_INTERVAL_TIME_KEY); // Based on the JobInfo documentation, attempting to declare a smaller period than // this when scheduling a job will result in a job that is still periodic, but will @@ -72,12 +78,6 @@ class BackgroundTaskSchedulerJobService implements BackgroundTaskSchedulerDelega intervalTimeMs = JobInfo.getMinPeriodMillis(); } - if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N) { - // Before Android N, there was no control over when the job will execute within - // the given interval. This makes it impossible to check for an expiration time. - return false; - } - // Since Android N, there was a minimum of 5 min set for the flex value. This // value is considerably lower from the previous one, since the minimum value // allowed for the interval time is of 15 min: diff --git a/chromium/components/background_task_scheduler/internal/android/javatests/src/org/chromium/components/background_task_scheduler/internal/BackgroundTaskSchedulerImplWithMockTest.java b/chromium/components/background_task_scheduler/internal/android/javatests/src/org/chromium/components/background_task_scheduler/internal/BackgroundTaskSchedulerImplWithMockTest.java index 399b15b7e3c..113796378df 100644 --- a/chromium/components/background_task_scheduler/internal/android/javatests/src/org/chromium/components/background_task_scheduler/internal/BackgroundTaskSchedulerImplWithMockTest.java +++ b/chromium/components/background_task_scheduler/internal/android/javatests/src/org/chromium/components/background_task_scheduler/internal/BackgroundTaskSchedulerImplWithMockTest.java @@ -4,7 +4,7 @@ package org.chromium.components.background_task_scheduler.internal; -import android.support.test.filters.SmallTest; +import androidx.test.filters.SmallTest; import org.junit.Assert; import org.junit.Before; diff --git a/chromium/components/background_task_scheduler/internal/android/javatests/src/org/chromium/components/background_task_scheduler/internal/BackgroundTaskSchedulerJobServiceTest.java b/chromium/components/background_task_scheduler/internal/android/javatests/src/org/chromium/components/background_task_scheduler/internal/BackgroundTaskSchedulerJobServiceTest.java index 93b6afca115..f6036c5c39e 100644 --- a/chromium/components/background_task_scheduler/internal/android/javatests/src/org/chromium/components/background_task_scheduler/internal/BackgroundTaskSchedulerJobServiceTest.java +++ b/chromium/components/background_task_scheduler/internal/android/javatests/src/org/chromium/components/background_task_scheduler/internal/BackgroundTaskSchedulerJobServiceTest.java @@ -10,7 +10,8 @@ import android.os.Build; import android.os.Bundle; import android.os.PersistableBundle; import android.support.test.InstrumentationRegistry; -import android.support.test.filters.SmallTest; + +import androidx.test.filters.SmallTest; import org.junit.Assert; import org.junit.Before; diff --git a/chromium/components/background_task_scheduler/internal/android/javatests/src/org/chromium/components/background_task_scheduler/internal/BundleToPersistableBundleConverterTest.java b/chromium/components/background_task_scheduler/internal/android/javatests/src/org/chromium/components/background_task_scheduler/internal/BundleToPersistableBundleConverterTest.java index 76752c0b01f..576ec1638a0 100644 --- a/chromium/components/background_task_scheduler/internal/android/javatests/src/org/chromium/components/background_task_scheduler/internal/BundleToPersistableBundleConverterTest.java +++ b/chromium/components/background_task_scheduler/internal/android/javatests/src/org/chromium/components/background_task_scheduler/internal/BundleToPersistableBundleConverterTest.java @@ -8,7 +8,8 @@ import android.annotation.TargetApi; import android.os.Build; import android.os.Bundle; import android.os.PersistableBundle; -import android.support.test.filters.SmallTest; + +import androidx.test.filters.SmallTest; import org.junit.Assert; import org.junit.Test; diff --git a/chromium/components/background_task_scheduler/internal/android/junit/src/org/chromium/components/background_task_scheduler/internal/BackgroundTaskSchedulerUmaTest.java b/chromium/components/background_task_scheduler/internal/android/junit/src/org/chromium/components/background_task_scheduler/internal/BackgroundTaskSchedulerUmaTest.java index 923cbeebedc..cefc5d21a80 100644 --- a/chromium/components/background_task_scheduler/internal/android/junit/src/org/chromium/components/background_task_scheduler/internal/BackgroundTaskSchedulerUmaTest.java +++ b/chromium/components/background_task_scheduler/internal/android/junit/src/org/chromium/components/background_task_scheduler/internal/BackgroundTaskSchedulerUmaTest.java @@ -85,6 +85,8 @@ public class BackgroundTaskSchedulerUmaTest { assertEquals(BackgroundTaskSchedulerUma.BACKGROUND_TASK_DOWNLOAD_AUTO_RESUMPTION, BackgroundTaskSchedulerUma.toUmaEnumValueFromTaskId( TaskIds.DOWNLOAD_AUTO_RESUMPTION_JOB_ID)); + assertEquals(BackgroundTaskSchedulerUma.BACKGROUND_TASK_DOWNLOAD_LATER, + BackgroundTaskSchedulerUma.toUmaEnumValueFromTaskId(TaskIds.DOWNLOAD_LATER_JOB_ID)); assertEquals(BackgroundTaskSchedulerUma.BACKGROUND_TASK_WEBVIEW_VARIATIONS, BackgroundTaskSchedulerUma.toUmaEnumValueFromTaskId( TaskIds.WEBVIEW_VARIATIONS_SEED_FETCH_JOB_ID)); @@ -123,7 +125,7 @@ public class BackgroundTaskSchedulerUmaTest { BackgroundTaskSchedulerUma.toUmaEnumValueFromTaskId(TaskIds.QUERY_TILE_JOB_ID)); assertEquals(BackgroundTaskSchedulerUma.BACKGROUND_TASK_FEEDV2_REFRESH, BackgroundTaskSchedulerUma.toUmaEnumValueFromTaskId(TaskIds.FEEDV2_REFRESH_JOB_ID)); - assertEquals(BackgroundTaskSchedulerUma.BACKGROUND_TASK_COUNT, 25); + assertEquals(BackgroundTaskSchedulerUma.BACKGROUND_TASK_COUNT, 26); } @Test diff --git a/chromium/components/background_task_scheduler/task_ids.h b/chromium/components/background_task_scheduler/task_ids.h index 78b491ab4e9..d9fea21eda6 100644 --- a/chromium/components/background_task_scheduler/task_ids.h +++ b/chromium/components/background_task_scheduler/task_ids.h @@ -37,6 +37,7 @@ enum class TaskIds { WEBAPK_UPDATE_JOB_ID = 91, DOWNLOAD_RESUMPTION_JOB_ID = 55, DOWNLOAD_AUTO_RESUMPTION_JOB_ID = 56, + DOWNLOAD_LATER_JOB_ID = 57, FEED_REFRESH_JOB_ID = 22, COMPONENT_UPDATE_JOB_ID = 2, DEPRECATED_EXPLORE_SITES_REFRESH_JOB_ID = 100, |