Home | History | Annotate | Download | only in job
      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 
     17 package android.app.job;
     18 
     19 import android.app.job.IJobCallback;
     20 import android.os.IBinder;
     21 import android.os.Parcel;
     22 import android.os.Parcelable;
     23 import 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  */
     29 public class JobParameters implements Parcelable {
     30 
     31     private final int jobId;
     32     private final PersistableBundle extras;
     33     private final IBinder callback;
     34     private final boolean overrideDeadlineExpired;
     35 
     36     /** @hide */
     37     public JobParameters(IBinder callback, int jobId, PersistableBundle extras,
     38                          boolean overrideDeadlineExpired) {
     39         this.jobId = jobId;
     40         this.extras = extras;
     41         this.callback = callback;
     42         this.overrideDeadlineExpired = overrideDeadlineExpired;
     43     }
     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 
     61     /**
     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 
     71     /** @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();
     80         overrideDeadlineExpired = in.readInt() == 1;
     81     }
     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);
     93         dest.writeInt(overrideDeadlineExpired ? 1 : 0);
     94     }
     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 }
    108