JobParameters.java revision 1a30bd9b13fd127d9bbfdc5fd4cb2f80ab7ece21
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; 201a30bd9b13fd127d9bbfdc5fd4cb2f80ab7ece21Dianne Hackbornimport android.net.Uri; 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 325db09084c8e4efc6311754243c39962fc8e7a766Shreyas Basarge /** @hide */ 335db09084c8e4efc6311754243c39962fc8e7a766Shreyas Basarge public static final int REASON_CANCELED = 0; 345db09084c8e4efc6311754243c39962fc8e7a766Shreyas Basarge /** @hide */ 355db09084c8e4efc6311754243c39962fc8e7a766Shreyas Basarge public static final int REASON_CONSTRAINTS_NOT_SATISFIED = 1; 365db09084c8e4efc6311754243c39962fc8e7a766Shreyas Basarge /** @hide */ 375db09084c8e4efc6311754243c39962fc8e7a766Shreyas Basarge public static final int REASON_PREEMPT = 2; 385db09084c8e4efc6311754243c39962fc8e7a766Shreyas Basarge /** @hide */ 395db09084c8e4efc6311754243c39962fc8e7a766Shreyas Basarge public static final int REASON_TIMEOUT = 3; 405db09084c8e4efc6311754243c39962fc8e7a766Shreyas Basarge /** @hide */ 415db09084c8e4efc6311754243c39962fc8e7a766Shreyas Basarge public static final int REASON_DEVICE_IDLE = 4; 425db09084c8e4efc6311754243c39962fc8e7a766Shreyas Basarge 437060b04f6d92351b67222e636ab378a0273bf3e7Christopher Tate private final int jobId; 443d86fd2bb9db6067c49634bc4c6cdb4d5235ad36Matthew Williams private final PersistableBundle extras; 456de79e2b17fa0796ea4d39fd9555b563c484248dMatthew Williams private final IBinder callback; 4603a4da6e8e92b19c1345016c06694cb3aabbfc27Matthew Williams private final boolean overrideDeadlineExpired; 471a30bd9b13fd127d9bbfdc5fd4cb2f80ab7ece21Dianne Hackborn private final Uri[] mTriggeredContentUris; 481a30bd9b13fd127d9bbfdc5fd4cb2f80ab7ece21Dianne Hackborn private final String[] mTriggeredContentAuthorities; 491a30bd9b13fd127d9bbfdc5fd4cb2f80ab7ece21Dianne Hackborn 505db09084c8e4efc6311754243c39962fc8e7a766Shreyas Basarge private int stopReason; // Default value of stopReason is REASON_CANCELED 516de79e2b17fa0796ea4d39fd9555b563c484248dMatthew Williams 526de79e2b17fa0796ea4d39fd9555b563c484248dMatthew Williams /** @hide */ 5303a4da6e8e92b19c1345016c06694cb3aabbfc27Matthew Williams public JobParameters(IBinder callback, int jobId, PersistableBundle extras, 541a30bd9b13fd127d9bbfdc5fd4cb2f80ab7ece21Dianne Hackborn boolean overrideDeadlineExpired, Uri[] triggeredContentUris, 551a30bd9b13fd127d9bbfdc5fd4cb2f80ab7ece21Dianne Hackborn String[] triggeredContentAuthorities) { 567060b04f6d92351b67222e636ab378a0273bf3e7Christopher Tate this.jobId = jobId; 576de79e2b17fa0796ea4d39fd9555b563c484248dMatthew Williams this.extras = extras; 586de79e2b17fa0796ea4d39fd9555b563c484248dMatthew Williams this.callback = callback; 5903a4da6e8e92b19c1345016c06694cb3aabbfc27Matthew Williams this.overrideDeadlineExpired = overrideDeadlineExpired; 601a30bd9b13fd127d9bbfdc5fd4cb2f80ab7ece21Dianne Hackborn this.mTriggeredContentUris = triggeredContentUris; 611a30bd9b13fd127d9bbfdc5fd4cb2f80ab7ece21Dianne Hackborn this.mTriggeredContentAuthorities = triggeredContentAuthorities; 626de79e2b17fa0796ea4d39fd9555b563c484248dMatthew Williams } 636e31c5c82bc5c9bddf9c01d254067ea5bebbd96bMatthew Williams 646e31c5c82bc5c9bddf9c01d254067ea5bebbd96bMatthew Williams /** 657060b04f6d92351b67222e636ab378a0273bf3e7Christopher Tate * @return The unique id of this job, specified at creation time. 666e31c5c82bc5c9bddf9c01d254067ea5bebbd96bMatthew Williams */ 677060b04f6d92351b67222e636ab378a0273bf3e7Christopher Tate public int getJobId() { 687060b04f6d92351b67222e636ab378a0273bf3e7Christopher Tate return jobId; 696e31c5c82bc5c9bddf9c01d254067ea5bebbd96bMatthew Williams } 706e31c5c82bc5c9bddf9c01d254067ea5bebbd96bMatthew Williams 716e31c5c82bc5c9bddf9c01d254067ea5bebbd96bMatthew Williams /** 725db09084c8e4efc6311754243c39962fc8e7a766Shreyas Basarge * Reason onStopJob() was called on this job. 735db09084c8e4efc6311754243c39962fc8e7a766Shreyas Basarge * @hide 745db09084c8e4efc6311754243c39962fc8e7a766Shreyas Basarge */ 755db09084c8e4efc6311754243c39962fc8e7a766Shreyas Basarge public int getStopReason() { 765db09084c8e4efc6311754243c39962fc8e7a766Shreyas Basarge return stopReason; 775db09084c8e4efc6311754243c39962fc8e7a766Shreyas Basarge } 785db09084c8e4efc6311754243c39962fc8e7a766Shreyas Basarge 795db09084c8e4efc6311754243c39962fc8e7a766Shreyas Basarge /** 807060b04f6d92351b67222e636ab378a0273bf3e7Christopher Tate * @return The extras you passed in when constructing this job with 817060b04f6d92351b67222e636ab378a0273bf3e7Christopher Tate * {@link android.app.job.JobInfo.Builder#setExtras(android.os.PersistableBundle)}. This will 826e31c5c82bc5c9bddf9c01d254067ea5bebbd96bMatthew Williams * never be null. If you did not set any extras this will be an empty bundle. 836e31c5c82bc5c9bddf9c01d254067ea5bebbd96bMatthew Williams */ 843d86fd2bb9db6067c49634bc4c6cdb4d5235ad36Matthew Williams public PersistableBundle getExtras() { 856e31c5c82bc5c9bddf9c01d254067ea5bebbd96bMatthew Williams return extras; 866e31c5c82bc5c9bddf9c01d254067ea5bebbd96bMatthew Williams } 876e31c5c82bc5c9bddf9c01d254067ea5bebbd96bMatthew Williams 8803a4da6e8e92b19c1345016c06694cb3aabbfc27Matthew Williams /** 8903a4da6e8e92b19c1345016c06694cb3aabbfc27Matthew Williams * For jobs with {@link android.app.job.JobInfo.Builder#setOverrideDeadline(long)} set, this 9003a4da6e8e92b19c1345016c06694cb3aabbfc27Matthew Williams * provides an easy way to tell whether the job is being executed due to the deadline 9103a4da6e8e92b19c1345016c06694cb3aabbfc27Matthew Williams * expiring. Note: If the job is running because its deadline expired, it implies that its 9203a4da6e8e92b19c1345016c06694cb3aabbfc27Matthew Williams * constraints will not be met. 9303a4da6e8e92b19c1345016c06694cb3aabbfc27Matthew Williams */ 9403a4da6e8e92b19c1345016c06694cb3aabbfc27Matthew Williams public boolean isOverrideDeadlineExpired() { 9503a4da6e8e92b19c1345016c06694cb3aabbfc27Matthew Williams return overrideDeadlineExpired; 9603a4da6e8e92b19c1345016c06694cb3aabbfc27Matthew Williams } 9703a4da6e8e92b19c1345016c06694cb3aabbfc27Matthew Williams 981a30bd9b13fd127d9bbfdc5fd4cb2f80ab7ece21Dianne Hackborn /** 991a30bd9b13fd127d9bbfdc5fd4cb2f80ab7ece21Dianne Hackborn * For jobs with {@link android.app.job.JobInfo.Builder#addTriggerContentUri} set, this 1001a30bd9b13fd127d9bbfdc5fd4cb2f80ab7ece21Dianne Hackborn * reports which URIs have triggered the job. This will be null if either no URIs have 1011a30bd9b13fd127d9bbfdc5fd4cb2f80ab7ece21Dianne Hackborn * triggered it (it went off due to a deadline or other reason), or the number of changed 1021a30bd9b13fd127d9bbfdc5fd4cb2f80ab7ece21Dianne Hackborn * URIs is too large to report. Whether or not the number of URIs is too large, you can 1031a30bd9b13fd127d9bbfdc5fd4cb2f80ab7ece21Dianne Hackborn * always use {@link #getTriggeredContentAuthorities()} to determine whether the job was 1041a30bd9b13fd127d9bbfdc5fd4cb2f80ab7ece21Dianne Hackborn * triggered due to any content changes and the authorities they are associated with. 1051a30bd9b13fd127d9bbfdc5fd4cb2f80ab7ece21Dianne Hackborn */ 1061a30bd9b13fd127d9bbfdc5fd4cb2f80ab7ece21Dianne Hackborn public Uri[] getTriggeredContentUris() { 1071a30bd9b13fd127d9bbfdc5fd4cb2f80ab7ece21Dianne Hackborn return mTriggeredContentUris; 1081a30bd9b13fd127d9bbfdc5fd4cb2f80ab7ece21Dianne Hackborn } 1091a30bd9b13fd127d9bbfdc5fd4cb2f80ab7ece21Dianne Hackborn 1101a30bd9b13fd127d9bbfdc5fd4cb2f80ab7ece21Dianne Hackborn /** 1111a30bd9b13fd127d9bbfdc5fd4cb2f80ab7ece21Dianne Hackborn * For jobs with {@link android.app.job.JobInfo.Builder#addTriggerContentUri} set, this 1121a30bd9b13fd127d9bbfdc5fd4cb2f80ab7ece21Dianne Hackborn * reports which content authorities have triggered the job. It will only be null if no 1131a30bd9b13fd127d9bbfdc5fd4cb2f80ab7ece21Dianne Hackborn * authorities have triggered it -- that is, the job executed for some other reason, such 1141a30bd9b13fd127d9bbfdc5fd4cb2f80ab7ece21Dianne Hackborn * as a deadline expiring. If this is non-null, you can use {@link #getTriggeredContentUris()} 1151a30bd9b13fd127d9bbfdc5fd4cb2f80ab7ece21Dianne Hackborn * to retrieve the details of which URIs changed (as long as that has not exceeded the maximum 1161a30bd9b13fd127d9bbfdc5fd4cb2f80ab7ece21Dianne Hackborn * number it can reported). 1171a30bd9b13fd127d9bbfdc5fd4cb2f80ab7ece21Dianne Hackborn */ 1181a30bd9b13fd127d9bbfdc5fd4cb2f80ab7ece21Dianne Hackborn public String[] getTriggeredContentAuthorities() { 1191a30bd9b13fd127d9bbfdc5fd4cb2f80ab7ece21Dianne Hackborn return mTriggeredContentAuthorities; 1201a30bd9b13fd127d9bbfdc5fd4cb2f80ab7ece21Dianne Hackborn } 1211a30bd9b13fd127d9bbfdc5fd4cb2f80ab7ece21Dianne Hackborn 1226de79e2b17fa0796ea4d39fd9555b563c484248dMatthew Williams /** @hide */ 1237060b04f6d92351b67222e636ab378a0273bf3e7Christopher Tate public IJobCallback getCallback() { 1247060b04f6d92351b67222e636ab378a0273bf3e7Christopher Tate return IJobCallback.Stub.asInterface(callback); 1256e31c5c82bc5c9bddf9c01d254067ea5bebbd96bMatthew Williams } 1266e31c5c82bc5c9bddf9c01d254067ea5bebbd96bMatthew Williams 1277060b04f6d92351b67222e636ab378a0273bf3e7Christopher Tate private JobParameters(Parcel in) { 1287060b04f6d92351b67222e636ab378a0273bf3e7Christopher Tate jobId = in.readInt(); 1293d86fd2bb9db6067c49634bc4c6cdb4d5235ad36Matthew Williams extras = in.readPersistableBundle(); 1306de79e2b17fa0796ea4d39fd9555b563c484248dMatthew Williams callback = in.readStrongBinder(); 13103a4da6e8e92b19c1345016c06694cb3aabbfc27Matthew Williams overrideDeadlineExpired = in.readInt() == 1; 1321a30bd9b13fd127d9bbfdc5fd4cb2f80ab7ece21Dianne Hackborn mTriggeredContentUris = in.createTypedArray(Uri.CREATOR); 1331a30bd9b13fd127d9bbfdc5fd4cb2f80ab7ece21Dianne Hackborn mTriggeredContentAuthorities = in.createStringArray(); 1345db09084c8e4efc6311754243c39962fc8e7a766Shreyas Basarge stopReason = in.readInt(); 1355db09084c8e4efc6311754243c39962fc8e7a766Shreyas Basarge } 1365db09084c8e4efc6311754243c39962fc8e7a766Shreyas Basarge 1375db09084c8e4efc6311754243c39962fc8e7a766Shreyas Basarge /** @hide */ 1385db09084c8e4efc6311754243c39962fc8e7a766Shreyas Basarge public void setStopReason(int reason) { 1395db09084c8e4efc6311754243c39962fc8e7a766Shreyas Basarge stopReason = reason; 1406e31c5c82bc5c9bddf9c01d254067ea5bebbd96bMatthew Williams } 1416e31c5c82bc5c9bddf9c01d254067ea5bebbd96bMatthew Williams 1426e31c5c82bc5c9bddf9c01d254067ea5bebbd96bMatthew Williams @Override 1436e31c5c82bc5c9bddf9c01d254067ea5bebbd96bMatthew Williams public int describeContents() { 1446e31c5c82bc5c9bddf9c01d254067ea5bebbd96bMatthew Williams return 0; 1456e31c5c82bc5c9bddf9c01d254067ea5bebbd96bMatthew Williams } 1466e31c5c82bc5c9bddf9c01d254067ea5bebbd96bMatthew Williams 1476e31c5c82bc5c9bddf9c01d254067ea5bebbd96bMatthew Williams @Override 1486e31c5c82bc5c9bddf9c01d254067ea5bebbd96bMatthew Williams public void writeToParcel(Parcel dest, int flags) { 1497060b04f6d92351b67222e636ab378a0273bf3e7Christopher Tate dest.writeInt(jobId); 1503d86fd2bb9db6067c49634bc4c6cdb4d5235ad36Matthew Williams dest.writePersistableBundle(extras); 1516de79e2b17fa0796ea4d39fd9555b563c484248dMatthew Williams dest.writeStrongBinder(callback); 15203a4da6e8e92b19c1345016c06694cb3aabbfc27Matthew Williams dest.writeInt(overrideDeadlineExpired ? 1 : 0); 1531a30bd9b13fd127d9bbfdc5fd4cb2f80ab7ece21Dianne Hackborn dest.writeTypedArray(mTriggeredContentUris, flags); 1541a30bd9b13fd127d9bbfdc5fd4cb2f80ab7ece21Dianne Hackborn dest.writeStringArray(mTriggeredContentAuthorities); 1555db09084c8e4efc6311754243c39962fc8e7a766Shreyas Basarge dest.writeInt(stopReason); 1566e31c5c82bc5c9bddf9c01d254067ea5bebbd96bMatthew Williams } 1576e31c5c82bc5c9bddf9c01d254067ea5bebbd96bMatthew Williams 1587060b04f6d92351b67222e636ab378a0273bf3e7Christopher Tate public static final Creator<JobParameters> CREATOR = new Creator<JobParameters>() { 1596e31c5c82bc5c9bddf9c01d254067ea5bebbd96bMatthew Williams @Override 1607060b04f6d92351b67222e636ab378a0273bf3e7Christopher Tate public JobParameters createFromParcel(Parcel in) { 1617060b04f6d92351b67222e636ab378a0273bf3e7Christopher Tate return new JobParameters(in); 1626e31c5c82bc5c9bddf9c01d254067ea5bebbd96bMatthew Williams } 1636e31c5c82bc5c9bddf9c01d254067ea5bebbd96bMatthew Williams 1646e31c5c82bc5c9bddf9c01d254067ea5bebbd96bMatthew Williams @Override 1657060b04f6d92351b67222e636ab378a0273bf3e7Christopher Tate public JobParameters[] newArray(int size) { 1667060b04f6d92351b67222e636ab378a0273bf3e7Christopher Tate return new JobParameters[size]; 1676e31c5c82bc5c9bddf9c01d254067ea5bebbd96bMatthew Williams } 1686e31c5c82bc5c9bddf9c01d254067ea5bebbd96bMatthew Williams }; 1696e31c5c82bc5c9bddf9c01d254067ea5bebbd96bMatthew Williams} 170