Merge "Correctly reschedule failed periodic" into mnc-dr-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
40ec3a9246
@@ -443,13 +443,16 @@ public class JobSchedulerService extends com.android.server.SystemService
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A job is rescheduled with exponential back-off if the client requests this from their
|
* Reschedules the given job based on the job's backoff policy. It doesn't make sense to
|
||||||
* execution logic.
|
* specify an override deadline on a failed job (the failed job will run even though it's not
|
||||||
* A caveat is for idle-mode jobs, for which the idle-mode constraint will usurp the
|
* ready), so we reschedule it with {@link JobStatus#NO_LATEST_RUNTIME}, but specify that any
|
||||||
* timeliness of the reschedule. For an idle-mode job, no deadline is given.
|
* ready job with {@link JobStatus#numFailures} > 0 will be executed.
|
||||||
|
*
|
||||||
* @param failureToReschedule Provided job status that we will reschedule.
|
* @param failureToReschedule Provided job status that we will reschedule.
|
||||||
* @return A newly instantiated JobStatus with the same constraints as the last job except
|
* @return A newly instantiated JobStatus with the same constraints as the last job except
|
||||||
* with adjusted timing constraints.
|
* with adjusted timing constraints.
|
||||||
|
*
|
||||||
|
* @see JobHandler#maybeQueueReadyJobsForExecutionLockedH
|
||||||
*/
|
*/
|
||||||
private JobStatus getRescheduleJobForFailure(JobStatus failureToReschedule) {
|
private JobStatus getRescheduleJobForFailure(JobStatus failureToReschedule) {
|
||||||
final long elapsedNowMillis = SystemClock.elapsedRealtime();
|
final long elapsedNowMillis = SystemClock.elapsedRealtime();
|
||||||
@@ -479,8 +482,9 @@ public class JobSchedulerService extends com.android.server.SystemService
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called after a periodic has executed so we can to re-add it. We take the last execution time
|
* Called after a periodic has executed so we can reschedule it. We take the last execution
|
||||||
* of the job to be the time of completion (i.e. the time at which this function is called).
|
* time of the job to be the time of completion (i.e. the time at which this function is
|
||||||
|
* called).
|
||||||
* This could be inaccurate b/c the job can run for as long as
|
* This could be inaccurate b/c the job can run for as long as
|
||||||
* {@link com.android.server.job.JobServiceContext#EXECUTING_TIMESLICE_MILLIS}, but will lead
|
* {@link com.android.server.job.JobServiceContext#EXECUTING_TIMESLICE_MILLIS}, but will lead
|
||||||
* to underscheduling at least, rather than if we had taken the last execution time to be the
|
* to underscheduling at least, rather than if we had taken the last execution time to be the
|
||||||
@@ -491,7 +495,12 @@ public class JobSchedulerService extends com.android.server.SystemService
|
|||||||
private JobStatus getRescheduleJobForPeriodic(JobStatus periodicToReschedule) {
|
private JobStatus getRescheduleJobForPeriodic(JobStatus periodicToReschedule) {
|
||||||
final long elapsedNow = SystemClock.elapsedRealtime();
|
final long elapsedNow = SystemClock.elapsedRealtime();
|
||||||
// Compute how much of the period is remaining.
|
// Compute how much of the period is remaining.
|
||||||
long runEarly = Math.max(periodicToReschedule.getLatestRunTimeElapsed() - elapsedNow, 0);
|
long runEarly = 0L;
|
||||||
|
|
||||||
|
// If this periodic was rescheduled it won't have a deadline.
|
||||||
|
if (periodicToReschedule.hasDeadlineConstraint()) {
|
||||||
|
runEarly = Math.max(periodicToReschedule.getLatestRunTimeElapsed() - elapsedNow, 0L);
|
||||||
|
}
|
||||||
long newEarliestRunTimeElapsed = elapsedNow + runEarly;
|
long newEarliestRunTimeElapsed = elapsedNow + runEarly;
|
||||||
long period = periodicToReschedule.getJob().getIntervalMillis();
|
long period = periodicToReschedule.getJob().getIntervalMillis();
|
||||||
long newLatestRuntimeElapsed = newEarliestRunTimeElapsed + period;
|
long newLatestRuntimeElapsed = newEarliestRunTimeElapsed + period;
|
||||||
|
|||||||
@@ -68,7 +68,7 @@ public class JobServiceContext extends IJobCallback.Stub implements ServiceConne
|
|||||||
private static final int defaultMaxActiveJobsPerService =
|
private static final int defaultMaxActiveJobsPerService =
|
||||||
ActivityManager.isLowRamDeviceStatic() ? 1 : 3;
|
ActivityManager.isLowRamDeviceStatic() ? 1 : 3;
|
||||||
/** Amount of time a job is allowed to execute for before being considered timed-out. */
|
/** Amount of time a job is allowed to execute for before being considered timed-out. */
|
||||||
private static final long EXECUTING_TIMESLICE_MILLIS = 10 * 60 * 1000;
|
private static final long EXECUTING_TIMESLICE_MILLIS = 10 * 60 * 1000; // 10mins.
|
||||||
/** Amount of time the JobScheduler will wait for a response from an app for a message. */
|
/** Amount of time the JobScheduler will wait for a response from an app for a message. */
|
||||||
private static final long OP_TIMEOUT_MILLIS = 8 * 1000;
|
private static final long OP_TIMEOUT_MILLIS = 8 * 1000;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user