JobParameters.java revision 03a4da6e8e92b19c1345016c06694cb3aabbfc27
16e31c5c82bc5c9bddf9c01d254067ea5bebbd96bMatthew Williams/* 26e31c5c82bc5c9bddf9c01d254067ea5bebbd96bMatthew Williams * Copyright (C) 2014 The Android Open Source Project 36e31c5c82bc5c9bddf9c01d254067ea5bebbd96bMatthew Williams * 46e31c5c82bc5c9bddf9c01d254067ea5bebbd96bMatthew Williams * Licensed under the Apache License, Version 2.0 (the "License"); 56e31c5c82bc5c9bddf9c01d254067ea5bebbd96bMatthew Williams * you may not use this file except in compliance with the License. 66e31c5c82bc5c9bddf9c01d254067ea5bebbd96bMatthew Williams * You may obtain a copy of the License at 76e31c5c82bc5c9bddf9c01d254067ea5bebbd96bMatthew Williams * 86e31c5c82bc5c9bddf9c01d254067ea5bebbd96bMatthew Williams * http://www.apache.org/licenses/LICENSE-2.0 96e31c5c82bc5c9bddf9c01d254067ea5bebbd96bMatthew Williams * 106e31c5c82bc5c9bddf9c01d254067ea5bebbd96bMatthew Williams * Unless required by applicable law or agreed to in writing, software 116e31c5c82bc5c9bddf9c01d254067ea5bebbd96bMatthew Williams * distributed under the License is distributed on an "AS IS" BASIS, 126e31c5c82bc5c9bddf9c01d254067ea5bebbd96bMatthew Williams * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 136e31c5c82bc5c9bddf9c01d254067ea5bebbd96bMatthew Williams * See the License for the specific language governing permissions and 146e31c5c82bc5c9bddf9c01d254067ea5bebbd96bMatthew Williams * limitations under the License 156e31c5c82bc5c9bddf9c01d254067ea5bebbd96bMatthew Williams */ 166e31c5c82bc5c9bddf9c01d254067ea5bebbd96bMatthew Williams 177060b04f6d92351b67222e636ab378a0273bf3e7Christopher Tatepackage android.app.job; 186e31c5c82bc5c9bddf9c01d254067ea5bebbd96bMatthew Williams 197060b04f6d92351b67222e636ab378a0273bf3e7Christopher Tateimport android.app.job.IJobCallback; 207060b04f6d92351b67222e636ab378a0273bf3e7Christopher Tateimport android.app.job.IJobCallback.Stub; 216e31c5c82bc5c9bddf9c01d254067ea5bebbd96bMatthew Williamsimport android.os.IBinder; 226e31c5c82bc5c9bddf9c01d254067ea5bebbd96bMatthew Williamsimport android.os.Parcel; 236e31c5c82bc5c9bddf9c01d254067ea5bebbd96bMatthew Williamsimport android.os.Parcelable; 243d86fd2bb9db6067c49634bc4c6cdb4d5235ad36Matthew Williamsimport android.os.PersistableBundle; 256e31c5c82bc5c9bddf9c01d254067ea5bebbd96bMatthew Williams 266e31c5c82bc5c9bddf9c01d254067ea5bebbd96bMatthew Williams/** 277060b04f6d92351b67222e636ab378a0273bf3e7Christopher Tate * Contains the parameters used to configure/identify your job. You do not create this object 286e31c5c82bc5c9bddf9c01d254067ea5bebbd96bMatthew Williams * yourself, instead it is handed in to your application by the System. 296e31c5c82bc5c9bddf9c01d254067ea5bebbd96bMatthew Williams */ 307060b04f6d92351b67222e636ab378a0273bf3e7Christopher Tatepublic class JobParameters implements Parcelable { 316e31c5c82bc5c9bddf9c01d254067ea5bebbd96bMatthew Williams 327060b04f6d92351b67222e636ab378a0273bf3e7Christopher Tate private final int jobId; 333d86fd2bb9db6067c49634bc4c6cdb4d5235ad36Matthew Williams private final PersistableBundle extras; 346de79e2b17fa0796ea4d39fd9555b563c484248dMatthew Williams private final IBinder callback; 3503a4da6e8e92b19c1345016c06694cb3aabbfc27Matthew Williams private final boolean overrideDeadlineExpired; 366de79e2b17fa0796ea4d39fd9555b563c484248dMatthew Williams 376de79e2b17fa0796ea4d39fd9555b563c484248dMatthew Williams /** @hide */ 3803a4da6e8e92b19c1345016c06694cb3aabbfc27Matthew Williams public JobParameters(IBinder callback, int jobId, PersistableBundle extras, 3903a4da6e8e92b19c1345016c06694cb3aabbfc27Matthew Williams boolean overrideDeadlineExpired) { 407060b04f6d92351b67222e636ab378a0273bf3e7Christopher Tate this.jobId = jobId; 416de79e2b17fa0796ea4d39fd9555b563c484248dMatthew Williams this.extras = extras; 426de79e2b17fa0796ea4d39fd9555b563c484248dMatthew Williams this.callback = callback; 4303a4da6e8e92b19c1345016c06694cb3aabbfc27Matthew Williams this.overrideDeadlineExpired = overrideDeadlineExpired; 446de79e2b17fa0796ea4d39fd9555b563c484248dMatthew Williams } 456e31c5c82bc5c9bddf9c01d254067ea5bebbd96bMatthew Williams 466e31c5c82bc5c9bddf9c01d254067ea5bebbd96bMatthew Williams /** 477060b04f6d92351b67222e636ab378a0273bf3e7Christopher Tate * @return The unique id of this job, specified at creation time. 486e31c5c82bc5c9bddf9c01d254067ea5bebbd96bMatthew Williams */ 497060b04f6d92351b67222e636ab378a0273bf3e7Christopher Tate public int getJobId() { 507060b04f6d92351b67222e636ab378a0273bf3e7Christopher Tate return jobId; 516e31c5c82bc5c9bddf9c01d254067ea5bebbd96bMatthew Williams } 526e31c5c82bc5c9bddf9c01d254067ea5bebbd96bMatthew Williams 536e31c5c82bc5c9bddf9c01d254067ea5bebbd96bMatthew Williams /** 547060b04f6d92351b67222e636ab378a0273bf3e7Christopher Tate * @return The extras you passed in when constructing this job with 557060b04f6d92351b67222e636ab378a0273bf3e7Christopher Tate * {@link android.app.job.JobInfo.Builder#setExtras(android.os.PersistableBundle)}. This will 566e31c5c82bc5c9bddf9c01d254067ea5bebbd96bMatthew Williams * never be null. If you did not set any extras this will be an empty bundle. 576e31c5c82bc5c9bddf9c01d254067ea5bebbd96bMatthew Williams */ 583d86fd2bb9db6067c49634bc4c6cdb4d5235ad36Matthew Williams public PersistableBundle getExtras() { 596e31c5c82bc5c9bddf9c01d254067ea5bebbd96bMatthew Williams return extras; 606e31c5c82bc5c9bddf9c01d254067ea5bebbd96bMatthew Williams } 616e31c5c82bc5c9bddf9c01d254067ea5bebbd96bMatthew Williams 6203a4da6e8e92b19c1345016c06694cb3aabbfc27Matthew Williams /** 6303a4da6e8e92b19c1345016c06694cb3aabbfc27Matthew Williams * For jobs with {@link android.app.job.JobInfo.Builder#setOverrideDeadline(long)} set, this 6403a4da6e8e92b19c1345016c06694cb3aabbfc27Matthew Williams * provides an easy way to tell whether the job is being executed due to the deadline 6503a4da6e8e92b19c1345016c06694cb3aabbfc27Matthew Williams * expiring. Note: If the job is running because its deadline expired, it implies that its 6603a4da6e8e92b19c1345016c06694cb3aabbfc27Matthew Williams * constraints will not be met. 6703a4da6e8e92b19c1345016c06694cb3aabbfc27Matthew Williams */ 6803a4da6e8e92b19c1345016c06694cb3aabbfc27Matthew Williams public boolean isOverrideDeadlineExpired() { 6903a4da6e8e92b19c1345016c06694cb3aabbfc27Matthew Williams return overrideDeadlineExpired; 7003a4da6e8e92b19c1345016c06694cb3aabbfc27Matthew Williams } 7103a4da6e8e92b19c1345016c06694cb3aabbfc27Matthew Williams 726de79e2b17fa0796ea4d39fd9555b563c484248dMatthew Williams /** @hide */ 737060b04f6d92351b67222e636ab378a0273bf3e7Christopher Tate public IJobCallback getCallback() { 747060b04f6d92351b67222e636ab378a0273bf3e7Christopher Tate return IJobCallback.Stub.asInterface(callback); 756e31c5c82bc5c9bddf9c01d254067ea5bebbd96bMatthew Williams } 766e31c5c82bc5c9bddf9c01d254067ea5bebbd96bMatthew Williams 777060b04f6d92351b67222e636ab378a0273bf3e7Christopher Tate private JobParameters(Parcel in) { 787060b04f6d92351b67222e636ab378a0273bf3e7Christopher Tate jobId = in.readInt(); 793d86fd2bb9db6067c49634bc4c6cdb4d5235ad36Matthew Williams extras = in.readPersistableBundle(); 806de79e2b17fa0796ea4d39fd9555b563c484248dMatthew Williams callback = in.readStrongBinder(); 8103a4da6e8e92b19c1345016c06694cb3aabbfc27Matthew Williams overrideDeadlineExpired = in.readInt() == 1; 826e31c5c82bc5c9bddf9c01d254067ea5bebbd96bMatthew Williams } 836e31c5c82bc5c9bddf9c01d254067ea5bebbd96bMatthew Williams 846e31c5c82bc5c9bddf9c01d254067ea5bebbd96bMatthew Williams @Override 856e31c5c82bc5c9bddf9c01d254067ea5bebbd96bMatthew Williams public int describeContents() { 866e31c5c82bc5c9bddf9c01d254067ea5bebbd96bMatthew Williams return 0; 876e31c5c82bc5c9bddf9c01d254067ea5bebbd96bMatthew Williams } 886e31c5c82bc5c9bddf9c01d254067ea5bebbd96bMatthew Williams 896e31c5c82bc5c9bddf9c01d254067ea5bebbd96bMatthew Williams @Override 906e31c5c82bc5c9bddf9c01d254067ea5bebbd96bMatthew Williams public void writeToParcel(Parcel dest, int flags) { 917060b04f6d92351b67222e636ab378a0273bf3e7Christopher Tate dest.writeInt(jobId); 923d86fd2bb9db6067c49634bc4c6cdb4d5235ad36Matthew Williams dest.writePersistableBundle(extras); 936de79e2b17fa0796ea4d39fd9555b563c484248dMatthew Williams dest.writeStrongBinder(callback); 9403a4da6e8e92b19c1345016c06694cb3aabbfc27Matthew Williams dest.writeInt(overrideDeadlineExpired ? 1 : 0); 956e31c5c82bc5c9bddf9c01d254067ea5bebbd96bMatthew Williams } 966e31c5c82bc5c9bddf9c01d254067ea5bebbd96bMatthew Williams 977060b04f6d92351b67222e636ab378a0273bf3e7Christopher Tate public static final Creator<JobParameters> CREATOR = new Creator<JobParameters>() { 986e31c5c82bc5c9bddf9c01d254067ea5bebbd96bMatthew Williams @Override 997060b04f6d92351b67222e636ab378a0273bf3e7Christopher Tate public JobParameters createFromParcel(Parcel in) { 1007060b04f6d92351b67222e636ab378a0273bf3e7Christopher Tate return new JobParameters(in); 1016e31c5c82bc5c9bddf9c01d254067ea5bebbd96bMatthew Williams } 1026e31c5c82bc5c9bddf9c01d254067ea5bebbd96bMatthew Williams 1036e31c5c82bc5c9bddf9c01d254067ea5bebbd96bMatthew Williams @Override 1047060b04f6d92351b67222e636ab378a0273bf3e7Christopher Tate public JobParameters[] newArray(int size) { 1057060b04f6d92351b67222e636ab378a0273bf3e7Christopher Tate return new JobParameters[size]; 1066e31c5c82bc5c9bddf9c01d254067ea5bebbd96bMatthew Williams } 1076e31c5c82bc5c9bddf9c01d254067ea5bebbd96bMatthew Williams }; 1086e31c5c82bc5c9bddf9c01d254067ea5bebbd96bMatthew Williams} 109