public class JobServiceContext extends IJobCallback.Stub implements ServiceConnection
JobSchedulerService
. To execute a job and to cancel a job.
- Execution of a new job is handled by the mAvailable
. This bit is flipped once when a
job lands, and again when it is complete.
- Cancelling is trickier, because there are also interactions from the client. It's possible
the JobServiceContext.JobServiceHandler
tries to process a
MSG_CANCEL
after the client has already finished. This is handled by having
JobServiceContext.JobServiceHandler.handleCancelH()
check whether
the context is still valid.
To mitigate this, tearing down the context removes all messages from the handler, including any
tardy MSG_CANCEL
s. Additionally, we avoid sending duplicate onStopJob()
calls to the client after they've specified jobFinished().Modifier and Type | Field and Description |
---|---|
static int |
NO_PREFERRED_UID |
Modifier and Type | Method and Description |
---|---|
void |
acknowledgeStartMessage(int jobId,
boolean ongoing) |
void |
acknowledgeStopMessage(int jobId,
boolean reschedule) |
void |
jobFinished(int jobId,
boolean reschedule) |
void |
onServiceConnected(ComponentName name,
IBinder service)
We acquire/release a wakelock on onServiceConnected/unbindService.
|
void |
onServiceDisconnected(ComponentName name)
If the client service crashes we reschedule this job and clean up.
|
public static final int NO_PREFERRED_UID
public void jobFinished(int jobId, boolean reschedule)
public void acknowledgeStopMessage(int jobId, boolean reschedule)
public void acknowledgeStartMessage(int jobId, boolean ongoing)
public void onServiceConnected(ComponentName name, IBinder service)
onServiceConnected
in interface ServiceConnection
name
- The concrete component name of the service that has been connected.service
- The IBinder of the Service's communication channel,public void onServiceDisconnected(ComponentName name)
onServiceDisconnected
in interface ServiceConnection
name
- The concrete component name of the service whose
connection has been lost.