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

Commit 8db0fc15 authored by Dianne Hackborn's avatar Dianne Hackborn
Browse files

More work on issue #26390151: Add new JobScheduler API...

...for monitoring content providers

We now have some delays before reporting URI changes, to allow
them to batch together.

Also clean up debug output, and fix some issues with how we
were managing the content observer state.

And while I am here, fix the device idle and app idle controllers
to no longer maintain their own list of jobs, but just directly
iterate over the JobStore.

Change-Id: If3fdff23c00c2f1b99901a9be096d851562d3439
parent b53a36b8
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -6313,6 +6313,8 @@ package android.app.job {
    method public static final long getMinimumPeriod();
    method public int getNetworkType();
    method public android.content.ComponentName getService();
    method public long getTriggerContentMaxDelay();
    method public long getTriggerContentUpdateDelay();
    method public android.app.job.JobInfo.TriggerContentUri[] getTriggerContentUris();
    method public boolean isPeriodic();
    method public boolean isPersisted();
@@ -6343,6 +6345,8 @@ 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 setTriggerContentMaxDelay(long);
    method public android.app.job.JobInfo.Builder setTriggerContentUpdateDelay(long);
  }
  public static final class JobInfo.TriggerContentUri implements android.os.Parcelable {
+4 −0
Original line number Diff line number Diff line
@@ -6581,6 +6581,8 @@ package android.app.job {
    method public static final long getMinimumPeriod();
    method public int getNetworkType();
    method public android.content.ComponentName getService();
    method public long getTriggerContentMaxDelay();
    method public long getTriggerContentUpdateDelay();
    method public android.app.job.JobInfo.TriggerContentUri[] getTriggerContentUris();
    method public boolean isPeriodic();
    method public boolean isPersisted();
@@ -6611,6 +6613,8 @@ 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 setTriggerContentMaxDelay(long);
    method public android.app.job.JobInfo.Builder setTriggerContentUpdateDelay(long);
  }
  public static final class JobInfo.TriggerContentUri implements android.os.Parcelable {
+4 −0
Original line number Diff line number Diff line
@@ -6317,6 +6317,8 @@ package android.app.job {
    method public static final long getMinimumPeriod();
    method public int getNetworkType();
    method public android.content.ComponentName getService();
    method public long getTriggerContentMaxDelay();
    method public long getTriggerContentUpdateDelay();
    method public android.app.job.JobInfo.TriggerContentUri[] getTriggerContentUris();
    method public boolean isPeriodic();
    method public boolean isPersisted();
@@ -6347,6 +6349,8 @@ 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 setTriggerContentMaxDelay(long);
    method public android.app.job.JobInfo.Builder setTriggerContentUpdateDelay(long);
  }
  public static final class JobInfo.TriggerContentUri implements android.os.Parcelable {
+47 −0
Original line number Diff line number Diff line
@@ -158,6 +158,8 @@ public class JobInfo implements Parcelable {
    private final boolean requireCharging;
    private final boolean requireDeviceIdle;
    private final TriggerContentUri[] triggerContentUris;
    private final long triggerContentUpdateDelay;
    private final long triggerContentMaxDelay;
    private final boolean hasEarlyConstraint;
    private final boolean hasLateConstraint;
    private final int networkType;
@@ -220,6 +222,22 @@ public class JobInfo implements Parcelable {
        return triggerContentUris;
    }

    /**
     * When triggering on content URI changes, this is the delay from when a change
     * is detected until the job is scheduled.
     */
    public long getTriggerContentUpdateDelay() {
        return triggerContentUpdateDelay;
    }

    /**
     * When triggering on content URI changes, this is the maximum delay we will
     * use before scheduling the job.
     */
    public long getTriggerContentMaxDelay() {
        return triggerContentMaxDelay;
    }

    /**
     * One of {@link android.app.job.JobInfo#NETWORK_TYPE_ANY},
     * {@link android.app.job.JobInfo#NETWORK_TYPE_NONE}, or
@@ -321,6 +339,8 @@ public class JobInfo implements Parcelable {
        requireCharging = in.readInt() == 1;
        requireDeviceIdle = in.readInt() == 1;
        triggerContentUris = in.createTypedArray(TriggerContentUri.CREATOR);
        triggerContentUpdateDelay = in.readLong();
        triggerContentMaxDelay = in.readLong();
        networkType = in.readInt();
        minLatencyMillis = in.readLong();
        maxExecutionDelayMillis = in.readLong();
@@ -344,6 +364,8 @@ public class JobInfo implements Parcelable {
        triggerContentUris = b.mTriggerContentUris != null
                ? b.mTriggerContentUris.toArray(new TriggerContentUri[b.mTriggerContentUris.size()])
                : null;
        triggerContentUpdateDelay = b.mTriggerContentUpdateDelay;
        triggerContentMaxDelay = b.mTriggerContentMaxDelay;
        networkType = b.mNetworkType;
        minLatencyMillis = b.mMinLatencyMillis;
        maxExecutionDelayMillis = b.mMaxExecutionDelayMillis;
@@ -371,6 +393,8 @@ public class JobInfo implements Parcelable {
        out.writeInt(requireCharging ? 1 : 0);
        out.writeInt(requireDeviceIdle ? 1 : 0);
        out.writeTypedArray(triggerContentUris, flags);
        out.writeLong(triggerContentUpdateDelay);
        out.writeLong(triggerContentMaxDelay);
        out.writeInt(networkType);
        out.writeLong(minLatencyMillis);
        out.writeLong(maxExecutionDelayMillis);
@@ -482,6 +506,8 @@ public class JobInfo implements Parcelable {
        private boolean mRequiresDeviceIdle;
        private int mNetworkType;
        private ArrayList<TriggerContentUri> mTriggerContentUris;
        private long mTriggerContentUpdateDelay = -1;
        private long mTriggerContentMaxDelay = -1;
        private boolean mIsPersisted;
        // One-off parameters.
        private long mMinLatencyMillis;
@@ -587,6 +613,27 @@ public class JobInfo implements Parcelable {
            return this;
        }

        /**
         * Set the delay (in milliseconds) from when a content change is detected until
         * 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.
         * @param durationMs Delay after most recent content change, in milliseconds.
         */
        public Builder setTriggerContentUpdateDelay(long durationMs) {
            mTriggerContentUpdateDelay = durationMs;
            return this;
        }

        /**
         * Set the maximum total delay (in milliseconds) that is allowed from the first
         * time a content change is detected until the job is scheduled.
         * @param durationMs Delay after initial content change, in milliseconds.
         */
        public Builder setTriggerContentMaxDelay(long durationMs) {
            mTriggerContentMaxDelay = durationMs;
            return this;
        }

        /**
         * Specify that this job should recur with the provided interval, not more than once per
         * period. You have no control over when within this interval this job will be executed,
+4 −0
Original line number Diff line number Diff line
@@ -257,6 +257,10 @@ public final class JobSchedulerService extends com.android.server.SystemService
        return mLock;
    }

    public JobStore getJobStore() {
        return mJobs;
    }

    @Override
    public void onStartUser(int userHandle) {
        mStartedUsers = ArrayUtils.appendInt(mStartedUsers, userHandle);
Loading