Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit b39ee5ed authored by Dianne Hackborn's avatar Dianne Hackborn Committed by Android (Google) Code Review
Browse files

Merge "Implement transient extras for jobs."

parents 156cc29a ba60473a
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -6239,6 +6239,7 @@ package android.app.job {
    method public long getMinLatencyMillis();
    method public int getNetworkType();
    method public android.content.ComponentName getService();
    method public android.os.Bundle getTransientExtras();
    method public android.app.job.JobInfo.TriggerContentUri[] getTriggerContentUris();
    method public boolean isPeriodic();
    method public boolean isPersisted();
@@ -6271,6 +6272,7 @@ package android.app.job {
    method public android.app.job.JobInfo.Builder setRequiredNetworkType(int);
    method public android.app.job.JobInfo.Builder setRequiresCharging(boolean);
    method public android.app.job.JobInfo.Builder setRequiresDeviceIdle(boolean);
    method public android.app.job.JobInfo.Builder setTransientExtras(android.os.Bundle);
  }
  public static final class JobInfo.TriggerContentUri implements android.os.Parcelable {
@@ -6287,6 +6289,7 @@ package android.app.job {
    method public int describeContents();
    method public android.os.PersistableBundle getExtras();
    method public int getJobId();
    method public android.os.Bundle getTransientExtras();
    method public java.lang.String[] getTriggeredContentAuthorities();
    method public android.net.Uri[] getTriggeredContentUris();
    method public boolean isOverrideDeadlineExpired();
@@ -28309,6 +28312,7 @@ package android.os {
    ctor public Bundle(android.os.Bundle);
    ctor public Bundle(android.os.PersistableBundle);
    method public java.lang.Object clone();
    method public android.os.Bundle deepcopy();
    method public int describeContents();
    method public android.os.IBinder getBinder(java.lang.String);
    method public android.os.Bundle getBundle(java.lang.String);
@@ -29017,6 +29021,7 @@ package android.os {
    ctor public PersistableBundle(int);
    ctor public PersistableBundle(android.os.PersistableBundle);
    method public java.lang.Object clone();
    method public android.os.PersistableBundle deepcopy();
    method public int describeContents();
    method public android.os.PersistableBundle getPersistableBundle(java.lang.String);
    method public void putPersistableBundle(java.lang.String, android.os.PersistableBundle);
+5 −0
Original line number Diff line number Diff line
@@ -6497,6 +6497,7 @@ package android.app.job {
    method public long getMinLatencyMillis();
    method public int getNetworkType();
    method public android.content.ComponentName getService();
    method public android.os.Bundle getTransientExtras();
    method public android.app.job.JobInfo.TriggerContentUri[] getTriggerContentUris();
    method public boolean isPeriodic();
    method public boolean isPersisted();
@@ -6529,6 +6530,7 @@ package android.app.job {
    method public android.app.job.JobInfo.Builder setRequiredNetworkType(int);
    method public android.app.job.JobInfo.Builder setRequiresCharging(boolean);
    method public android.app.job.JobInfo.Builder setRequiresDeviceIdle(boolean);
    method public android.app.job.JobInfo.Builder setTransientExtras(android.os.Bundle);
  }
  public static final class JobInfo.TriggerContentUri implements android.os.Parcelable {
@@ -6545,6 +6547,7 @@ package android.app.job {
    method public int describeContents();
    method public android.os.PersistableBundle getExtras();
    method public int getJobId();
    method public android.os.Bundle getTransientExtras();
    method public java.lang.String[] getTriggeredContentAuthorities();
    method public android.net.Uri[] getTriggeredContentUris();
    method public boolean isOverrideDeadlineExpired();
@@ -30595,6 +30598,7 @@ package android.os {
    ctor public Bundle(android.os.Bundle);
    ctor public Bundle(android.os.PersistableBundle);
    method public java.lang.Object clone();
    method public android.os.Bundle deepcopy();
    method public int describeContents();
    method public android.os.IBinder getBinder(java.lang.String);
    method public android.os.Bundle getBundle(java.lang.String);
@@ -31303,6 +31307,7 @@ package android.os {
    ctor public PersistableBundle(int);
    ctor public PersistableBundle(android.os.PersistableBundle);
    method public java.lang.Object clone();
    method public android.os.PersistableBundle deepcopy();
    method public int describeContents();
    method public android.os.PersistableBundle getPersistableBundle(java.lang.String);
    method public void putPersistableBundle(java.lang.String, android.os.PersistableBundle);
+5 −0
Original line number Diff line number Diff line
@@ -6241,6 +6241,7 @@ package android.app.job {
    method public long getMinLatencyMillis();
    method public int getNetworkType();
    method public android.content.ComponentName getService();
    method public android.os.Bundle getTransientExtras();
    method public android.app.job.JobInfo.TriggerContentUri[] getTriggerContentUris();
    method public boolean isPeriodic();
    method public boolean isPersisted();
@@ -6273,6 +6274,7 @@ package android.app.job {
    method public android.app.job.JobInfo.Builder setRequiredNetworkType(int);
    method public android.app.job.JobInfo.Builder setRequiresCharging(boolean);
    method public android.app.job.JobInfo.Builder setRequiresDeviceIdle(boolean);
    method public android.app.job.JobInfo.Builder setTransientExtras(android.os.Bundle);
  }
  public static final class JobInfo.TriggerContentUri implements android.os.Parcelable {
@@ -6289,6 +6291,7 @@ package android.app.job {
    method public int describeContents();
    method public android.os.PersistableBundle getExtras();
    method public int getJobId();
    method public android.os.Bundle getTransientExtras();
    method public java.lang.String[] getTriggeredContentAuthorities();
    method public android.net.Uri[] getTriggeredContentUris();
    method public boolean isOverrideDeadlineExpired();
@@ -28318,6 +28321,7 @@ package android.os {
    ctor public Bundle(android.os.Bundle);
    ctor public Bundle(android.os.PersistableBundle);
    method public java.lang.Object clone();
    method public android.os.Bundle deepcopy();
    method public int describeContents();
    method public android.os.IBinder getBinder(java.lang.String);
    method public android.os.Bundle getBundle(java.lang.String);
@@ -29026,6 +29030,7 @@ package android.os {
    ctor public PersistableBundle(int);
    ctor public PersistableBundle(android.os.PersistableBundle);
    method public java.lang.Object clone();
    method public android.os.PersistableBundle deepcopy();
    method public int describeContents();
    method public android.os.PersistableBundle getPersistableBundle(java.lang.String);
    method public void putPersistableBundle(java.lang.String, android.os.PersistableBundle);
+29 −2
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@ import android.annotation.NonNull;
import android.annotation.Nullable;
import android.content.ComponentName;
import android.net.Uri;
import android.os.Bundle;
import android.os.Parcel;
import android.os.Parcelable;
import android.os.PersistableBundle;
@@ -85,6 +86,7 @@ public class JobInfo implements Parcelable {

    private final int jobId;
    private final PersistableBundle extras;
    private final Bundle transientExtras;
    private final ComponentName service;
    private final boolean requireCharging;
    private final boolean requireDeviceIdle;
@@ -116,6 +118,14 @@ public class JobInfo implements Parcelable {
        return extras;
    }

    /**
     * Bundle of transient extras which are returned to your application at execution time,
     * but not persisted by the system.
     */
    public Bundle getTransientExtras() {
        return transientExtras;
    }

    /**
     * Name of the service endpoint that will be called back into by the JobScheduler.
     */
@@ -247,6 +257,7 @@ public class JobInfo implements Parcelable {
    private JobInfo(Parcel in) {
        jobId = in.readInt();
        extras = in.readPersistableBundle();
        transientExtras = in.readBundle();
        service = in.readParcelable(null);
        requireCharging = in.readInt() == 1;
        requireDeviceIdle = in.readInt() == 1;
@@ -267,7 +278,8 @@ public class JobInfo implements Parcelable {

    private JobInfo(JobInfo.Builder b) {
        jobId = b.mJobId;
        extras = b.mExtras;
        extras = b.mExtras.deepcopy();
        transientExtras = b.mTransientExtras.deepcopy();
        service = b.mJobService;
        requireCharging = b.mRequiresCharging;
        requireDeviceIdle = b.mRequiresDeviceIdle;
@@ -297,6 +309,7 @@ public class JobInfo implements Parcelable {
    public void writeToParcel(Parcel out, int flags) {
        out.writeInt(jobId);
        out.writePersistableBundle(extras);
        out.writeBundle(transientExtras);
        out.writeParcelable(service, flags);
        out.writeInt(requireCharging ? 1 : 0);
        out.writeInt(requireDeviceIdle ? 1 : 0);
@@ -405,6 +418,7 @@ public class JobInfo implements Parcelable {
    public static final class Builder {
        private int mJobId;
        private PersistableBundle mExtras = PersistableBundle.EMPTY;
        private Bundle mTransientExtras = Bundle.EMPTY;
        private ComponentName mJobService;
        private int mPriority;
        // Requirements.
@@ -457,6 +471,16 @@ public class JobInfo implements Parcelable {
            return this;
        }

        /**
         * Set optional transient extras. This is incompatible with jobs that are also
         * persisted with {@link #setPersisted(boolean)}; mixing the two is not allowed.
         * @param extras Bundle containing extras you want the scheduler to hold on to for you.
         */
        public Builder setTransientExtras(Bundle extras) {
            mTransientExtras = extras;
            return this;
        }

        /**
         * Set some description of the kind of network type your job needs to have.
         * Not calling this function means the network is not necessary, as the default is
@@ -616,7 +640,6 @@ public class JobInfo implements Parcelable {
                throw new IllegalArgumentException("You're trying to build a job with no " +
                        "constraints, this is not allowed.");
            }
            mExtras = new PersistableBundle(mExtras);  // Make our own copy.
            // Check that a deadline was not set on a periodic job.
            if (mIsPeriodic && (mMaxExecutionDelayMillis != 0L)) {
                throw new IllegalArgumentException("Can't call setOverrideDeadline() on a " +
@@ -634,6 +657,10 @@ public class JobInfo implements Parcelable {
                throw new IllegalArgumentException("Can't call addTriggerContentUri() on a " +
                        "persisted job");
            }
            if (mIsPersisted && !mTransientExtras.isEmpty()) {
                throw new IllegalArgumentException("Can't call setTransientExtras() on a " +
                        "persisted job");
            }
            if (mBackoffPolicySet && mRequiresDeviceIdle) {
                throw new IllegalArgumentException("An idle mode job will not respect any" +
                        " back-off policy, so calling setBackoffCriteria with" +
+15 −1
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@ package android.app.job;

import android.app.job.IJobCallback;
import android.net.Uri;
import android.os.Bundle;
import android.os.IBinder;
import android.os.Parcel;
import android.os.Parcelable;
@@ -42,6 +43,7 @@ public class JobParameters implements Parcelable {

    private final int jobId;
    private final PersistableBundle extras;
    private final Bundle transientExtras;
    private final IBinder callback;
    private final boolean overrideDeadlineExpired;
    private final Uri[] mTriggeredContentUris;
@@ -51,10 +53,11 @@ public class JobParameters implements Parcelable {

    /** @hide */
    public JobParameters(IBinder callback, int jobId, PersistableBundle extras,
                boolean overrideDeadlineExpired, Uri[] triggeredContentUris,
            Bundle transientExtras, boolean overrideDeadlineExpired, Uri[] triggeredContentUris,
            String[] triggeredContentAuthorities) {
        this.jobId = jobId;
        this.extras = extras;
        this.transientExtras = transientExtras;
        this.callback = callback;
        this.overrideDeadlineExpired = overrideDeadlineExpired;
        this.mTriggeredContentUris = triggeredContentUris;
@@ -85,6 +88,15 @@ public class JobParameters implements Parcelable {
        return extras;
    }

    /**
     * @return The transient extras you passed in when constructing this job with
     * {@link android.app.job.JobInfo.Builder#setTransientExtras(android.os.Bundle)}. This will
     * never be null. If you did not set any extras this will be an empty bundle.
     */
    public Bundle getTransientExtras() {
        return transientExtras;
    }

    /**
     * For jobs with {@link android.app.job.JobInfo.Builder#setOverrideDeadline(long)} set, this
     * provides an easy way to tell whether the job is being executed due to the deadline
@@ -127,6 +139,7 @@ public class JobParameters implements Parcelable {
    private JobParameters(Parcel in) {
        jobId = in.readInt();
        extras = in.readPersistableBundle();
        transientExtras = in.readBundle();
        callback = in.readStrongBinder();
        overrideDeadlineExpired = in.readInt() == 1;
        mTriggeredContentUris = in.createTypedArray(Uri.CREATOR);
@@ -148,6 +161,7 @@ public class JobParameters implements Parcelable {
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeInt(jobId);
        dest.writePersistableBundle(extras);
        dest.writeBundle(transientExtras);
        dest.writeStrongBinder(callback);
        dest.writeInt(overrideDeadlineExpired ? 1 : 0);
        dest.writeTypedArray(mTriggeredContentUris, flags);
Loading