blob: 7ee39f5cd93997c34a0fe37a1002d10415db22f1 [file] [log] [blame]
Christopher Tate7060b042014-06-09 19:50:00 -07001/*
2 * Copyright (C) 2014 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License
15 */
16
17package android.app.job;
18
19import android.app.job.IJobCallback;
Christopher Tate7060b042014-06-09 19:50:00 -070020import android.os.IBinder;
21import android.os.Parcel;
22import android.os.Parcelable;
23import android.os.PersistableBundle;
24
25/**
26 * Contains the parameters used to configure/identify your job. You do not create this object
27 * yourself, instead it is handed in to your application by the System.
28 */
29public class JobParameters implements Parcelable {
30
31 private final int jobId;
32 private final PersistableBundle extras;
33 private final IBinder callback;
Matthew Williams03a4da62014-09-10 17:32:18 -070034 private final boolean overrideDeadlineExpired;
Christopher Tate7060b042014-06-09 19:50:00 -070035
36 /** @hide */
Matthew Williams03a4da62014-09-10 17:32:18 -070037 public JobParameters(IBinder callback, int jobId, PersistableBundle extras,
38 boolean overrideDeadlineExpired) {
Christopher Tate7060b042014-06-09 19:50:00 -070039 this.jobId = jobId;
40 this.extras = extras;
41 this.callback = callback;
Matthew Williams03a4da62014-09-10 17:32:18 -070042 this.overrideDeadlineExpired = overrideDeadlineExpired;
Christopher Tate7060b042014-06-09 19:50:00 -070043 }
44
45 /**
46 * @return The unique id of this job, specified at creation time.
47 */
48 public int getJobId() {
49 return jobId;
50 }
51
52 /**
53 * @return The extras you passed in when constructing this job with
54 * {@link android.app.job.JobInfo.Builder#setExtras(android.os.PersistableBundle)}. This will
55 * never be null. If you did not set any extras this will be an empty bundle.
56 */
57 public PersistableBundle getExtras() {
58 return extras;
59 }
60
Matthew Williams03a4da62014-09-10 17:32:18 -070061 /**
62 * For jobs with {@link android.app.job.JobInfo.Builder#setOverrideDeadline(long)} set, this
63 * provides an easy way to tell whether the job is being executed due to the deadline
64 * expiring. Note: If the job is running because its deadline expired, it implies that its
65 * constraints will not be met.
66 */
67 public boolean isOverrideDeadlineExpired() {
68 return overrideDeadlineExpired;
69 }
70
Christopher Tate7060b042014-06-09 19:50:00 -070071 /** @hide */
72 public IJobCallback getCallback() {
73 return IJobCallback.Stub.asInterface(callback);
74 }
75
76 private JobParameters(Parcel in) {
77 jobId = in.readInt();
78 extras = in.readPersistableBundle();
79 callback = in.readStrongBinder();
Matthew Williams03a4da62014-09-10 17:32:18 -070080 overrideDeadlineExpired = in.readInt() == 1;
Christopher Tate7060b042014-06-09 19:50:00 -070081 }
82
83 @Override
84 public int describeContents() {
85 return 0;
86 }
87
88 @Override
89 public void writeToParcel(Parcel dest, int flags) {
90 dest.writeInt(jobId);
91 dest.writePersistableBundle(extras);
92 dest.writeStrongBinder(callback);
Matthew Williams03a4da62014-09-10 17:32:18 -070093 dest.writeInt(overrideDeadlineExpired ? 1 : 0);
Christopher Tate7060b042014-06-09 19:50:00 -070094 }
95
96 public static final Creator<JobParameters> CREATOR = new Creator<JobParameters>() {
97 @Override
98 public JobParameters createFromParcel(Parcel in) {
99 return new JobParameters(in);
100 }
101
102 @Override
103 public JobParameters[] newArray(int size) {
104 return new JobParameters[size];
105 }
106 };
107}