Merge "API council requested tweaks to JobInfo." into pi-dev

This commit is contained in:
TreeHugger Robot
2018-03-27 16:25:23 +00:00
committed by Android (Google) Code Review
5 changed files with 252 additions and 71 deletions

View File

@@ -7041,7 +7041,8 @@ package android.app.job {
method public int getBackoffPolicy(); method public int getBackoffPolicy();
method public android.content.ClipData getClipData(); method public android.content.ClipData getClipData();
method public int getClipGrantFlags(); method public int getClipGrantFlags();
method public long getEstimatedNetworkBytes(); method public long getEstimatedNetworkDownloadBytes();
method public long getEstimatedNetworkUploadBytes();
method public android.os.PersistableBundle getExtras(); method public android.os.PersistableBundle getExtras();
method public long getFlexMillis(); method public long getFlexMillis();
method public int getId(); method public int getId();
@@ -7058,8 +7059,10 @@ package android.app.job {
method public long getTriggerContentMaxDelay(); method public long getTriggerContentMaxDelay();
method public long getTriggerContentUpdateDelay(); method public long getTriggerContentUpdateDelay();
method public android.app.job.JobInfo.TriggerContentUri[] getTriggerContentUris(); method public android.app.job.JobInfo.TriggerContentUri[] getTriggerContentUris();
method public boolean isImportantWhileForeground();
method public boolean isPeriodic(); method public boolean isPeriodic();
method public boolean isPersisted(); method public boolean isPersisted();
method public boolean isPrefetch();
method public boolean isRequireBatteryNotLow(); method public boolean isRequireBatteryNotLow();
method public boolean isRequireCharging(); method public boolean isRequireCharging();
method public boolean isRequireDeviceIdle(); method public boolean isRequireDeviceIdle();
@@ -7085,15 +7088,15 @@ package android.app.job {
method public android.app.job.JobInfo build(); method public android.app.job.JobInfo build();
method public android.app.job.JobInfo.Builder setBackoffCriteria(long, int); method public android.app.job.JobInfo.Builder setBackoffCriteria(long, int);
method public android.app.job.JobInfo.Builder setClipData(android.content.ClipData, int); method public android.app.job.JobInfo.Builder setClipData(android.content.ClipData, int);
method public android.app.job.JobInfo.Builder setEstimatedNetworkBytes(long); method public android.app.job.JobInfo.Builder setEstimatedNetworkBytes(long, long);
method public android.app.job.JobInfo.Builder setExtras(android.os.PersistableBundle); method public android.app.job.JobInfo.Builder setExtras(android.os.PersistableBundle);
method public android.app.job.JobInfo.Builder setImportantWhileForeground(boolean); method public android.app.job.JobInfo.Builder setImportantWhileForeground(boolean);
method public android.app.job.JobInfo.Builder setIsPrefetch(boolean);
method public android.app.job.JobInfo.Builder setMinimumLatency(long); method public android.app.job.JobInfo.Builder setMinimumLatency(long);
method public android.app.job.JobInfo.Builder setOverrideDeadline(long); method public android.app.job.JobInfo.Builder setOverrideDeadline(long);
method public android.app.job.JobInfo.Builder setPeriodic(long); method public android.app.job.JobInfo.Builder setPeriodic(long);
method public android.app.job.JobInfo.Builder setPeriodic(long, long); method public android.app.job.JobInfo.Builder setPeriodic(long, long);
method public android.app.job.JobInfo.Builder setPersisted(boolean); method public android.app.job.JobInfo.Builder setPersisted(boolean);
method public android.app.job.JobInfo.Builder setPrefetch(boolean);
method public android.app.job.JobInfo.Builder setRequiredNetwork(android.net.NetworkRequest); method public android.app.job.JobInfo.Builder setRequiredNetwork(android.net.NetworkRequest);
method public android.app.job.JobInfo.Builder setRequiredNetworkType(int); method public android.app.job.JobInfo.Builder setRequiredNetworkType(int);
method public android.app.job.JobInfo.Builder setRequiresBatteryNotLow(boolean); method public android.app.job.JobInfo.Builder setRequiresBatteryNotLow(boolean);
@@ -7163,10 +7166,11 @@ package android.app.job {
public final class JobWorkItem implements android.os.Parcelable { public final class JobWorkItem implements android.os.Parcelable {
ctor public JobWorkItem(android.content.Intent); ctor public JobWorkItem(android.content.Intent);
ctor public JobWorkItem(android.content.Intent, long); ctor public JobWorkItem(android.content.Intent, long, long);
method public int describeContents(); method public int describeContents();
method public int getDeliveryCount(); method public int getDeliveryCount();
method public long getEstimatedNetworkBytes(); method public long getEstimatedNetworkDownloadBytes();
method public long getEstimatedNetworkUploadBytes();
method public android.content.Intent getIntent(); method public android.content.Intent getIntent();
method public void writeToParcel(android.os.Parcel, int); method public void writeToParcel(android.os.Parcel, int);
field public static final android.os.Parcelable.Creator<android.app.job.JobWorkItem> CREATOR; field public static final android.os.Parcelable.Creator<android.app.job.JobWorkItem> CREATOR;

View File

@@ -54,6 +54,24 @@ package android.app.admin {
} }
package android.app.job {
public class JobInfo implements android.os.Parcelable {
method public deprecated long getEstimatedNetworkBytes();
}
public static final class JobInfo.Builder {
method public deprecated android.app.job.JobInfo.Builder setEstimatedNetworkBytes(long);
method public deprecated android.app.job.JobInfo.Builder setIsPrefetch(boolean);
}
public final class JobWorkItem implements android.os.Parcelable {
ctor public deprecated JobWorkItem(android.content.Intent, long);
method public deprecated long getEstimatedNetworkBytes();
}
}
package android.app.usage { package android.app.usage {
public final class StorageStats implements android.os.Parcelable { public final class StorageStats implements android.os.Parcelable {

View File

@@ -65,7 +65,6 @@ public class JobInfo implements Parcelable {
NETWORK_TYPE_UNMETERED, NETWORK_TYPE_UNMETERED,
NETWORK_TYPE_NOT_ROAMING, NETWORK_TYPE_NOT_ROAMING,
NETWORK_TYPE_CELLULAR, NETWORK_TYPE_CELLULAR,
NETWORK_TYPE_METERED,
}) })
@Retention(RetentionPolicy.SOURCE) @Retention(RetentionPolicy.SOURCE)
public @interface NetworkType {} public @interface NetworkType {}
@@ -253,7 +252,7 @@ public class JobInfo implements Parcelable {
/** /**
* @hide * @hide
*/ */
public static final int FLAG_IS_PREFETCH = 1 << 2; public static final int FLAG_PREFETCH = 1 << 2;
/** /**
* This job needs to be exempted from the app standby throttling. Only the system (UID 1000) * This job needs to be exempted from the app standby throttling. Only the system (UID 1000)
@@ -296,7 +295,8 @@ public class JobInfo implements Parcelable {
private final boolean hasEarlyConstraint; private final boolean hasEarlyConstraint;
private final boolean hasLateConstraint; private final boolean hasLateConstraint;
private final NetworkRequest networkRequest; private final NetworkRequest networkRequest;
private final long networkBytes; private final long networkDownloadBytes;
private final long networkUploadBytes;
private final long minLatencyMillis; private final long minLatencyMillis;
private final long maxExecutionDelayMillis; private final long maxExecutionDelayMillis;
private final boolean isPeriodic; private final boolean isPeriodic;
@@ -317,30 +317,28 @@ public class JobInfo implements Parcelable {
} }
/** /**
* Bundle of extras which are returned to your application at execution time. * @see JobInfo.Builder#setExtras(PersistableBundle)
*/ */
public @NonNull PersistableBundle getExtras() { public @NonNull PersistableBundle getExtras() {
return extras; return extras;
} }
/** /**
* Bundle of transient extras which are returned to your application at execution time, * @see JobInfo.Builder#setTransientExtras(Bundle)
* but not persisted by the system.
*/ */
public @NonNull Bundle getTransientExtras() { public @NonNull Bundle getTransientExtras() {
return transientExtras; return transientExtras;
} }
/** /**
* ClipData of information that is returned to your application at execution time, * @see JobInfo.Builder#setClipData(ClipData, int)
* but not persisted by the system.
*/ */
public @Nullable ClipData getClipData() { public @Nullable ClipData getClipData() {
return clipData; return clipData;
} }
/** /**
* Permission grants that go along with {@link #getClipData}. * @see JobInfo.Builder#setClipData(ClipData, int)
*/ */
public int getClipGrantFlags() { public int getClipGrantFlags() {
return clipGrantFlags; return clipGrantFlags;
@@ -369,32 +367,28 @@ public class JobInfo implements Parcelable {
} }
/** /**
* Whether this job requires that the device be charging (or be a non-battery-powered * @see JobInfo.Builder#setRequiresCharging(boolean)
* device connected to permanent power, such as Android TV devices).
*/ */
public boolean isRequireCharging() { public boolean isRequireCharging() {
return (constraintFlags & CONSTRAINT_FLAG_CHARGING) != 0; return (constraintFlags & CONSTRAINT_FLAG_CHARGING) != 0;
} }
/** /**
* Whether this job needs the device's battery level to not be at below the critical threshold. * @see JobInfo.Builder#setRequiresBatteryNotLow(boolean)
*/ */
public boolean isRequireBatteryNotLow() { public boolean isRequireBatteryNotLow() {
return (constraintFlags & CONSTRAINT_FLAG_BATTERY_NOT_LOW) != 0; return (constraintFlags & CONSTRAINT_FLAG_BATTERY_NOT_LOW) != 0;
} }
/** /**
* Whether this job requires that the user <em>not</em> be interacting with the device. * @see JobInfo.Builder#setRequiresDeviceIdle(boolean)
*
* <p class="note">This is <em>not</em> the same as "doze" or "device idle";
* it is purely about the user's direct interactions.</p>
*/ */
public boolean isRequireDeviceIdle() { public boolean isRequireDeviceIdle() {
return (constraintFlags & CONSTRAINT_FLAG_DEVICE_IDLE) != 0; return (constraintFlags & CONSTRAINT_FLAG_DEVICE_IDLE) != 0;
} }
/** /**
* Whether this job needs the device's storage to not be low. * @see JobInfo.Builder#setRequiresStorageNotLow(boolean)
*/ */
public boolean isRequireStorageNotLow() { public boolean isRequireStorageNotLow() {
return (constraintFlags & CONSTRAINT_FLAG_STORAGE_NOT_LOW) != 0; return (constraintFlags & CONSTRAINT_FLAG_STORAGE_NOT_LOW) != 0;
@@ -410,6 +404,7 @@ public class JobInfo implements Parcelable {
/** /**
* Which content: URIs must change for the job to be scheduled. Returns null * Which content: URIs must change for the job to be scheduled. Returns null
* if there are none required. * if there are none required.
* @see JobInfo.Builder#addTriggerContentUri(TriggerContentUri)
*/ */
public @Nullable TriggerContentUri[] getTriggerContentUris() { public @Nullable TriggerContentUri[] getTriggerContentUris() {
return triggerContentUris; return triggerContentUris;
@@ -418,6 +413,7 @@ public class JobInfo implements Parcelable {
/** /**
* When triggering on content URI changes, this is the delay from when a change * When triggering on content URI changes, this is the delay from when a change
* is detected until the job is scheduled. * is detected until the job is scheduled.
* @see JobInfo.Builder#setTriggerContentUpdateDelay(long)
*/ */
public long getTriggerContentUpdateDelay() { public long getTriggerContentUpdateDelay() {
return triggerContentUpdateDelay; return triggerContentUpdateDelay;
@@ -426,6 +422,7 @@ public class JobInfo implements Parcelable {
/** /**
* When triggering on content URI changes, this is the maximum delay we will * When triggering on content URI changes, this is the maximum delay we will
* use before scheduling the job. * use before scheduling the job.
* @see JobInfo.Builder#setTriggerContentMaxDelay(long)
*/ */
public long getTriggerContentMaxDelay() { public long getTriggerContentMaxDelay() {
return triggerContentMaxDelay; return triggerContentMaxDelay;
@@ -466,28 +463,59 @@ public class JobInfo implements Parcelable {
} }
/** /**
* Return the estimated size of network traffic that will be performed by * @deprecated replaced by {@link #getEstimatedNetworkDownloadBytes()} and
* {@link #getEstimatedNetworkUploadBytes()}.
* @removed
*/
@Deprecated
public @BytesLong long getEstimatedNetworkBytes() {
if (networkDownloadBytes == NETWORK_BYTES_UNKNOWN
&& networkUploadBytes == NETWORK_BYTES_UNKNOWN) {
return NETWORK_BYTES_UNKNOWN;
} else if (networkDownloadBytes == NETWORK_BYTES_UNKNOWN) {
return networkUploadBytes;
} else if (networkUploadBytes == NETWORK_BYTES_UNKNOWN) {
return networkDownloadBytes;
} else {
return networkDownloadBytes + networkUploadBytes;
}
}
/**
* Return the estimated size of download traffic that will be performed by
* this job, in bytes. * this job, in bytes.
* *
* @return Estimated size of network traffic, or * @return Estimated size of download traffic, or
* {@link #NETWORK_BYTES_UNKNOWN} when unknown. * {@link #NETWORK_BYTES_UNKNOWN} when unknown.
* @see Builder#setEstimatedNetworkBytes(long) * @see Builder#setEstimatedNetworkBytes(long, long)
*/ */
public @BytesLong long getEstimatedNetworkBytes() { public @BytesLong long getEstimatedNetworkDownloadBytes() {
return networkBytes; return networkDownloadBytes;
}
/**
* Return the estimated size of upload traffic that will be performed by
* this job, in bytes.
*
* @return Estimated size of upload traffic, or
* {@link #NETWORK_BYTES_UNKNOWN} when unknown.
* @see Builder#setEstimatedNetworkBytes(long, long)
*/
public @BytesLong long getEstimatedNetworkUploadBytes() {
return networkUploadBytes;
} }
/** /**
* Set for a job that does not recur periodically, to specify a delay after which the job * Set for a job that does not recur periodically, to specify a delay after which the job
* will be eligible for execution. This value is not set if the job recurs periodically. * will be eligible for execution. This value is not set if the job recurs periodically.
* @see JobInfo.Builder#setMinimumLatency(long)
*/ */
public long getMinLatencyMillis() { public long getMinLatencyMillis() {
return minLatencyMillis; return minLatencyMillis;
} }
/** /**
* See {@link Builder#setOverrideDeadline(long)}. This value is not set if the job recurs * @see JobInfo.Builder#setOverrideDeadline(long)
* periodically.
*/ */
public long getMaxExecutionDelayMillis() { public long getMaxExecutionDelayMillis() {
return maxExecutionDelayMillis; return maxExecutionDelayMillis;
@@ -495,13 +523,15 @@ public class JobInfo implements Parcelable {
/** /**
* Track whether this job will repeat with a given period. * Track whether this job will repeat with a given period.
* @see JobInfo.Builder#setPeriodic(long)
* @see JobInfo.Builder#setPeriodic(long, long)
*/ */
public boolean isPeriodic() { public boolean isPeriodic() {
return isPeriodic; return isPeriodic;
} }
/** /**
* @return Whether or not this job should be persisted across device reboots. * @see JobInfo.Builder#setPersisted(boolean)
*/ */
public boolean isPersisted() { public boolean isPersisted() {
return isPersisted; return isPersisted;
@@ -510,6 +540,8 @@ public class JobInfo implements Parcelable {
/** /**
* Set to the interval between occurrences of this job. This value is <b>not</b> set if the * Set to the interval between occurrences of this job. This value is <b>not</b> set if the
* job does not recur periodically. * job does not recur periodically.
* @see JobInfo.Builder#setPeriodic(long)
* @see JobInfo.Builder#setPeriodic(long, long)
*/ */
public long getIntervalMillis() { public long getIntervalMillis() {
return intervalMillis; return intervalMillis;
@@ -518,6 +550,8 @@ public class JobInfo implements Parcelable {
/** /**
* Flex time for this job. Only valid if this is a periodic job. The job can * Flex time for this job. Only valid if this is a periodic job. The job can
* execute at any time in a window of flex length at the end of the period. * execute at any time in a window of flex length at the end of the period.
* @see JobInfo.Builder#setPeriodic(long)
* @see JobInfo.Builder#setPeriodic(long, long)
*/ */
public long getFlexMillis() { public long getFlexMillis() {
return flexMillis; return flexMillis;
@@ -527,6 +561,7 @@ public class JobInfo implements Parcelable {
* The amount of time the JobScheduler will wait before rescheduling a failed job. This value * The amount of time the JobScheduler will wait before rescheduling a failed job. This value
* will be increased depending on the backoff policy specified at job creation time. Defaults * will be increased depending on the backoff policy specified at job creation time. Defaults
* to 30 seconds, minimum is currently 10 seconds. * to 30 seconds, minimum is currently 10 seconds.
* @see JobInfo.Builder#setBackoffCriteria(long, int)
*/ */
public long getInitialBackoffMillis() { public long getInitialBackoffMillis() {
return initialBackoffMillis; return initialBackoffMillis;
@@ -534,11 +569,26 @@ public class JobInfo implements Parcelable {
/** /**
* Return the backoff policy of this job. * Return the backoff policy of this job.
* @see JobInfo.Builder#setBackoffCriteria(long, int)
*/ */
public @BackoffPolicy int getBackoffPolicy() { public @BackoffPolicy int getBackoffPolicy() {
return backoffPolicy; return backoffPolicy;
} }
/**
* @see JobInfo.Builder#setImportantWhileForeground(boolean)
*/
public boolean isImportantWhileForeground() {
return (flags & FLAG_IMPORTANT_WHILE_FOREGROUND) != 0;
}
/**
* @see JobInfo.Builder#setPrefetch(boolean)
*/
public boolean isPrefetch() {
return (flags & FLAG_PREFETCH) != 0;
}
/** /**
* User can specify an early constraint of 0L, which is valid, so we keep track of whether the * User can specify an early constraint of 0L, which is valid, so we keep track of whether the
* function was called at all. * function was called at all.
@@ -610,7 +660,10 @@ public class JobInfo implements Parcelable {
if (!Objects.equals(networkRequest, j.networkRequest)) { if (!Objects.equals(networkRequest, j.networkRequest)) {
return false; return false;
} }
if (networkBytes != j.networkBytes) { if (networkDownloadBytes != j.networkDownloadBytes) {
return false;
}
if (networkUploadBytes != j.networkUploadBytes) {
return false; return false;
} }
if (minLatencyMillis != j.minLatencyMillis) { if (minLatencyMillis != j.minLatencyMillis) {
@@ -673,7 +726,8 @@ public class JobInfo implements Parcelable {
if (networkRequest != null) { if (networkRequest != null) {
hashCode = 31 * hashCode + networkRequest.hashCode(); hashCode = 31 * hashCode + networkRequest.hashCode();
} }
hashCode = 31 * hashCode + Long.hashCode(networkBytes); hashCode = 31 * hashCode + Long.hashCode(networkDownloadBytes);
hashCode = 31 * hashCode + Long.hashCode(networkUploadBytes);
hashCode = 31 * hashCode + Long.hashCode(minLatencyMillis); hashCode = 31 * hashCode + Long.hashCode(minLatencyMillis);
hashCode = 31 * hashCode + Long.hashCode(maxExecutionDelayMillis); hashCode = 31 * hashCode + Long.hashCode(maxExecutionDelayMillis);
hashCode = 31 * hashCode + Boolean.hashCode(isPeriodic); hashCode = 31 * hashCode + Boolean.hashCode(isPeriodic);
@@ -708,7 +762,8 @@ public class JobInfo implements Parcelable {
} else { } else {
networkRequest = null; networkRequest = null;
} }
networkBytes = in.readLong(); networkDownloadBytes = in.readLong();
networkUploadBytes = in.readLong();
minLatencyMillis = in.readLong(); minLatencyMillis = in.readLong();
maxExecutionDelayMillis = in.readLong(); maxExecutionDelayMillis = in.readLong();
isPeriodic = in.readInt() == 1; isPeriodic = in.readInt() == 1;
@@ -737,7 +792,8 @@ public class JobInfo implements Parcelable {
triggerContentUpdateDelay = b.mTriggerContentUpdateDelay; triggerContentUpdateDelay = b.mTriggerContentUpdateDelay;
triggerContentMaxDelay = b.mTriggerContentMaxDelay; triggerContentMaxDelay = b.mTriggerContentMaxDelay;
networkRequest = b.mNetworkRequest; networkRequest = b.mNetworkRequest;
networkBytes = b.mNetworkBytes; networkDownloadBytes = b.mNetworkDownloadBytes;
networkUploadBytes = b.mNetworkUploadBytes;
minLatencyMillis = b.mMinLatencyMillis; minLatencyMillis = b.mMinLatencyMillis;
maxExecutionDelayMillis = b.mMaxExecutionDelayMillis; maxExecutionDelayMillis = b.mMaxExecutionDelayMillis;
isPeriodic = b.mIsPeriodic; isPeriodic = b.mIsPeriodic;
@@ -780,7 +836,8 @@ public class JobInfo implements Parcelable {
} else { } else {
out.writeInt(0); out.writeInt(0);
} }
out.writeLong(networkBytes); out.writeLong(networkDownloadBytes);
out.writeLong(networkUploadBytes);
out.writeLong(minLatencyMillis); out.writeLong(minLatencyMillis);
out.writeLong(maxExecutionDelayMillis); out.writeLong(maxExecutionDelayMillis);
out.writeInt(isPeriodic ? 1 : 0); out.writeInt(isPeriodic ? 1 : 0);
@@ -914,7 +971,8 @@ public class JobInfo implements Parcelable {
// Requirements. // Requirements.
private int mConstraintFlags; private int mConstraintFlags;
private NetworkRequest mNetworkRequest; private NetworkRequest mNetworkRequest;
private long mNetworkBytes = NETWORK_BYTES_UNKNOWN; private long mNetworkDownloadBytes = NETWORK_BYTES_UNKNOWN;
private long mNetworkUploadBytes = NETWORK_BYTES_UNKNOWN;
private ArrayList<TriggerContentUri> mTriggerContentUris; private ArrayList<TriggerContentUri> mTriggerContentUris;
private long mTriggerContentUpdateDelay = -1; private long mTriggerContentUpdateDelay = -1;
private long mTriggerContentMaxDelay = -1; private long mTriggerContentMaxDelay = -1;
@@ -965,6 +1023,7 @@ public class JobInfo implements Parcelable {
/** /**
* Set optional extras. This is persisted, so we only allow primitive types. * Set optional extras. This is persisted, so we only allow primitive types.
* @param extras Bundle containing extras you want the scheduler to hold on to for you. * @param extras Bundle containing extras you want the scheduler to hold on to for you.
* @see JobInfo#getExtras()
*/ */
public Builder setExtras(@NonNull PersistableBundle extras) { public Builder setExtras(@NonNull PersistableBundle extras) {
mExtras = extras; mExtras = extras;
@@ -979,6 +1038,7 @@ public class JobInfo implements Parcelable {
* {@link android.app.job.JobInfo.Builder#build()} is called.</p> * {@link android.app.job.JobInfo.Builder#build()} is called.</p>
* *
* @param extras Bundle containing extras you want the scheduler to hold on to for you. * @param extras Bundle containing extras you want the scheduler to hold on to for you.
* @see JobInfo#getTransientExtras()
*/ */
public Builder setTransientExtras(@NonNull Bundle extras) { public Builder setTransientExtras(@NonNull Bundle extras) {
mTransientExtras = extras; mTransientExtras = extras;
@@ -1006,6 +1066,8 @@ public class JobInfo implements Parcelable {
* a combination of {@link android.content.Intent#FLAG_GRANT_READ_URI_PERMISSION}, * a combination of {@link android.content.Intent#FLAG_GRANT_READ_URI_PERMISSION},
* {@link android.content.Intent#FLAG_GRANT_WRITE_URI_PERMISSION}, and * {@link android.content.Intent#FLAG_GRANT_WRITE_URI_PERMISSION}, and
* {@link android.content.Intent#FLAG_GRANT_PREFIX_URI_PERMISSION}. * {@link android.content.Intent#FLAG_GRANT_PREFIX_URI_PERMISSION}.
* @see JobInfo#getClipData()
* @see JobInfo#getClipGrantFlags()
*/ */
public Builder setClipData(@Nullable ClipData clip, int grantFlags) { public Builder setClipData(@Nullable ClipData clip, int grantFlags) {
mClipData = clip; mClipData = clip;
@@ -1095,6 +1157,16 @@ public class JobInfo implements Parcelable {
return this; return this;
} }
/**
* @deprecated replaced by
* {@link #setEstimatedNetworkBytes(long, long)}.
* @removed
*/
@Deprecated
public Builder setEstimatedNetworkBytes(@BytesLong long networkBytes) {
return setEstimatedNetworkBytes(networkBytes, NETWORK_BYTES_UNKNOWN);
}
/** /**
* Set the estimated size of network traffic that will be performed by * Set the estimated size of network traffic that will be performed by
* this job, in bytes. * this job, in bytes.
@@ -1112,23 +1184,30 @@ public class JobInfo implements Parcelable {
* <li>A job that synchronizes email could end up using an extreme range * <li>A job that synchronizes email could end up using an extreme range
* of data, from under 1KB when nothing has changed, to dozens of MB * of data, from under 1KB when nothing has changed, to dozens of MB
* when there are new emails with attachments. Jobs that cannot provide * when there are new emails with attachments. Jobs that cannot provide
* reasonable estimates should leave this estimated value undefined. * reasonable estimates should use the sentinel value
* {@link JobInfo#NETWORK_BYTES_UNKNOWN}.
* </ul> * </ul>
* Note that the system may choose to delay jobs with large network * Note that the system may choose to delay jobs with large network
* usage estimates when the device has a poor network connection, in * usage estimates when the device has a poor network connection, in
* order to save battery. * order to save battery.
* <p>
* The values provided here only reflect the traffic that will be
* performed by the base job; if you're using {@link JobWorkItem} then
* you also need to define the network traffic used by each work item
* when constructing them.
* *
* @param networkBytes The estimated size of network traffic that will * @param downloadBytes The estimated size of network traffic that will
* be performed by this job, in bytes. This value only * be downloaded by this job, in bytes.
* reflects the traffic that will be performed by the base * @param uploadBytes The estimated size of network traffic that will be
* job; if you're using {@link JobWorkItem} then you also * uploaded by this job, in bytes.
* need to define the network traffic used by each work item * @see JobInfo#getEstimatedNetworkDownloadBytes()
* when constructing them. * @see JobInfo#getEstimatedNetworkUploadBytes()
* @see JobInfo#getEstimatedNetworkBytes() * @see JobWorkItem#JobWorkItem(android.content.Intent, long, long)
* @see JobWorkItem#JobWorkItem(android.content.Intent, long)
*/ */
public Builder setEstimatedNetworkBytes(@BytesLong long networkBytes) { public Builder setEstimatedNetworkBytes(@BytesLong long downloadBytes,
mNetworkBytes = networkBytes; @BytesLong long uploadBytes) {
mNetworkDownloadBytes = downloadBytes;
mNetworkUploadBytes = uploadBytes;
return this; return this;
} }
@@ -1146,6 +1225,7 @@ public class JobInfo implements Parcelable {
* *
* @param requiresCharging Pass {@code true} to require that the device be * @param requiresCharging Pass {@code true} to require that the device be
* charging in order to run the job. * charging in order to run the job.
* @see JobInfo#isRequireCharging()
*/ */
public Builder setRequiresCharging(boolean requiresCharging) { public Builder setRequiresCharging(boolean requiresCharging) {
mConstraintFlags = (mConstraintFlags&~CONSTRAINT_FLAG_CHARGING) mConstraintFlags = (mConstraintFlags&~CONSTRAINT_FLAG_CHARGING)
@@ -1159,6 +1239,7 @@ public class JobInfo implements Parcelable {
* is not low, which is generally the point where the user is given a "low battery" * is not low, which is generally the point where the user is given a "low battery"
* warning. * warning.
* @param batteryNotLow Whether or not the device's battery level must not be low. * @param batteryNotLow Whether or not the device's battery level must not be low.
* @see JobInfo#isRequireBatteryNotLow()
*/ */
public Builder setRequiresBatteryNotLow(boolean batteryNotLow) { public Builder setRequiresBatteryNotLow(boolean batteryNotLow) {
mConstraintFlags = (mConstraintFlags&~CONSTRAINT_FLAG_BATTERY_NOT_LOW) mConstraintFlags = (mConstraintFlags&~CONSTRAINT_FLAG_BATTERY_NOT_LOW)
@@ -1183,6 +1264,7 @@ public class JobInfo implements Parcelable {
* *
* @param requiresDeviceIdle Pass {@code true} to prevent the job from running * @param requiresDeviceIdle Pass {@code true} to prevent the job from running
* while the device is being used interactively. * while the device is being used interactively.
* @see JobInfo#isRequireDeviceIdle()
*/ */
public Builder setRequiresDeviceIdle(boolean requiresDeviceIdle) { public Builder setRequiresDeviceIdle(boolean requiresDeviceIdle) {
mConstraintFlags = (mConstraintFlags&~CONSTRAINT_FLAG_DEVICE_IDLE) mConstraintFlags = (mConstraintFlags&~CONSTRAINT_FLAG_DEVICE_IDLE)
@@ -1196,6 +1278,7 @@ public class JobInfo implements Parcelable {
* in a low storage state, which is generally the point where the user is given a * in a low storage state, which is generally the point where the user is given a
* "low storage" warning. * "low storage" warning.
* @param storageNotLow Whether or not the device's available storage must not be low. * @param storageNotLow Whether or not the device's available storage must not be low.
* @see JobInfo#isRequireStorageNotLow()
*/ */
public Builder setRequiresStorageNotLow(boolean storageNotLow) { public Builder setRequiresStorageNotLow(boolean storageNotLow) {
mConstraintFlags = (mConstraintFlags&~CONSTRAINT_FLAG_STORAGE_NOT_LOW) mConstraintFlags = (mConstraintFlags&~CONSTRAINT_FLAG_STORAGE_NOT_LOW)
@@ -1228,6 +1311,7 @@ public class JobInfo implements Parcelable {
* job} * job}
* *
* @param uri The content: URI to monitor. * @param uri The content: URI to monitor.
* @see JobInfo#getTriggerContentUris()
*/ */
public Builder addTriggerContentUri(@NonNull TriggerContentUri uri) { public Builder addTriggerContentUri(@NonNull TriggerContentUri uri) {
if (mTriggerContentUris == null) { if (mTriggerContentUris == null) {
@@ -1242,6 +1326,7 @@ public class JobInfo implements Parcelable {
* the job is scheduled. If there are more changes during that time, the delay * the job is scheduled. If there are more changes during that time, the delay
* will be reset to start at the time of the most recent change. * will be reset to start at the time of the most recent change.
* @param durationMs Delay after most recent content change, in milliseconds. * @param durationMs Delay after most recent content change, in milliseconds.
* @see JobInfo#getTriggerContentUpdateDelay()
*/ */
public Builder setTriggerContentUpdateDelay(long durationMs) { public Builder setTriggerContentUpdateDelay(long durationMs) {
mTriggerContentUpdateDelay = durationMs; mTriggerContentUpdateDelay = durationMs;
@@ -1252,6 +1337,7 @@ public class JobInfo implements Parcelable {
* Set the maximum total delay (in milliseconds) that is allowed from the first * Set the maximum total delay (in milliseconds) that is allowed from the first
* time a content change is detected until the job is scheduled. * time a content change is detected until the job is scheduled.
* @param durationMs Delay after initial content change, in milliseconds. * @param durationMs Delay after initial content change, in milliseconds.
* @see JobInfo#getTriggerContentMaxDelay()
*/ */
public Builder setTriggerContentMaxDelay(long durationMs) { public Builder setTriggerContentMaxDelay(long durationMs) {
mTriggerContentMaxDelay = durationMs; mTriggerContentMaxDelay = durationMs;
@@ -1265,6 +1351,8 @@ public class JobInfo implements Parcelable {
* Setting this function on the builder with {@link #setMinimumLatency(long)} or * Setting this function on the builder with {@link #setMinimumLatency(long)} or
* {@link #setOverrideDeadline(long)} will result in an error. * {@link #setOverrideDeadline(long)} will result in an error.
* @param intervalMillis Millisecond interval for which this job will repeat. * @param intervalMillis Millisecond interval for which this job will repeat.
* @see JobInfo#getIntervalMillis()
* @see JobInfo#getFlexMillis()
*/ */
public Builder setPeriodic(long intervalMillis) { public Builder setPeriodic(long intervalMillis) {
return setPeriodic(intervalMillis, intervalMillis); return setPeriodic(intervalMillis, intervalMillis);
@@ -1278,6 +1366,8 @@ public class JobInfo implements Parcelable {
* @param flexMillis Millisecond flex for this job. Flex is clamped to be at least * @param flexMillis Millisecond flex for this job. Flex is clamped to be at least
* {@link #getMinFlexMillis()} or 5 percent of the period, whichever is * {@link #getMinFlexMillis()} or 5 percent of the period, whichever is
* higher. * higher.
* @see JobInfo#getIntervalMillis()
* @see JobInfo#getFlexMillis()
*/ */
public Builder setPeriodic(long intervalMillis, long flexMillis) { public Builder setPeriodic(long intervalMillis, long flexMillis) {
final long minPeriod = getMinPeriodMillis(); final long minPeriod = getMinPeriodMillis();
@@ -1309,6 +1399,7 @@ public class JobInfo implements Parcelable {
* {@link android.app.job.JobInfo.Builder#build()} is called. * {@link android.app.job.JobInfo.Builder#build()} is called.
* @param minLatencyMillis Milliseconds before which this job will not be considered for * @param minLatencyMillis Milliseconds before which this job will not be considered for
* execution. * execution.
* @see JobInfo#getMinLatencyMillis()
*/ */
public Builder setMinimumLatency(long minLatencyMillis) { public Builder setMinimumLatency(long minLatencyMillis) {
mMinLatencyMillis = minLatencyMillis; mMinLatencyMillis = minLatencyMillis;
@@ -1322,6 +1413,7 @@ public class JobInfo implements Parcelable {
* this property on a periodic job, doing so will throw an * this property on a periodic job, doing so will throw an
* {@link java.lang.IllegalArgumentException} when * {@link java.lang.IllegalArgumentException} when
* {@link android.app.job.JobInfo.Builder#build()} is called. * {@link android.app.job.JobInfo.Builder#build()} is called.
* @see JobInfo#getMaxExecutionDelayMillis()
*/ */
public Builder setOverrideDeadline(long maxExecutionDelayMillis) { public Builder setOverrideDeadline(long maxExecutionDelayMillis) {
mMaxExecutionDelayMillis = maxExecutionDelayMillis; mMaxExecutionDelayMillis = maxExecutionDelayMillis;
@@ -1341,6 +1433,8 @@ public class JobInfo implements Parcelable {
* mode. * mode.
* @param initialBackoffMillis Millisecond time interval to wait initially when job has * @param initialBackoffMillis Millisecond time interval to wait initially when job has
* failed. * failed.
* @see JobInfo#getInitialBackoffMillis()
* @see JobInfo#getBackoffPolicy()
*/ */
public Builder setBackoffCriteria(long initialBackoffMillis, public Builder setBackoffCriteria(long initialBackoffMillis,
@BackoffPolicy int backoffPolicy) { @BackoffPolicy int backoffPolicy) {
@@ -1371,6 +1465,7 @@ public class JobInfo implements Parcelable {
* *
* @param importantWhileForeground whether to relax doze restrictions for this job when the * @param importantWhileForeground whether to relax doze restrictions for this job when the
* app is in the foreground. False by default. * app is in the foreground. False by default.
* @see JobInfo#isImportantWhileForeground()
*/ */
public Builder setImportantWhileForeground(boolean importantWhileForeground) { public Builder setImportantWhileForeground(boolean importantWhileForeground) {
if (importantWhileForeground) { if (importantWhileForeground) {
@@ -1381,6 +1476,15 @@ public class JobInfo implements Parcelable {
return this; return this;
} }
/**
* @removed
* @deprecated replaced with {@link #setPrefetch(boolean)}
*/
@Deprecated
public Builder setIsPrefetch(boolean isPrefetch) {
return setPrefetch(isPrefetch);
}
/** /**
* Setting this to true indicates that this job is designed to prefetch * Setting this to true indicates that this job is designed to prefetch
* content that will make a material improvement to the experience of * content that will make a material improvement to the experience of
@@ -1393,12 +1497,13 @@ public class JobInfo implements Parcelable {
* network when there is a surplus of metered data available. The system * network when there is a surplus of metered data available. The system
* may also use this signal in combination with end user usage patterns * may also use this signal in combination with end user usage patterns
* to ensure data is prefetched before the user launches your app. * to ensure data is prefetched before the user launches your app.
* @see JobInfo#isPrefetch()
*/ */
public Builder setIsPrefetch(boolean isPrefetch) { public Builder setPrefetch(boolean prefetch) {
if (isPrefetch) { if (prefetch) {
mFlags |= FLAG_IS_PREFETCH; mFlags |= FLAG_PREFETCH;
} else { } else {
mFlags &= (~FLAG_IS_PREFETCH); mFlags &= (~FLAG_PREFETCH);
} }
return this; return this;
} }
@@ -1408,6 +1513,7 @@ public class JobInfo implements Parcelable {
* *
* @param isPersisted True to indicate that the job will be written to * @param isPersisted True to indicate that the job will be written to
* disk and loaded at boot. * disk and loaded at boot.
* @see JobInfo#isPersisted()
*/ */
@RequiresPermission(android.Manifest.permission.RECEIVE_BOOT_COMPLETED) @RequiresPermission(android.Manifest.permission.RECEIVE_BOOT_COMPLETED)
public Builder setPersisted(boolean isPersisted) { public Builder setPersisted(boolean isPersisted) {
@@ -1427,7 +1533,7 @@ public class JobInfo implements Parcelable {
"constraints, this is not allowed."); "constraints, this is not allowed.");
} }
// Check that network estimates require network type // Check that network estimates require network type
if (mNetworkBytes > 0 && mNetworkRequest == null) { if ((mNetworkDownloadBytes > 0 || mNetworkUploadBytes > 0) && mNetworkRequest == null) {
throw new IllegalArgumentException( throw new IllegalArgumentException(
"Can't provide estimated network usage without requiring a network"); "Can't provide estimated network usage without requiring a network");
} }

View File

@@ -16,6 +16,8 @@
package android.app.job; package android.app.job;
import static android.app.job.JobInfo.NETWORK_BYTES_UNKNOWN;
import android.annotation.BytesLong; import android.annotation.BytesLong;
import android.content.Intent; import android.content.Intent;
import android.os.Parcel; import android.os.Parcel;
@@ -28,7 +30,8 @@ import android.os.Parcelable;
*/ */
final public class JobWorkItem implements Parcelable { final public class JobWorkItem implements Parcelable {
final Intent mIntent; final Intent mIntent;
final long mNetworkBytes; final long mNetworkDownloadBytes;
final long mNetworkUploadBytes;
int mDeliveryCount; int mDeliveryCount;
int mWorkId; int mWorkId;
Object mGrants; Object mGrants;
@@ -41,22 +44,36 @@ final public class JobWorkItem implements Parcelable {
*/ */
public JobWorkItem(Intent intent) { public JobWorkItem(Intent intent) {
mIntent = intent; mIntent = intent;
mNetworkBytes = JobInfo.NETWORK_BYTES_UNKNOWN; mNetworkDownloadBytes = NETWORK_BYTES_UNKNOWN;
mNetworkUploadBytes = NETWORK_BYTES_UNKNOWN;
}
/**
* @deprecated replaced by {@link #JobWorkItem(Intent, long, long)}
* @removed
*/
@Deprecated
public JobWorkItem(Intent intent, @BytesLong long networkBytes) {
this(intent, networkBytes, NETWORK_BYTES_UNKNOWN);
} }
/** /**
* Create a new piece of work, which can be submitted to * Create a new piece of work, which can be submitted to
* {@link JobScheduler#enqueue JobScheduler.enqueue}. * {@link JobScheduler#enqueue JobScheduler.enqueue}.
* <p>
* See {@link JobInfo.Builder#setEstimatedNetworkBytes(long, long)} for
* details about how to estimate network traffic.
* *
* @param intent The general Intent describing this work. * @param intent The general Intent describing this work.
* @param networkBytes The estimated size of network traffic that will be * @param downloadBytes The estimated size of network traffic that will be
* performed by this job work item, in bytes. See * downloaded by this job work item, in bytes.
* {@link JobInfo.Builder#setEstimatedNetworkBytes(long)} for * @param uploadBytes The estimated size of network traffic that will be
* details about how to estimate. * uploaded by this job work item, in bytes.
*/ */
public JobWorkItem(Intent intent, @BytesLong long networkBytes) { public JobWorkItem(Intent intent, @BytesLong long downloadBytes, @BytesLong long uploadBytes) {
mIntent = intent; mIntent = intent;
mNetworkBytes = networkBytes; mNetworkDownloadBytes = downloadBytes;
mNetworkUploadBytes = uploadBytes;
} }
/** /**
@@ -67,14 +84,44 @@ final public class JobWorkItem implements Parcelable {
} }
/** /**
* Return the estimated size of network traffic that will be performed by * @deprecated replaced by {@link #getEstimatedNetworkDownloadBytes()} and
* {@link #getEstimatedNetworkUploadBytes()}.
* @removed
*/
@Deprecated
public @BytesLong long getEstimatedNetworkBytes() {
if (mNetworkDownloadBytes == NETWORK_BYTES_UNKNOWN
&& mNetworkUploadBytes == NETWORK_BYTES_UNKNOWN) {
return NETWORK_BYTES_UNKNOWN;
} else if (mNetworkDownloadBytes == NETWORK_BYTES_UNKNOWN) {
return mNetworkUploadBytes;
} else if (mNetworkUploadBytes == NETWORK_BYTES_UNKNOWN) {
return mNetworkDownloadBytes;
} else {
return mNetworkDownloadBytes + mNetworkUploadBytes;
}
}
/**
* Return the estimated size of download traffic that will be performed by
* this job, in bytes.
*
* @return Estimated size of download traffic, or
* {@link JobInfo#NETWORK_BYTES_UNKNOWN} when unknown.
*/
public @BytesLong long getEstimatedNetworkDownloadBytes() {
return mNetworkDownloadBytes;
}
/**
* Return the estimated size of upload traffic that will be performed by
* this job work item, in bytes. * this job work item, in bytes.
* *
* @return estimated size, or {@link JobInfo#NETWORK_BYTES_UNKNOWN} when * @return Estimated size of upload traffic, or
* unknown. * {@link JobInfo#NETWORK_BYTES_UNKNOWN} when unknown.
*/ */
public @BytesLong long getEstimatedNetworkBytes() { public @BytesLong long getEstimatedNetworkUploadBytes() {
return mNetworkBytes; return mNetworkUploadBytes;
} }
/** /**
@@ -128,9 +175,13 @@ final public class JobWorkItem implements Parcelable {
sb.append(mWorkId); sb.append(mWorkId);
sb.append(" intent="); sb.append(" intent=");
sb.append(mIntent); sb.append(mIntent);
if (mNetworkBytes != JobInfo.NETWORK_BYTES_UNKNOWN) { if (mNetworkDownloadBytes != NETWORK_BYTES_UNKNOWN) {
sb.append(" networkBytes="); sb.append(" downloadBytes=");
sb.append(mNetworkBytes); sb.append(mNetworkDownloadBytes);
}
if (mNetworkUploadBytes != NETWORK_BYTES_UNKNOWN) {
sb.append(" uploadBytes=");
sb.append(mNetworkUploadBytes);
} }
if (mDeliveryCount != 0) { if (mDeliveryCount != 0) {
sb.append(" dcount="); sb.append(" dcount=");
@@ -151,7 +202,8 @@ final public class JobWorkItem implements Parcelable {
} else { } else {
out.writeInt(0); out.writeInt(0);
} }
out.writeLong(mNetworkBytes); out.writeLong(mNetworkDownloadBytes);
out.writeLong(mNetworkUploadBytes);
out.writeInt(mDeliveryCount); out.writeInt(mDeliveryCount);
out.writeInt(mWorkId); out.writeInt(mWorkId);
} }
@@ -173,7 +225,8 @@ final public class JobWorkItem implements Parcelable {
} else { } else {
mIntent = null; mIntent = null;
} }
mNetworkBytes = in.readLong(); mNetworkDownloadBytes = in.readLong();
mNetworkUploadBytes = in.readLong();
mDeliveryCount = in.readInt(); mDeliveryCount = in.readInt();
mWorkId = in.readInt(); mWorkId = in.readInt();
} }

View File

@@ -160,7 +160,7 @@ public final class ConnectivityController extends StateController implements
private static boolean isRelaxedSatisfied(JobStatus jobStatus, Network network, private static boolean isRelaxedSatisfied(JobStatus jobStatus, Network network,
NetworkCapabilities capabilities, Constants constants) { NetworkCapabilities capabilities, Constants constants) {
// Only consider doing this for prefetching jobs // Only consider doing this for prefetching jobs
if ((jobStatus.getJob().getFlags() & JobInfo.FLAG_IS_PREFETCH) == 0) { if (!jobStatus.getJob().isPrefetch()) {
return false; return false;
} }