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

Commit 7da13d7c authored by Dianne Hackborn's avatar Dianne Hackborn
Browse files

Add new "work queue" feature to JobScheduler.

This gives semantics similar to the start command
queue of services.

The implementation is currently lacking in URI permission
grant handling of the work intents; that will be coming
in a follow-up change.

This includes a first step of adjusting/fixing locking
within JobSchedulerService.  The JobServiceContext class
has a bunch of stuff it does that assumes it doesn't need
locking because it schedules the work on a handler.  However,
to be able to correctly implement the work finish flow (that
takes care of stopping the job when there is no more work),
we can't dispatch these asynchronously so need to get rid of
that and just do explicit locking.

The switch to explicit locking is half-way there (again the
remaining part will be a follow-on CL).  Right now we have
the locking, but still also the handler.  But it turns out
there were a number of things we were doing without a lock
held where we actually should have been holding a lock, so
this is better anyway.

Test: new tests added

Change-Id: Iebd098046209b28e60fd2f4d855d7f91cd3a8b03
parent 4a306894
Loading
Loading
Loading
Loading
+12 −0
Original line number Diff line number Diff line
@@ -6826,6 +6826,8 @@ package android.app.job {
  }
  public class JobParameters implements android.os.Parcelable {
    method public void completeWork(android.app.job.JobWorkItem);
    method public android.app.job.JobWorkItem dequeueWork();
    method public int describeContents();
    method public android.content.ClipData getClipData();
    method public int getClipGrantFlags();
@@ -6843,6 +6845,7 @@ package android.app.job {
    ctor public JobScheduler();
    method public abstract void cancel(int);
    method public abstract void cancelAll();
    method public abstract int enqueue(android.app.job.JobInfo, android.app.job.JobWorkItem);
    method public abstract java.util.List<android.app.job.JobInfo> getAllPendingJobs();
    method public abstract android.app.job.JobInfo getPendingJob(int);
    method public abstract int schedule(android.app.job.JobInfo);
@@ -6859,6 +6862,15 @@ package android.app.job {
    field public static final java.lang.String PERMISSION_BIND = "android.permission.BIND_JOB_SERVICE";
  }
  public final class JobWorkItem implements android.os.Parcelable {
    ctor public JobWorkItem(android.content.Intent);
    ctor public JobWorkItem(android.os.Parcel);
    method public int describeContents();
    method public android.content.Intent getIntent();
    method public void writeToParcel(android.os.Parcel, int);
    field public static final android.os.Parcelable.Creator<android.app.job.JobWorkItem> CREATOR;
  }
}
package android.app.usage {
+12 −0
Original line number Diff line number Diff line
@@ -7255,6 +7255,8 @@ package android.app.job {
  }
  public class JobParameters implements android.os.Parcelable {
    method public void completeWork(android.app.job.JobWorkItem);
    method public android.app.job.JobWorkItem dequeueWork();
    method public int describeContents();
    method public android.content.ClipData getClipData();
    method public int getClipGrantFlags();
@@ -7272,6 +7274,7 @@ package android.app.job {
    ctor public JobScheduler();
    method public abstract void cancel(int);
    method public abstract void cancelAll();
    method public abstract int enqueue(android.app.job.JobInfo, android.app.job.JobWorkItem);
    method public abstract java.util.List<android.app.job.JobInfo> getAllPendingJobs();
    method public abstract android.app.job.JobInfo getPendingJob(int);
    method public abstract int schedule(android.app.job.JobInfo);
@@ -7289,6 +7292,15 @@ package android.app.job {
    field public static final java.lang.String PERMISSION_BIND = "android.permission.BIND_JOB_SERVICE";
  }
  public final class JobWorkItem implements android.os.Parcelable {
    ctor public JobWorkItem(android.content.Intent);
    ctor public JobWorkItem(android.os.Parcel);
    method public int describeContents();
    method public android.content.Intent getIntent();
    method public void writeToParcel(android.os.Parcel, int);
    field public static final android.os.Parcelable.Creator<android.app.job.JobWorkItem> CREATOR;
  }
}
package android.app.usage {
+12 −0
Original line number Diff line number Diff line
@@ -6855,6 +6855,8 @@ package android.app.job {
  }
  public class JobParameters implements android.os.Parcelable {
    method public void completeWork(android.app.job.JobWorkItem);
    method public android.app.job.JobWorkItem dequeueWork();
    method public int describeContents();
    method public android.content.ClipData getClipData();
    method public int getClipGrantFlags();
@@ -6872,6 +6874,7 @@ package android.app.job {
    ctor public JobScheduler();
    method public abstract void cancel(int);
    method public abstract void cancelAll();
    method public abstract int enqueue(android.app.job.JobInfo, android.app.job.JobWorkItem);
    method public abstract java.util.List<android.app.job.JobInfo> getAllPendingJobs();
    method public abstract android.app.job.JobInfo getPendingJob(int);
    method public abstract int schedule(android.app.job.JobInfo);
@@ -6888,6 +6891,15 @@ package android.app.job {
    field public static final java.lang.String PERMISSION_BIND = "android.permission.BIND_JOB_SERVICE";
  }
  public final class JobWorkItem implements android.os.Parcelable {
    ctor public JobWorkItem(android.content.Intent);
    ctor public JobWorkItem(android.os.Parcel);
    method public int describeContents();
    method public android.content.Intent getIntent();
    method public void writeToParcel(android.os.Parcel, int);
    field public static final android.os.Parcelable.Creator<android.app.job.JobWorkItem> CREATOR;
  }
}
package android.app.usage {
+11 −0
Original line number Diff line number Diff line
@@ -20,6 +20,8 @@ package android.app;
import android.app.job.JobInfo;
import android.app.job.JobScheduler;
import android.app.job.IJobScheduler;
import android.app.job.JobWorkItem;
import android.content.Intent;
import android.os.RemoteException;

import java.util.List;
@@ -45,6 +47,15 @@ public class JobSchedulerImpl extends JobScheduler {
        }
    }

    @Override
    public int enqueue(JobInfo job, JobWorkItem work) {
        try {
            return mBinder.enqueue(job, work);
        } catch (RemoteException e) {
            return JobScheduler.RESULT_FAILURE;
        }
    }

    @Override
    public int scheduleAsPackage(JobInfo job, String packageName, int userId, String tag) {
        try {
+10 −0
Original line number Diff line number Diff line
@@ -16,6 +16,8 @@

package android.app.job;

import android.app.job.JobWorkItem;

/**
 * The server side of the JobScheduler IPC protocols.  The app-side implementation
 * invokes on this interface to indicate completion of the (asynchronous) instructions
@@ -42,6 +44,14 @@ interface IJobCallback {
     * @param reschedule Whether or not to reschedule this job.
     */
    void acknowledgeStopMessage(int jobId, boolean reschedule);
    /*
     * Called to deqeue next work item for the job.
     */
    JobWorkItem dequeueWork(int jobId);
    /*
     * Called to report that job has completed processing a work item.
     */
    boolean completeWork(int jobId, int workId);
    /*
     * Tell the job manager that the client is done with its execution, so that it can go on to
     * the next one and stop attributing wakelock time to us etc.
Loading