summaryrefslogtreecommitdiffstats
path: root/core/java/android
diff options
context:
space:
mode:
authorChristopher Tate <ctate@google.com>2014-06-10 21:27:53 +0000
committerAndroid (Google) Code Review <android-gerrit@google.com>2014-06-10 21:27:54 +0000
commite9ed3707b234c893622aec3ddecbf2f9d41d1454 (patch)
tree5e78c9c2ab1b7b2f1c1daedb06104cd7a2647e41 /core/java/android
parent583b6f782c2e989bd6d62838a3f1c69104335fdd (diff)
parent7060b04f6d92351b67222e636ab378a0273bf3e7 (diff)
downloadframeworks_base-e9ed3707b234c893622aec3ddecbf2f9d41d1454.zip
frameworks_base-e9ed3707b234c893622aec3ddecbf2f9d41d1454.tar.gz
frameworks_base-e9ed3707b234c893622aec3ddecbf2f9d41d1454.tar.bz2
Merge "Out with the old; in with the new" into lmp-preview-dev
Diffstat (limited to 'core/java/android')
-rw-r--r--core/java/android/app/ContextImpl.java8
-rw-r--r--core/java/android/app/JobSchedulerImpl.java (renamed from core/java/android/app/TaskManagerImpl.java)28
-rw-r--r--core/java/android/app/job/IJobCallback.aidl (renamed from core/java/android/app/task/ITaskCallback.aidl)31
-rw-r--r--core/java/android/app/job/IJobScheduler.aidl (renamed from core/java/android/app/task/ITaskManager.aidl)14
-rw-r--r--core/java/android/app/job/IJobService.aidl (renamed from core/java/android/app/task/ITaskService.aidl)19
-rw-r--r--core/java/android/app/job/JobInfo.aidl (renamed from core/java/android/app/task/Task.aidl)5
-rw-r--r--core/java/android/app/job/JobInfo.java (renamed from core/java/android/app/task/Task.java)150
-rw-r--r--core/java/android/app/job/JobParameters.aidl (renamed from core/java/android/app/task/TaskParams.aidl)4
-rw-r--r--core/java/android/app/job/JobParameters.java (renamed from core/java/android/app/task/TaskParams.java)44
-rw-r--r--core/java/android/app/job/JobScheduler.java72
-rw-r--r--core/java/android/app/job/JobService.java (renamed from core/java/android/app/task/TaskService.java)161
-rw-r--r--core/java/android/app/task/TaskManager.java72
-rw-r--r--core/java/android/content/Context.java16
13 files changed, 311 insertions, 313 deletions
diff --git a/core/java/android/app/ContextImpl.java b/core/java/android/app/ContextImpl.java
index 5bbc43c..c5190d3 100644
--- a/core/java/android/app/ContextImpl.java
+++ b/core/java/android/app/ContextImpl.java
@@ -133,7 +133,7 @@ import android.view.textservice.TextServicesManager;
import android.accounts.AccountManager;
import android.accounts.IAccountManager;
import android.app.admin.DevicePolicyManager;
-import android.app.task.ITaskManager;
+import android.app.job.IJobScheduler;
import android.app.trust.TrustManager;
import com.android.internal.annotations.GuardedBy;
@@ -697,10 +697,10 @@ class ContextImpl extends Context {
return new UsageStatsManager(ctx.getOuterContext());
}});
- registerService(TASK_SERVICE, new ServiceFetcher() {
+ registerService(JOB_SCHEDULER_SERVICE, new ServiceFetcher() {
public Object createService(ContextImpl ctx) {
- IBinder b = ServiceManager.getService(TASK_SERVICE);
- return new TaskManagerImpl(ITaskManager.Stub.asInterface(b));
+ IBinder b = ServiceManager.getService(JOB_SCHEDULER_SERVICE);
+ return new JobSchedulerImpl(IJobScheduler.Stub.asInterface(b));
}});
}
diff --git a/core/java/android/app/TaskManagerImpl.java b/core/java/android/app/JobSchedulerImpl.java
index fe29fb7..09038d5 100644
--- a/core/java/android/app/TaskManagerImpl.java
+++ b/core/java/android/app/JobSchedulerImpl.java
@@ -17,38 +17,38 @@
// in android.app so ContextImpl has package access
package android.app;
-import android.app.task.ITaskManager;
-import android.app.task.Task;
-import android.app.task.TaskManager;
+import android.app.job.JobInfo;
+import android.app.job.JobScheduler;
+import android.app.job.IJobScheduler;
import android.os.RemoteException;
import java.util.List;
/**
- * Concrete implementation of the TaskManager interface
+ * Concrete implementation of the JobScheduler interface
* @hide
*/
-public class TaskManagerImpl extends TaskManager {
- ITaskManager mBinder;
+public class JobSchedulerImpl extends JobScheduler {
+ IJobScheduler mBinder;
- /* package */ TaskManagerImpl(ITaskManager binder) {
+ /* package */ JobSchedulerImpl(IJobScheduler binder) {
mBinder = binder;
}
@Override
- public int schedule(Task task) {
+ public int schedule(JobInfo job) {
try {
- return mBinder.schedule(task);
+ return mBinder.schedule(job);
} catch (RemoteException e) {
- return TaskManager.RESULT_FAILURE;
+ return JobScheduler.RESULT_FAILURE;
}
}
@Override
- public void cancel(int taskId) {
+ public void cancel(int jobId) {
try {
- mBinder.cancel(taskId);
+ mBinder.cancel(jobId);
} catch (RemoteException e) {}
}
@@ -62,9 +62,9 @@ public class TaskManagerImpl extends TaskManager {
}
@Override
- public List<Task> getAllPendingTasks() {
+ public List<JobInfo> getAllPendingJobs() {
try {
- return mBinder.getAllPendingTasks();
+ return mBinder.getAllPendingJobs();
} catch (RemoteException e) {
return null;
}
diff --git a/core/java/android/app/task/ITaskCallback.aidl b/core/java/android/app/job/IJobCallback.aidl
index d8a32fd..2d3948f 100644
--- a/core/java/android/app/task/ITaskCallback.aidl
+++ b/core/java/android/app/job/IJobCallback.aidl
@@ -14,43 +14,40 @@
* limitations under the License.
*/
-package android.app.task;
-
-import android.app.task.ITaskService;
-import android.app.task.TaskParams;
+package android.app.job;
/**
- * The server side of the TaskManager IPC protocols. The app-side implementation
+ * The server side of the JobScheduler IPC protocols. The app-side implementation
* invokes on this interface to indicate completion of the (asynchronous) instructions
* issued by the server.
*
* In all cases, the 'who' parameter is the caller's service binder, used to track
- * which Task Service instance is reporting.
+ * which Job Service instance is reporting.
*
* {@hide}
*/
-interface ITaskCallback {
+interface IJobCallback {
/**
* Immediate callback to the system after sending a start signal, used to quickly detect ANR.
*
- * @param taskId Unique integer used to identify this task.
- * @param ongoing True to indicate that the client is processing the task. False if the task is
+ * @param jobId Unique integer used to identify this job.
+ * @param ongoing True to indicate that the client is processing the job. False if the job is
* complete
*/
- void acknowledgeStartMessage(int taskId, boolean ongoing);
+ void acknowledgeStartMessage(int jobId, boolean ongoing);
/**
* Immediate callback to the system after sending a stop signal, used to quickly detect ANR.
*
- * @param taskId Unique integer used to identify this task.
- * @param rescheulde Whether or not to reschedule this task.
+ * @param jobId Unique integer used to identify this job.
+ * @param reschedule Whether or not to reschedule this job.
*/
- void acknowledgeStopMessage(int taskId, boolean reschedule);
+ void acknowledgeStopMessage(int jobId, boolean reschedule);
/*
- * Tell the task manager that the client is done with its execution, so that it can go on to
+ * Tell the job manager that the client is done with its execution, so that it can go on to
* the next one and stop attributing wakelock time to us etc.
*
- * @param taskId Unique integer used to identify this task.
- * @param reschedule Whether or not to reschedule this task.
+ * @param jobId Unique integer used to identify this job.
+ * @param reschedule Whether or not to reschedule this job.
*/
- void taskFinished(int taskId, boolean reschedule);
+ void jobFinished(int jobId, boolean reschedule);
}
diff --git a/core/java/android/app/task/ITaskManager.aidl b/core/java/android/app/job/IJobScheduler.aidl
index b56c78a..f1258ae 100644
--- a/core/java/android/app/task/ITaskManager.aidl
+++ b/core/java/android/app/job/IJobScheduler.aidl
@@ -14,17 +14,17 @@
* limitations under the License.
*/
-package android.app.task;
+package android.app.job;
-import android.app.task.Task;
+import android.app.job.JobInfo;
/**
- * IPC interface that supports the app-facing {@link #TaskManager} api.
+ * IPC interface that supports the app-facing {@link #JobScheduler} api.
* {@hide}
*/
-interface ITaskManager {
- int schedule(in Task task);
- void cancel(int taskId);
+interface IJobScheduler {
+ int schedule(in JobInfo job);
+ void cancel(int jobId);
void cancelAll();
- List<Task> getAllPendingTasks();
+ List<JobInfo> getAllPendingJobs();
}
diff --git a/core/java/android/app/task/ITaskService.aidl b/core/java/android/app/job/IJobService.aidl
index 87b0191..63f8b81 100644
--- a/core/java/android/app/task/ITaskService.aidl
+++ b/core/java/android/app/job/IJobService.aidl
@@ -14,22 +14,19 @@
* limitations under the License.
*/
-package android.app.task;
+package android.app.job;
-import android.app.task.ITaskCallback;
-import android.app.task.TaskParams;
-
-import android.os.Bundle;
+import android.app.job.JobParameters;
/**
* Interface that the framework uses to communicate with application code that implements a
- * TaskService. End user code does not implement this interface directly; instead, the app's
- * service implementation will extend android.app.task.TaskService.
+ * JobService. End user code does not implement this interface directly; instead, the app's
+ * service implementation will extend android.app.job.JobService.
* {@hide}
*/
-oneway interface ITaskService {
- /** Begin execution of application's task. */
- void startTask(in TaskParams taskParams);
+oneway interface IJobService {
+ /** Begin execution of application's job. */
+ void startJob(in JobParameters jobParams);
/** Stop execution of application's task. */
- void stopTask(in TaskParams taskParams);
+ void stopJob(in JobParameters jobParams);
}
diff --git a/core/java/android/app/task/Task.aidl b/core/java/android/app/job/JobInfo.aidl
index 1f25439..7b198a8 100644
--- a/core/java/android/app/task/Task.aidl
+++ b/core/java/android/app/job/JobInfo.aidl
@@ -14,7 +14,6 @@
* limitations under the License.
*/
-package android.app.task;
+package android.app.job;
-parcelable Task;
- \ No newline at end of file
+parcelable JobInfo;
diff --git a/core/java/android/app/task/Task.java b/core/java/android/app/job/JobInfo.java
index 0e660b3..a22e4cd 100644
--- a/core/java/android/app/task/Task.java
+++ b/core/java/android/app/job/JobInfo.java
@@ -14,7 +14,7 @@
* limitations under the License
*/
-package android.app.task;
+package android.app.job;
import android.content.ComponentName;
import android.os.Bundle;
@@ -23,22 +23,22 @@ import android.os.Parcelable;
import android.os.PersistableBundle;
/**
- * Container of data passed to the {@link android.app.task.TaskManager} fully encapsulating the
+ * Container of data passed to the {@link android.app.job.JobScheduler} fully encapsulating the
* parameters required to schedule work against the calling application. These are constructed
- * using the {@link Task.Builder}.
+ * using the {@link JobInfo.Builder}.
*/
-public class Task implements Parcelable {
+public class JobInfo implements Parcelable {
public interface NetworkType {
/** Default. */
public final int NONE = 0;
- /** This task requires network connectivity. */
+ /** This job requires network connectivity. */
public final int ANY = 1;
- /** This task requires network connectivity that is unmetered. */
+ /** This job requires network connectivity that is unmetered. */
public final int UNMETERED = 2;
}
/**
- * Amount of backoff a task has initially by default, in milliseconds.
+ * Amount of backoff a job has initially by default, in milliseconds.
* @hide.
*/
public static final long DEFAULT_INITIAL_BACKOFF_MILLIS = 5000L;
@@ -63,7 +63,7 @@ public class Task implements Parcelable {
public final int EXPONENTIAL = 1;
}
- private final int taskId;
+ private final int jobId;
// TODO: Change this to use PersistableBundle when that lands in master.
private final PersistableBundle extras;
private final ComponentName service;
@@ -80,10 +80,10 @@ public class Task implements Parcelable {
private final int backoffPolicy;
/**
- * Unique task id associated with this class. This is assigned to your task by the scheduler.
+ * Unique job id associated with this class. This is assigned to your job by the scheduler.
*/
public int getId() {
- return taskId;
+ return jobId;
}
/**
@@ -94,43 +94,43 @@ public class Task implements Parcelable {
}
/**
- * Name of the service endpoint that will be called back into by the TaskManager.
+ * Name of the service endpoint that will be called back into by the JobScheduler.
*/
public ComponentName getService() {
return service;
}
/**
- * Whether this task needs the device to be plugged in.
+ * Whether this job needs the device to be plugged in.
*/
public boolean isRequireCharging() {
return requireCharging;
}
/**
- * Whether this task needs the device to be in an Idle maintenance window.
+ * Whether this job needs the device to be in an Idle maintenance window.
*/
public boolean isRequireDeviceIdle() {
return requireDeviceIdle;
}
/**
- * See {@link android.app.task.Task.NetworkType} for a description of this value.
+ * See {@link android.app.job.JobInfo.NetworkType} for a description of this value.
*/
public int getNetworkCapabilities() {
return networkCapabilities;
}
/**
- * Set for a task that does not recur periodically, to specify a delay after which the task
- * will be eligible for execution. This value is not set if the task recurs periodically.
+ * Set for a job that does not recur periodically, to specify a delay after which the job
+ * will be eligible for execution. This value is not set if the job recurs periodically.
*/
public long getMinLatencyMillis() {
return minLatencyMillis;
}
/**
- * See {@link Builder#setOverrideDeadline(long)}. This value is not set if the task recurs
+ * See {@link Builder#setOverrideDeadline(long)}. This value is not set if the job recurs
* periodically.
*/
public long getMaxExecutionDelayMillis() {
@@ -138,23 +138,23 @@ public class Task implements Parcelable {
}
/**
- * Track whether this task will repeat with a given period.
+ * Track whether this job will repeat with a given period.
*/
public boolean isPeriodic() {
return isPeriodic;
}
/**
- * Set to the interval between occurrences of this task. This value is <b>not</b> set if the
- * task does not recur periodically.
+ * Set to the interval between occurrences of this job. This value is <b>not</b> set if the
+ * job does not recur periodically.
*/
public long getIntervalMillis() {
return intervalMillis;
}
/**
- * The amount of time the TaskManager will wait before rescheduling a failed task. This value
- * will be increased depending on the backoff policy specified at task creation time. Defaults
+ * The amount of time the JobScheduler will wait before rescheduling a failed job. This value
+ * will be increased depending on the backoff policy specified at job creation time. Defaults
* to 5 seconds.
*/
public long getInitialBackoffMillis() {
@@ -162,7 +162,7 @@ public class Task implements Parcelable {
}
/**
- * See {@link android.app.task.Task.BackoffPolicy} for an explanation of the values this field
+ * See {@link android.app.job.JobInfo.BackoffPolicy} for an explanation of the values this field
* can take. This defaults to exponential.
*/
public int getBackoffPolicy() {
@@ -187,8 +187,8 @@ public class Task implements Parcelable {
return hasLateConstraint;
}
- private Task(Parcel in) {
- taskId = in.readInt();
+ private JobInfo(Parcel in) {
+ jobId = in.readInt();
extras = in.readPersistableBundle();
service = in.readParcelable(null);
requireCharging = in.readInt() == 1;
@@ -204,10 +204,10 @@ public class Task implements Parcelable {
hasLateConstraint = in.readInt() == 1;
}
- private Task(Task.Builder b) {
- taskId = b.mTaskId;
+ private JobInfo(JobInfo.Builder b) {
+ jobId = b.mJobId;
extras = b.mExtras;
- service = b.mTaskService;
+ service = b.mJobService;
requireCharging = b.mRequiresCharging;
requireDeviceIdle = b.mRequiresDeviceIdle;
networkCapabilities = b.mNetworkCapabilities;
@@ -228,7 +228,7 @@ public class Task implements Parcelable {
@Override
public void writeToParcel(Parcel out, int flags) {
- out.writeInt(taskId);
+ out.writeInt(jobId);
out.writePersistableBundle(extras);
out.writeParcelable(service, flags);
out.writeInt(requireCharging ? 1 : 0);
@@ -244,23 +244,23 @@ public class Task implements Parcelable {
out.writeInt(hasLateConstraint ? 1 : 0);
}
- public static final Creator<Task> CREATOR = new Creator<Task>() {
+ public static final Creator<JobInfo> CREATOR = new Creator<JobInfo>() {
@Override
- public Task createFromParcel(Parcel in) {
- return new Task(in);
+ public JobInfo createFromParcel(Parcel in) {
+ return new JobInfo(in);
}
@Override
- public Task[] newArray(int size) {
- return new Task[size];
+ public JobInfo[] newArray(int size) {
+ return new JobInfo[size];
}
};
- /** Builder class for constructing {@link Task} objects. */
+ /** Builder class for constructing {@link JobInfo} objects. */
public static final class Builder {
- private int mTaskId;
+ private int mJobId;
private PersistableBundle mExtras = PersistableBundle.EMPTY;
- private ComponentName mTaskService;
+ private ComponentName mJobService;
// Requirements.
private boolean mRequiresCharging;
private boolean mRequiresDeviceIdle;
@@ -280,15 +280,15 @@ public class Task implements Parcelable {
private boolean mBackoffPolicySet = false;
/**
- * @param taskId Application-provided id for this task. Subsequent calls to cancel, or
- * tasks created with the same taskId, will update the pre-existing task with
+ * @param jobId Application-provided id for this job. Subsequent calls to cancel, or
+ * jobs created with the same jobId, will update the pre-existing job with
* the same id.
- * @param taskService The endpoint that you implement that will receive the callback from the
- * TaskManager.
+ * @param jobService The endpoint that you implement that will receive the callback from the
+ * JobScheduler.
*/
- public Builder(int taskId, ComponentName taskService) {
- mTaskService = taskService;
- mTaskId = taskId;
+ public Builder(int jobId, ComponentName jobService) {
+ mJobService = jobService;
+ mJobId = jobId;
}
/**
@@ -302,10 +302,10 @@ public class Task implements Parcelable {
/**
* Set some description of the kind of network capabilities you would like to have. This
- * will be a parameter defined in {@link android.app.task.Task.NetworkType}.
+ * will be a parameter defined in {@link android.app.job.JobInfo.NetworkType}.
* Not calling this function means the network is not necessary.
* Bear in mind that calling this function defines network as a strict requirement for your
- * task if the network requested is not available your task will never run. See
+ * job if the network requested is not available your job will never run. See
* {@link #setOverrideDeadline(long)} to change this behaviour.
*/
public Builder setRequiredNetworkCapabilities(int networkCapabilities) {
@@ -313,10 +313,10 @@ public class Task implements Parcelable {
return this;
}
- /*
- * Specify that to run this task, the device needs to be plugged in. This defaults to
+ /**
+ * Specify that to run this job, the device needs to be plugged in. This defaults to
* false.
- * @param requireCharging Whether or not the device is plugged in.
+ * @param requiresCharging Whether or not the device is plugged in.
*/
public Builder setRequiresCharging(boolean requiresCharging) {
mRequiresCharging = requiresCharging;
@@ -324,11 +324,11 @@ public class Task implements Parcelable {
}
/**
- * Specify that to run, the task needs the device to be in idle mode. This defaults to
+ * Specify that to run, the job needs the device to be in idle mode. This defaults to
* false.
* <p>Idle mode is a loose definition provided by the system, which means that the device
* is not in use, and has not been in use for some time. As such, it is a good time to
- * perform resource heavy tasks. Bear in mind that battery usage will still be attributed
+ * perform resource heavy jobs. Bear in mind that battery usage will still be attributed
* to your application, and surfaced to the user in battery stats.</p>
* @param requiresDeviceIdle Whether or not the device need be within an idle maintenance
* window.
@@ -339,17 +339,17 @@ public class Task implements Parcelable {
}
/**
- * Specify that this task should recur with the provided interval, not more than once per
- * period. You have no control over when within this interval this task will be executed,
+ * Specify that this job should recur with the provided interval, not more than once per
+ * period. You have no control over when within this interval this job will be executed,
* only the guarantee that it will be executed at most once within this interval.
- * A periodic task will be repeated until the phone is turned off, however it will only be
+ * A periodic job will be repeated until the phone is turned off, however it will only be
* persisted beyond boot if the client app has declared the
* {@link android.Manifest.permission#RECEIVE_BOOT_COMPLETED} permission. You can schedule
- * periodic tasks without this permission, they simply will cease to exist after the phone
+ * periodic jobs without this permission, they simply will cease to exist after the phone
* restarts.
* Setting this function on the builder with {@link #setMinimumLatency(long)} or
* {@link #setOverrideDeadline(long)} will result in an error.
- * @param intervalMillis Millisecond interval for which this task will repeat.
+ * @param intervalMillis Millisecond interval for which this job will repeat.
*/
public Builder setPeriodic(long intervalMillis) {
mIsPeriodic = true;
@@ -359,11 +359,11 @@ public class Task implements Parcelable {
}
/**
- * Specify that this task should be delayed by the provided amount of time.
- * Because it doesn't make sense setting this property on a periodic task, doing so will
+ * Specify that this job should be delayed by the provided amount of time.
+ * Because it doesn't make sense setting this property on a periodic job, doing so will
* throw an {@link java.lang.IllegalArgumentException} when
- * {@link android.app.task.Task.Builder#build()} is called.
- * @param minLatencyMillis Milliseconds before which this task will not be considered for
+ * {@link android.app.job.JobInfo.Builder#build()} is called.
+ * @param minLatencyMillis Milliseconds before which this job will not be considered for
* execution.
*/
public Builder setMinimumLatency(long minLatencyMillis) {
@@ -373,11 +373,11 @@ public class Task implements Parcelable {
}
/**
- * Set deadline which is the maximum scheduling latency. The task will be run by this
+ * Set deadline which is the maximum scheduling latency. The job will be run by this
* deadline even if other requirements are not met. Because it doesn't make sense setting
- * this property on a periodic task, doing so will throw an
+ * this property on a periodic job, doing so will throw an
* {@link java.lang.IllegalArgumentException} when
- * {@link android.app.task.Task.Builder#build()} is called.
+ * {@link android.app.job.JobInfo.Builder#build()} is called.
*/
public Builder setOverrideDeadline(long maxExecutionDelayMillis) {
mMaxExecutionDelayMillis = maxExecutionDelayMillis;
@@ -389,13 +389,13 @@ public class Task implements Parcelable {
* Set up the back-off/retry policy.
* This defaults to some respectable values: {5 seconds, Exponential}. We cap back-off at
* 1hr.
- * Note that trying to set a backoff criteria for a task with
+ * Note that trying to set a backoff criteria for a job with
* {@link #setRequiresDeviceIdle(boolean)} will throw an exception when you call build().
- * This is because back-off typically does not make sense for these types of tasks. See
- * {@link android.app.task.TaskService#taskFinished(android.app.task.TaskParams, boolean)}
- * for more description of the return value for the case of a task executing while in idle
+ * This is because back-off typically does not make sense for these types of jobs. See
+ * {@link android.app.job.JobService#jobFinished(android.app.job.JobParameters, boolean)}
+ * for more description of the return value for the case of a job executing while in idle
* mode.
- * @param initialBackoffMillis Millisecond time interval to wait initially when task has
+ * @param initialBackoffMillis Millisecond time interval to wait initially when job has
* failed.
* @param backoffPolicy is one of {@link BackoffPolicy}
*/
@@ -407,25 +407,25 @@ public class Task implements Parcelable {
}
/**
- * @return The task object to hand to the TaskManager. This object is immutable.
+ * @return The job object to hand to the JobScheduler. This object is immutable.
*/
- public Task build() {
+ public JobInfo build() {
mExtras = new PersistableBundle(mExtras); // Make our own copy.
- // Check that a deadline was not set on a periodic task.
+ // Check that a deadline was not set on a periodic job.
if (mIsPeriodic && (mMaxExecutionDelayMillis != 0L)) {
throw new IllegalArgumentException("Can't call setOverrideDeadline() on a " +
- "periodic task.");
+ "periodic job.");
}
if (mIsPeriodic && (mMinLatencyMillis != 0L)) {
throw new IllegalArgumentException("Can't call setMinimumLatency() on a " +
- "periodic task");
+ "periodic job");
}
if (mBackoffPolicySet && mRequiresDeviceIdle) {
- throw new IllegalArgumentException("An idle mode task will not respect any" +
+ throw new IllegalArgumentException("An idle mode job will not respect any" +
" back-off policy, so calling setBackoffCriteria with" +
" setRequiresDeviceIdle is an error.");
}
- return new Task(this);
+ return new JobInfo(this);
}
}
diff --git a/core/java/android/app/task/TaskParams.aidl b/core/java/android/app/job/JobParameters.aidl
index 9b25855..e7551b9 100644
--- a/core/java/android/app/task/TaskParams.aidl
+++ b/core/java/android/app/job/JobParameters.aidl
@@ -14,6 +14,6 @@
* limitations under the License.
*/
-package android.app.task;
+package android.app.job;
-parcelable TaskParams; \ No newline at end of file
+parcelable JobParameters;
diff --git a/core/java/android/app/task/TaskParams.java b/core/java/android/app/job/JobParameters.java
index f4908c6..724856a 100644
--- a/core/java/android/app/task/TaskParams.java
+++ b/core/java/android/app/job/JobParameters.java
@@ -14,40 +14,42 @@
* limitations under the License
*/
-package android.app.task;
+package android.app.job;
+import android.app.job.IJobCallback;
+import android.app.job.IJobCallback.Stub;
import android.os.IBinder;
import android.os.Parcel;
import android.os.Parcelable;
import android.os.PersistableBundle;
/**
- * Contains the parameters used to configure/identify your task. You do not create this object
+ * Contains the parameters used to configure/identify your job. You do not create this object
* yourself, instead it is handed in to your application by the System.
*/
-public class TaskParams implements Parcelable {
+public class JobParameters implements Parcelable {
- private final int taskId;
+ private final int jobId;
private final PersistableBundle extras;
private final IBinder callback;
/** @hide */
- public TaskParams(int taskId, PersistableBundle extras, IBinder callback) {
- this.taskId = taskId;
+ public JobParameters(int jobId, PersistableBundle extras, IBinder callback) {
+ this.jobId = jobId;
this.extras = extras;
this.callback = callback;
}
/**
- * @return The unique id of this task, specified at creation time.
+ * @return The unique id of this job, specified at creation time.
*/
- public int getTaskId() {
- return taskId;
+ public int getJobId() {
+ return jobId;
}
/**
- * @return The extras you passed in when constructing this task with
- * {@link android.app.task.Task.Builder#setExtras(android.os.PersistableBundle)}. This will
+ * @return The extras you passed in when constructing this job with
+ * {@link android.app.job.JobInfo.Builder#setExtras(android.os.PersistableBundle)}. This will
* never be null. If you did not set any extras this will be an empty bundle.
*/
public PersistableBundle getExtras() {
@@ -55,12 +57,12 @@ public class TaskParams implements Parcelable {
}
/** @hide */
- public ITaskCallback getCallback() {
- return ITaskCallback.Stub.asInterface(callback);
+ public IJobCallback getCallback() {
+ return IJobCallback.Stub.asInterface(callback);
}
- private TaskParams(Parcel in) {
- taskId = in.readInt();
+ private JobParameters(Parcel in) {
+ jobId = in.readInt();
extras = in.readPersistableBundle();
callback = in.readStrongBinder();
}
@@ -72,20 +74,20 @@ public class TaskParams implements Parcelable {
@Override
public void writeToParcel(Parcel dest, int flags) {
- dest.writeInt(taskId);
+ dest.writeInt(jobId);
dest.writePersistableBundle(extras);
dest.writeStrongBinder(callback);
}
- public static final Creator<TaskParams> CREATOR = new Creator<TaskParams>() {
+ public static final Creator<JobParameters> CREATOR = new Creator<JobParameters>() {
@Override
- public TaskParams createFromParcel(Parcel in) {
- return new TaskParams(in);
+ public JobParameters createFromParcel(Parcel in) {
+ return new JobParameters(in);
}
@Override
- public TaskParams[] newArray(int size) {
- return new TaskParams[size];
+ public JobParameters[] newArray(int size) {
+ return new JobParameters[size];
}
};
}
diff --git a/core/java/android/app/job/JobScheduler.java b/core/java/android/app/job/JobScheduler.java
new file mode 100644
index 0000000..7fe192c
--- /dev/null
+++ b/core/java/android/app/job/JobScheduler.java
@@ -0,0 +1,72 @@
+/*
+ * Copyright (C) 2014 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License
+ */
+
+package android.app.job;
+
+import java.util.List;
+
+import android.content.Context;
+
+/**
+ * Class for scheduling various types of jobs with the scheduling framework on the device.
+ *
+ * <p>You do not
+ * instantiate this class directly; instead, retrieve it through
+ * {@link android.content.Context#getSystemService
+ * Context.getSystemService(Context.JOB_SCHEDULER_SERVICE)}.
+ */
+public abstract class JobScheduler {
+ /**
+ * Returned from {@link #schedule(JobInfo)} when an invalid parameter was supplied. This can occur
+ * if the run-time for your job is too short, or perhaps the system can't resolve the
+ * requisite {@link JobService} in your package.
+ */
+ public static final int RESULT_FAILURE = 0;
+ /**
+ * Returned from {@link #schedule(JobInfo)} if this application has made too many requests for
+ * work over too short a time.
+ */
+ // TODO: Determine if this is necessary.
+ public static final int RESULT_SUCCESS = 1;
+
+ /**
+ * @param job The job you wish scheduled. See
+ * {@link android.app.job.JobInfo.Builder JobInfo.Builder} for more detail on the sorts of jobs
+ * you can schedule.
+ * @return If >0, this int returns the jobId of the successfully scheduled job.
+ * Otherwise you have to compare the return value to the error codes defined in this class.
+ */
+ public abstract int schedule(JobInfo job);
+
+ /**
+ * Cancel a job that is pending in the JobScheduler.
+ * @param jobId unique identifier for this job. Obtain this value from the jobs returned by
+ * {@link #getAllPendingJobs()}.
+ * @return
+ */
+ public abstract void cancel(int jobId);
+
+ /**
+ * Cancel all jobs that have been registered with the JobScheduler by this package.
+ */
+ public abstract void cancelAll();
+
+ /**
+ * @return a list of all the jobs registered by this package that have not yet been executed.
+ */
+ public abstract List<JobInfo> getAllPendingJobs();
+
+}
diff --git a/core/java/android/app/task/TaskService.java b/core/java/android/app/job/JobService.java
index 8ce4484..eea0268 100644
--- a/core/java/android/app/task/TaskService.java
+++ b/core/java/android/app/job/JobService.java
@@ -14,9 +14,12 @@
* limitations under the License
*/
-package android.app.task;
+package android.app.job;
import android.app.Service;
+import android.app.job.IJobCallback;
+import android.app.job.IJobService;
+import android.app.job.IJobService.Stub;
import android.content.Intent;
import android.os.Handler;
import android.os.IBinder;
@@ -28,72 +31,72 @@ import android.util.Log;
import com.android.internal.annotations.GuardedBy;
/**
- * <p>Entry point for the callback from the {@link android.app.task.TaskManager}.</p>
+ * <p>Entry point for the callback from the {@link android.app.job.JobScheduler}.</p>
* <p>This is the base class that handles asynchronous requests that were previously scheduled. You
- * are responsible for overriding {@link TaskService#onStartTask(TaskParams)}, which is where
- * you will implement your task logic.</p>
- * <p>This service executes each incoming task on a {@link android.os.Handler} running on your
+ * are responsible for overriding {@link JobService#onStartJob(JobParameters)}, which is where
+ * you will implement your job logic.</p>
+ * <p>This service executes each incoming job on a {@link android.os.Handler} running on your
* application's main thread. This means that you <b>must</b> offload your execution logic to
* another thread/handler/{@link android.os.AsyncTask} of your choosing. Not doing so will result
- * in blocking any future callbacks from the TaskManager - specifically
- * {@link #onStopTask(android.app.task.TaskParams)}, which is meant to inform you that the
+ * in blocking any future callbacks from the JobManager - specifically
+ * {@link #onStopJob(android.app.job.JobParameters)}, which is meant to inform you that the
* scheduling requirements are no longer being met.</p>
*/
-public abstract class TaskService extends Service {
- private static final String TAG = "TaskService";
+public abstract class JobService extends Service {
+ private static final String TAG = "JobService";
/**
- * Task services must be protected with this permission:
+ * Job services must be protected with this permission:
*
* <pre class="prettyprint">
- * <service android:name="MyTaskService"
- * android:permission="android.permission.BIND_TASK_SERVICE" >
+ * <service android:name="MyJobService"
+ * android:permission="android.permission.BIND_JOB_SERVICE" >
* ...
* </service>
* </pre>
*
- * <p>If a task service is declared in the manifest but not protected with this
+ * <p>If a job service is declared in the manifest but not protected with this
* permission, that service will be ignored by the OS.
*/
public static final String PERMISSION_BIND =
- "android.permission.BIND_TASK_SERVICE";
+ "android.permission.BIND_JOB_SERVICE";
/**
* Identifier for a message that will result in a call to
- * {@link #onStartTask(android.app.task.TaskParams)}.
+ * {@link #onStartJob(android.app.job.JobParameters)}.
*/
- private final int MSG_EXECUTE_TASK = 0;
+ private final int MSG_EXECUTE_JOB = 0;
/**
- * Message that will result in a call to {@link #onStopTask(android.app.task.TaskParams)}.
+ * Message that will result in a call to {@link #onStopJob(android.app.job.JobParameters)}.
*/
- private final int MSG_STOP_TASK = 1;
+ private final int MSG_STOP_JOB = 1;
/**
- * Message that the client has completed execution of this task.
+ * Message that the client has completed execution of this job.
*/
- private final int MSG_TASK_FINISHED = 2;
+ private final int MSG_JOB_FINISHED = 2;
/** Lock object for {@link #mHandler}. */
private final Object mHandlerLock = new Object();
/**
- * Handler we post tasks to. Responsible for calling into the client logic, and handling the
+ * Handler we post jobs to. Responsible for calling into the client logic, and handling the
* callback to the system.
*/
@GuardedBy("mHandlerLock")
- TaskHandler mHandler;
+ JobHandler mHandler;
/** Binder for this service. */
- ITaskService mBinder = new ITaskService.Stub() {
+ IJobService mBinder = new IJobService.Stub() {
@Override
- public void startTask(TaskParams taskParams) {
+ public void startJob(JobParameters jobParams) {
ensureHandler();
- Message m = Message.obtain(mHandler, MSG_EXECUTE_TASK, taskParams);
+ Message m = Message.obtain(mHandler, MSG_EXECUTE_JOB, jobParams);
m.sendToTarget();
}
@Override
- public void stopTask(TaskParams taskParams) {
+ public void stopJob(JobParameters jobParams) {
ensureHandler();
- Message m = Message.obtain(mHandler, MSG_STOP_TASK, taskParams);
+ Message m = Message.obtain(mHandler, MSG_STOP_JOB, jobParams);
m.sendToTarget();
}
};
@@ -102,7 +105,7 @@ public abstract class TaskService extends Service {
void ensureHandler() {
synchronized (mHandlerLock) {
if (mHandler == null) {
- mHandler = new TaskHandler(getMainLooper());
+ mHandler = new JobHandler(getMainLooper());
}
}
}
@@ -112,45 +115,45 @@ public abstract class TaskService extends Service {
* (app-specified) mechanism.
* @hide
*/
- class TaskHandler extends Handler {
- TaskHandler(Looper looper) {
+ class JobHandler extends Handler {
+ JobHandler(Looper looper) {
super(looper);
}
@Override
public void handleMessage(Message msg) {
- final TaskParams params = (TaskParams) msg.obj;
+ final JobParameters params = (JobParameters) msg.obj;
switch (msg.what) {
- case MSG_EXECUTE_TASK:
+ case MSG_EXECUTE_JOB:
try {
- boolean workOngoing = TaskService.this.onStartTask(params);
+ boolean workOngoing = JobService.this.onStartJob(params);
ackStartMessage(params, workOngoing);
} catch (Exception e) {
- Log.e(TAG, "Error while executing task: " + params.getTaskId());
+ Log.e(TAG, "Error while executing job: " + params.getJobId());
throw new RuntimeException(e);
}
break;
- case MSG_STOP_TASK:
+ case MSG_STOP_JOB:
try {
- boolean ret = TaskService.this.onStopTask(params);
+ boolean ret = JobService.this.onStopJob(params);
ackStopMessage(params, ret);
} catch (Exception e) {
- Log.e(TAG, "Application unable to handle onStopTask.", e);
+ Log.e(TAG, "Application unable to handle onStopJob.", e);
throw new RuntimeException(e);
}
break;
- case MSG_TASK_FINISHED:
+ case MSG_JOB_FINISHED:
final boolean needsReschedule = (msg.arg2 == 1);
- ITaskCallback callback = params.getCallback();
+ IJobCallback callback = params.getCallback();
if (callback != null) {
try {
- callback.taskFinished(params.getTaskId(), needsReschedule);
+ callback.jobFinished(params.getJobId(), needsReschedule);
} catch (RemoteException e) {
- Log.e(TAG, "Error reporting task finish to system: binder has gone" +
+ Log.e(TAG, "Error reporting job finish to system: binder has gone" +
"away.");
}
} else {
- Log.e(TAG, "finishTask() called for a nonexistent task id.");
+ Log.e(TAG, "finishJob() called for a nonexistent job id.");
}
break;
default:
@@ -159,34 +162,34 @@ public abstract class TaskService extends Service {
}
}
- private void ackStartMessage(TaskParams params, boolean workOngoing) {
- final ITaskCallback callback = params.getCallback();
- final int taskId = params.getTaskId();
+ private void ackStartMessage(JobParameters params, boolean workOngoing) {
+ final IJobCallback callback = params.getCallback();
+ final int jobId = params.getJobId();
if (callback != null) {
try {
- callback.acknowledgeStartMessage(taskId, workOngoing);
+ callback.acknowledgeStartMessage(jobId, workOngoing);
} catch(RemoteException e) {
- Log.e(TAG, "System unreachable for starting task.");
+ Log.e(TAG, "System unreachable for starting job.");
}
} else {
if (Log.isLoggable(TAG, Log.DEBUG)) {
- Log.d(TAG, "Attempting to ack a task that has already been processed.");
+ Log.d(TAG, "Attempting to ack a job that has already been processed.");
}
}
}
- private void ackStopMessage(TaskParams params, boolean reschedule) {
- final ITaskCallback callback = params.getCallback();
- final int taskId = params.getTaskId();
+ private void ackStopMessage(JobParameters params, boolean reschedule) {
+ final IJobCallback callback = params.getCallback();
+ final int jobId = params.getJobId();
if (callback != null) {
try {
- callback.acknowledgeStopMessage(taskId, reschedule);
+ callback.acknowledgeStopMessage(jobId, reschedule);
} catch(RemoteException e) {
- Log.e(TAG, "System unreachable for stopping task.");
+ Log.e(TAG, "System unreachable for stopping job.");
}
} else {
if (Log.isLoggable(TAG, Log.DEBUG)) {
- Log.d(TAG, "Attempting to ack a task that has already been processed.");
+ Log.d(TAG, "Attempting to ack a job that has already been processed.");
}
}
}
@@ -198,59 +201,59 @@ public abstract class TaskService extends Service {
}
/**
- * Override this method with the callback logic for your task. Any such logic needs to be
+ * Override this method with the callback logic for your job. Any such logic needs to be
* performed on a separate thread, as this function is executed on your application's main
* thread.
*
- * @param params Parameters specifying info about this task, including the extras bundle you
- * optionally provided at task-creation time.
+ * @param params Parameters specifying info about this job, including the extras bundle you
+ * optionally provided at job-creation time.
* @return True if your service needs to process the work (on a separate thread). False if
- * there's no more work to be done for this task.
+ * there's no more work to be done for this job.
*/
- public abstract boolean onStartTask(TaskParams params);
+ public abstract boolean onStartJob(JobParameters params);
/**
- * This method is called if the system has determined that you must stop execution of your task
- * even before you've had a chance to call {@link #taskFinished(TaskParams, boolean)}.
+ * This method is called if the system has determined that you must stop execution of your job
+ * even before you've had a chance to call {@link #jobFinished(JobParameters, boolean)}.
*
* <p>This will happen if the requirements specified at schedule time are no longer met. For
* example you may have requested WiFi with
- * {@link android.app.task.Task.Builder#setRequiredNetworkCapabilities(int)}, yet while your
- * task was executing the user toggled WiFi. Another example is if you had specified
- * {@link android.app.task.Task.Builder#setRequiresDeviceIdle(boolean)}, and the phone left its
+ * {@link android.app.job.JobInfo.Builder#setRequiredNetworkCapabilities(int)}, yet while your
+ * job was executing the user toggled WiFi. Another example is if you had specified
+ * {@link android.app.job.JobInfo.Builder#setRequiresDeviceIdle(boolean)}, and the phone left its
* idle maintenance window. You are solely responsible for the behaviour of your application
* upon receipt of this message; your app will likely start to misbehave if you ignore it. One
* immediate repercussion is that the system will cease holding a wakelock for you.</p>
*
- * @param params Parameters specifying info about this task.
- * @return True to indicate to the TaskManager whether you'd like to reschedule this task based
- * on the retry criteria provided at task creation-time. False to drop the task. Regardless of
- * the value returned, your task must stop executing.
+ * @param params Parameters specifying info about this job.
+ * @return True to indicate to the JobManager whether you'd like to reschedule this job based
+ * on the retry criteria provided at job creation-time. False to drop the job. Regardless of
+ * the value returned, your job must stop executing.
*/
- public abstract boolean onStopTask(TaskParams params);
+ public abstract boolean onStopJob(JobParameters params);
/**
- * Callback to inform the TaskManager you've finished executing. This can be called from any
+ * Callback to inform the JobManager you've finished executing. This can be called from any
* thread, as it will ultimately be run on your application's main thread. When the system
* receives this message it will release the wakelock being held.
* <p>
* You can specify post-execution behaviour to the scheduler here with
- * <code>needsReschedule </code>. This will apply a back-off timer to your task based on
+ * <code>needsReschedule </code>. This will apply a back-off timer to your job based on
* the default, or what was set with
- * {@link android.app.task.Task.Builder#setBackoffCriteria(long, int)}. The original
- * requirements are always honoured even for a backed-off task. Note that a task running in
- * idle mode will not be backed-off. Instead what will happen is the task will be re-added
+ * {@link android.app.job.JobInfo.Builder#setBackoffCriteria(long, int)}. The original
+ * requirements are always honoured even for a backed-off job. Note that a job running in
+ * idle mode will not be backed-off. Instead what will happen is the job will be re-added
* to the queue and re-executed within a future idle maintenance window.
* </p>
*
- * @param params Parameters specifying system-provided info about this task, this was given to
- * your application in {@link #onStartTask(TaskParams)}.
- * @param needsReschedule True if this task is complete, false if you want the TaskManager to
+ * @param params Parameters specifying system-provided info about this job, this was given to
+ * your application in {@link #onStartJob(JobParameters)}.
+ * @param needsReschedule True if this job is complete, false if you want the JobManager to
* reschedule you.
*/
- public final void taskFinished(TaskParams params, boolean needsReschedule) {
+ public final void jobFinished(JobParameters params, boolean needsReschedule) {
ensureHandler();
- Message m = Message.obtain(mHandler, MSG_TASK_FINISHED, params);
+ Message m = Message.obtain(mHandler, MSG_JOB_FINISHED, params);
m.arg2 = needsReschedule ? 1 : 0;
m.sendToTarget();
}
diff --git a/core/java/android/app/task/TaskManager.java b/core/java/android/app/task/TaskManager.java
deleted file mode 100644
index 00f57da..0000000
--- a/core/java/android/app/task/TaskManager.java
+++ /dev/null
@@ -1,72 +0,0 @@
-/*
- * Copyright (C) 2014 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License
- */
-
-package android.app.task;
-
-import java.util.List;
-
-import android.content.Context;
-
-/**
- * Class for scheduling various types of tasks with the scheduling framework on the device.
- *
- * <p>You do not
- * instantiate this class directly; instead, retrieve it through
- * {@link android.content.Context#getSystemService
- * Context.getSystemService(Context.TASK_SERVICE)}.
- */
-public abstract class TaskManager {
- /*
- * Returned from {@link #schedule(Task)} when an invalid parameter was supplied. This can occur
- * if the run-time for your task is too short, or perhaps the system can't resolve the
- * requisite {@link TaskService} in your package.
- */
- public static final int RESULT_FAILURE = 0;
- /**
- * Returned from {@link #schedule(Task)} if this application has made too many requests for
- * work over too short a time.
- */
- // TODO: Determine if this is necessary.
- public static final int RESULT_SUCCESS = 1;
-
- /**
- * @param task The task you wish scheduled. See
- * {@link android.app.task.Task.Builder Task.Builder} for more detail on the sorts of tasks
- * you can schedule.
- * @return If >0, this int returns the taskId of the successfully scheduled task.
- * Otherwise you have to compare the return value to the error codes defined in this class.
- */
- public abstract int schedule(Task task);
-
- /**
- * Cancel a task that is pending in the TaskManager.
- * @param taskId unique identifier for this task. Obtain this value from the tasks returned by
- * {@link #getAllPendingTasks()}.
- * @return
- */
- public abstract void cancel(int taskId);
-
- /**
- * Cancel all tasks that have been registered with the TaskManager by this package.
- */
- public abstract void cancelAll();
-
- /**
- * @return a list of all the tasks registered by this package that have not yet been executed.
- */
- public abstract List<Task> getAllPendingTasks();
-
-}
diff --git a/core/java/android/content/Context.java b/core/java/android/content/Context.java
index 9fe9bce..cdcfd2e 100644
--- a/core/java/android/content/Context.java
+++ b/core/java/android/content/Context.java
@@ -2059,7 +2059,7 @@ public abstract class Context {
PRINT_SERVICE,
MEDIA_SESSION_SERVICE,
BATTERY_SERVICE,
- TASK_SERVICE,
+ JOB_SCHEDULER_SERVICE,
})
@Retention(RetentionPolicy.SOURCE)
public @interface ServiceName {}
@@ -2116,8 +2116,8 @@ public abstract class Context {
* <dd> A {@link android.app.DownloadManager} for requesting HTTP downloads
* <dt> {@link #BATTERY_SERVICE} ("batterymanager")
* <dd> A {@link android.os.BatteryManager} for managing battery state
- * <dt> {@link #TASK_SERVICE} ("taskmanager")
- * <dd> A {@link android.app.task.TaskManager} for managing scheduled tasks
+ * <dt> {@link #JOB_SCHEDULER_SERVICE} ("taskmanager")
+ * <dd> A {@link android.app.job.JobScheduler} for managing scheduled tasks
* </dl>
*
* <p>Note: System services obtained via this API may be closely associated with
@@ -2171,8 +2171,8 @@ public abstract class Context {
* @see android.app.DownloadManager
* @see #BATTERY_SERVICE
* @see android.os.BatteryManager
- * @see #TASK_SERVICE
- * @see android.app.task.TaskManager
+ * @see #JOB_SCHEDULER_SERVICE
+ * @see android.app.job.JobScheduler
*/
public abstract Object getSystemService(@ServiceName @NonNull String name);
@@ -2761,12 +2761,12 @@ public abstract class Context {
/**
* Use with {@link #getSystemService} to retrieve a {@link
- * android.app.task.TaskManager} instance for managing occasional
+ * android.app.job.JobScheduler} instance for managing occasional
* background tasks.
* @see #getSystemService
- * @see android.app.task.TaskManager
+ * @see android.app.job.JobScheduler
*/
- public static final String TASK_SERVICE = "task";
+ public static final String JOB_SCHEDULER_SERVICE = "jobscheduler";
/**
* Determine whether the given permission is allowed for a particular