1/*
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;
20import android.app.job.IJobCallback.Stub;
21import android.os.IBinder;
22import android.os.Parcel;
23import android.os.Parcelable;
24import android.os.PersistableBundle;
25
26/**
27 * Contains the parameters used to configure/identify your job. You do not create this object
28 * yourself, instead it is handed in to your application by the System.
29 */
30public class JobParameters implements Parcelable {
31
32    private final int jobId;
33    private final PersistableBundle extras;
34    private final IBinder callback;
35    private final boolean overrideDeadlineExpired;
36
37    /** @hide */
38    public JobParameters(IBinder callback, int jobId, PersistableBundle extras,
39                         boolean overrideDeadlineExpired) {
40        this.jobId = jobId;
41        this.extras = extras;
42        this.callback = callback;
43        this.overrideDeadlineExpired = overrideDeadlineExpired;
44    }
45
46    /**
47     * @return The unique id of this job, specified at creation time.
48     */
49    public int getJobId() {
50        return jobId;
51    }
52
53    /**
54     * @return The extras you passed in when constructing this job with
55     * {@link android.app.job.JobInfo.Builder#setExtras(android.os.PersistableBundle)}. This will
56     * never be null. If you did not set any extras this will be an empty bundle.
57     */
58    public PersistableBundle getExtras() {
59        return extras;
60    }
61
62    /**
63     * For jobs with {@link android.app.job.JobInfo.Builder#setOverrideDeadline(long)} set, this
64     * provides an easy way to tell whether the job is being executed due to the deadline
65     * expiring. Note: If the job is running because its deadline expired, it implies that its
66     * constraints will not be met.
67     */
68    public boolean isOverrideDeadlineExpired() {
69        return overrideDeadlineExpired;
70    }
71
72    /** @hide */
73    public IJobCallback getCallback() {
74        return IJobCallback.Stub.asInterface(callback);
75    }
76
77    private JobParameters(Parcel in) {
78        jobId = in.readInt();
79        extras = in.readPersistableBundle();
80        callback = in.readStrongBinder();
81        overrideDeadlineExpired = in.readInt() == 1;
82    }
83
84    @Override
85    public int describeContents() {
86        return 0;
87    }
88
89    @Override
90    public void writeToParcel(Parcel dest, int flags) {
91        dest.writeInt(jobId);
92        dest.writePersistableBundle(extras);
93        dest.writeStrongBinder(callback);
94        dest.writeInt(overrideDeadlineExpired ? 1 : 0);
95    }
96
97    public static final Creator<JobParameters> CREATOR = new Creator<JobParameters>() {
98        @Override
99        public JobParameters createFromParcel(Parcel in) {
100            return new JobParameters(in);
101        }
102
103        @Override
104        public JobParameters[] newArray(int size) {
105            return new JobParameters[size];
106        }
107    };
108}
109