public final class JobSchedulerService extends SystemService implements StateChangedListener, JobCompletedListener
mJobs
need to lock on that object.
Any function with the suffix 'Locked' also needs to lock on mJobs
.Modifier and Type | Field and Description |
---|---|
static boolean |
DEBUG |
PHASE_ACTIVITY_MANAGER_READY, PHASE_BOOT_COMPLETED, PHASE_LOCK_SETTINGS_READY, PHASE_SYSTEM_SERVICES_READY, PHASE_THIRD_PARTY_APPS_CAN_START, PHASE_WAIT_FOR_DEFAULT_DISPLAY
Constructor and Description |
---|
JobSchedulerService(Context context)
Initializes the system service.
|
Modifier and Type | Method and Description |
---|---|
void |
cancelJob(int uid,
int jobId)
Entry point from client to cancel the job corresponding to the jobId provided.
|
void |
cancelJobsForUid(int uid,
boolean forceAll)
Entry point from client to cancel all jobs originating from their uid.
|
JobStore |
getJobStore() |
Object |
getLock() |
JobInfo |
getPendingJob(int uid,
int jobId) |
List<JobInfo> |
getPendingJobs(int uid) |
void |
onBootPhase(int phase)
Called on each phase of the boot process.
|
void |
onControllerStateChanged()
Posts a message to the
JobSchedulerService.JobHandler that
some controller's state has changed, so as to run through the list of jobs and start/stop
any that are eligible. |
void |
onDeviceIdleStateChanged(boolean deviceIdle) |
void |
onJobCompleted(JobStatus jobStatus,
boolean needsReschedule)
A job just finished executing.
|
void |
onRunJobNow(JobStatus jobStatus)
Called by the controller to notify the JobManager that regardless of the state of the task,
it must be run immediately.
|
void |
onStart()
Called when the dependencies listed in the @Service class-annotation are available
and after the chosen start phase.
|
void |
onStartUser(int userHandle)
Called when a new user is starting, for system services to initialize any per-user
state they maintain for running users.
|
void |
onStopUser(int userHandle)
Called when an existing user is stopping, for system services to finalize any per-user
state they maintain for running users.
|
void |
onUnlockUser(int userHandle)
Called when an existing user is unlocked.
|
int |
schedule(JobInfo job,
int uId)
Entry point from client to schedule the provided job.
|
int |
scheduleAsPackage(JobInfo job,
int uId,
String packageName,
int userId,
String tag) |
getBinderService, getContext, getLocalService, isSafeMode, onCleanupUser, onSwitchUser, publishBinderService, publishBinderService, publishLocalService
public static final boolean DEBUG
public JobSchedulerService(Context context)
Subclasses must define a single argument constructor that accepts the context and passes it to super.
context
- The system server context.public Object getLock()
public JobStore getJobStore()
public void onStartUser(int userHandle)
SystemService
onStartUser
in class SystemService
userHandle
- The identifier of the user.public void onUnlockUser(int userHandle)
SystemService
onUnlockUser
in class SystemService
userHandle
- The identifier of the user.public void onStopUser(int userHandle)
SystemService
onStopUser
in class SystemService
userHandle
- The identifier of the user.public int schedule(JobInfo job, int uId)
job
- JobInfo object containing execution parametersuId
- The package identifier of the application this job is for.JobScheduler#RESULT_*
return codes.public int scheduleAsPackage(JobInfo job, int uId, String packageName, int userId, String tag)
public JobInfo getPendingJob(int uid, int jobId)
public void cancelJobsForUid(int uid, boolean forceAll)
uid
- Uid to check against for removal of a job.forceAll
- If true, all jobs for the uid will be canceled; if false, only those
whose apps are stopped.public void cancelJob(int uid, int jobId)
uid
- Uid of the calling client.jobId
- Id of the job, provided at schedule-time.public void onDeviceIdleStateChanged(boolean deviceIdle)
onDeviceIdleStateChanged
in interface StateChangedListener
public void onStart()
SystemService
onStart
in class SystemService
public void onBootPhase(int phase)
SystemService
onBootPhase
in class SystemService
phase
- The current boot phase.public void onJobCompleted(JobStatus jobStatus, boolean needsReschedule)
JobStatus
from the store and depending on
whether we want to reschedule we readd it to the controllers.onJobCompleted
in interface JobCompletedListener
jobStatus
- Completed job.needsReschedule
- Whether the implementing class should reschedule this job.public void onControllerStateChanged()
JobSchedulerService.JobHandler
that
some controller's state has changed, so as to run through the list of jobs and start/stop
any that are eligible.onControllerStateChanged
in interface StateChangedListener
public void onRunJobNow(JobStatus jobStatus)
StateChangedListener
onRunJobNow
in interface StateChangedListener
jobStatus
- The state of the task which is to be run immediately. null
indicates to the scheduler that any ready jobs should be flushed.