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.net.Uri; 21 import android.os.IBinder; 22 import android.os.Parcel; 23 import android.os.Parcelable; 24 import 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 */ 30 public class JobParameters implements Parcelable { 31 32 /** @hide */ 33 public static final int REASON_CANCELED = 0; 34 /** @hide */ 35 public static final int REASON_CONSTRAINTS_NOT_SATISFIED = 1; 36 /** @hide */ 37 public static final int REASON_PREEMPT = 2; 38 /** @hide */ 39 public static final int REASON_TIMEOUT = 3; 40 /** @hide */ 41 public static final int REASON_DEVICE_IDLE = 4; 42 43 private final int jobId; 44 private final PersistableBundle extras; 45 private final IBinder callback; 46 private final boolean overrideDeadlineExpired; 47 private final Uri[] mTriggeredContentUris; 48 private final String[] mTriggeredContentAuthorities; 49 50 private int stopReason; // Default value of stopReason is REASON_CANCELED 51 52 /** @hide */ 53 public JobParameters(IBinder callback, int jobId, PersistableBundle extras, 54 boolean overrideDeadlineExpired, Uri[] triggeredContentUris, 55 String[] triggeredContentAuthorities) { 56 this.jobId = jobId; 57 this.extras = extras; 58 this.callback = callback; 59 this.overrideDeadlineExpired = overrideDeadlineExpired; 60 this.mTriggeredContentUris = triggeredContentUris; 61 this.mTriggeredContentAuthorities = triggeredContentAuthorities; 62 } 63 64 /** 65 * @return The unique id of this job, specified at creation time. 66 */ 67 public int getJobId() { 68 return jobId; 69 } 70 71 /** 72 * Reason onStopJob() was called on this job. 73 * @hide 74 */ 75 public int getStopReason() { 76 return stopReason; 77 } 78 79 /** 80 * @return The extras you passed in when constructing this job with 81 * {@link android.app.job.JobInfo.Builder#setExtras(android.os.PersistableBundle)}. This will 82 * never be null. If you did not set any extras this will be an empty bundle. 83 */ 84 public PersistableBundle getExtras() { 85 return extras; 86 } 87 88 /** 89 * For jobs with {@link android.app.job.JobInfo.Builder#setOverrideDeadline(long)} set, this 90 * provides an easy way to tell whether the job is being executed due to the deadline 91 * expiring. Note: If the job is running because its deadline expired, it implies that its 92 * constraints will not be met. 93 */ 94 public boolean isOverrideDeadlineExpired() { 95 return overrideDeadlineExpired; 96 } 97 98 /** 99 * For jobs with {@link android.app.job.JobInfo.Builder#addTriggerContentUri} set, this 100 * reports which URIs have triggered the job. This will be null if either no URIs have 101 * triggered it (it went off due to a deadline or other reason), or the number of changed 102 * URIs is too large to report. Whether or not the number of URIs is too large, you can 103 * always use {@link #getTriggeredContentAuthorities()} to determine whether the job was 104 * triggered due to any content changes and the authorities they are associated with. 105 */ 106 public Uri[] getTriggeredContentUris() { 107 return mTriggeredContentUris; 108 } 109 110 /** 111 * For jobs with {@link android.app.job.JobInfo.Builder#addTriggerContentUri} set, this 112 * reports which content authorities have triggered the job. It will only be null if no 113 * authorities have triggered it -- that is, the job executed for some other reason, such 114 * as a deadline expiring. If this is non-null, you can use {@link #getTriggeredContentUris()} 115 * to retrieve the details of which URIs changed (as long as that has not exceeded the maximum 116 * number it can reported). 117 */ 118 public String[] getTriggeredContentAuthorities() { 119 return mTriggeredContentAuthorities; 120 } 121 122 /** @hide */ 123 public IJobCallback getCallback() { 124 return IJobCallback.Stub.asInterface(callback); 125 } 126 127 private JobParameters(Parcel in) { 128 jobId = in.readInt(); 129 extras = in.readPersistableBundle(); 130 callback = in.readStrongBinder(); 131 overrideDeadlineExpired = in.readInt() == 1; 132 mTriggeredContentUris = in.createTypedArray(Uri.CREATOR); 133 mTriggeredContentAuthorities = in.createStringArray(); 134 stopReason = in.readInt(); 135 } 136 137 /** @hide */ 138 public void setStopReason(int reason) { 139 stopReason = reason; 140 } 141 142 @Override 143 public int describeContents() { 144 return 0; 145 } 146 147 @Override 148 public void writeToParcel(Parcel dest, int flags) { 149 dest.writeInt(jobId); 150 dest.writePersistableBundle(extras); 151 dest.writeStrongBinder(callback); 152 dest.writeInt(overrideDeadlineExpired ? 1 : 0); 153 dest.writeTypedArray(mTriggeredContentUris, flags); 154 dest.writeStringArray(mTriggeredContentAuthorities); 155 dest.writeInt(stopReason); 156 } 157 158 public static final Creator<JobParameters> CREATOR = new Creator<JobParameters>() { 159 @Override 160 public JobParameters createFromParcel(Parcel in) { 161 return new JobParameters(in); 162 } 163 164 @Override 165 public JobParameters[] newArray(int size) { 166 return new JobParameters[size]; 167 } 168 }; 169 } 170