Merge "Don't back off for first few system stops." into udc-dev am: 0f26a22cdb
Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/23249503 Change-Id: I01d91a3f729169ebbaeaf7f6be3a33b55df5f119 Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
@@ -2600,10 +2600,14 @@ public class JobSchedulerService extends com.android.server.SystemService
|
|||||||
} else {
|
} else {
|
||||||
numSystemStops++;
|
numSystemStops++;
|
||||||
}
|
}
|
||||||
final int backoffAttempts = Math.max(1,
|
final int backoffAttempts =
|
||||||
numFailures + numSystemStops / mConstants.SYSTEM_STOP_TO_FAILURE_RATIO);
|
numFailures + numSystemStops / mConstants.SYSTEM_STOP_TO_FAILURE_RATIO;
|
||||||
long delayMillis;
|
final long earliestRuntimeMs;
|
||||||
|
|
||||||
|
if (backoffAttempts == 0) {
|
||||||
|
earliestRuntimeMs = JobStatus.NO_EARLIEST_RUNTIME;
|
||||||
|
} else {
|
||||||
|
long delayMillis;
|
||||||
switch (job.getBackoffPolicy()) {
|
switch (job.getBackoffPolicy()) {
|
||||||
case JobInfo.BACKOFF_POLICY_LINEAR: {
|
case JobInfo.BACKOFF_POLICY_LINEAR: {
|
||||||
long backoff = initialBackoffMillis;
|
long backoff = initialBackoffMillis;
|
||||||
@@ -2611,23 +2615,28 @@ public class JobSchedulerService extends com.android.server.SystemService
|
|||||||
backoff = mConstants.MIN_LINEAR_BACKOFF_TIME_MS;
|
backoff = mConstants.MIN_LINEAR_BACKOFF_TIME_MS;
|
||||||
}
|
}
|
||||||
delayMillis = backoff * backoffAttempts;
|
delayMillis = backoff * backoffAttempts;
|
||||||
} break;
|
}
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
if (DEBUG) {
|
if (DEBUG) {
|
||||||
Slog.v(TAG, "Unrecognised back-off policy, defaulting to exponential.");
|
Slog.v(TAG, "Unrecognised back-off policy, defaulting to exponential.");
|
||||||
}
|
}
|
||||||
|
// Intentional fallthrough.
|
||||||
case JobInfo.BACKOFF_POLICY_EXPONENTIAL: {
|
case JobInfo.BACKOFF_POLICY_EXPONENTIAL: {
|
||||||
long backoff = initialBackoffMillis;
|
long backoff = initialBackoffMillis;
|
||||||
if (backoff < mConstants.MIN_EXP_BACKOFF_TIME_MS) {
|
if (backoff < mConstants.MIN_EXP_BACKOFF_TIME_MS) {
|
||||||
backoff = mConstants.MIN_EXP_BACKOFF_TIME_MS;
|
backoff = mConstants.MIN_EXP_BACKOFF_TIME_MS;
|
||||||
}
|
}
|
||||||
delayMillis = (long) Math.scalb(backoff, backoffAttempts - 1);
|
delayMillis = (long) Math.scalb(backoff, backoffAttempts - 1);
|
||||||
} break;
|
}
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
delayMillis =
|
delayMillis =
|
||||||
Math.min(delayMillis, JobInfo.MAX_BACKOFF_DELAY_MILLIS);
|
Math.min(delayMillis, JobInfo.MAX_BACKOFF_DELAY_MILLIS);
|
||||||
|
earliestRuntimeMs = elapsedNowMillis + delayMillis;
|
||||||
|
}
|
||||||
JobStatus newJob = new JobStatus(failureToReschedule,
|
JobStatus newJob = new JobStatus(failureToReschedule,
|
||||||
elapsedNowMillis + delayMillis,
|
earliestRuntimeMs,
|
||||||
JobStatus.NO_LATEST_RUNTIME, numFailures, numSystemStops,
|
JobStatus.NO_LATEST_RUNTIME, numFailures, numSystemStops,
|
||||||
failureToReschedule.getLastSuccessfulRunTime(), sSystemClock.millis(),
|
failureToReschedule.getLastSuccessfulRunTime(), sSystemClock.millis(),
|
||||||
failureToReschedule.getCumulativeExecutionTimeMs());
|
failureToReschedule.getCumulativeExecutionTimeMs());
|
||||||
|
|||||||
@@ -402,13 +402,15 @@ public class JobSchedulerServiceTest {
|
|||||||
JobStatus rescheduledJob = mService.getRescheduleJobForFailureLocked(originalJob,
|
JobStatus rescheduledJob = mService.getRescheduleJobForFailureLocked(originalJob,
|
||||||
JobParameters.STOP_REASON_DEVICE_STATE,
|
JobParameters.STOP_REASON_DEVICE_STATE,
|
||||||
JobParameters.INTERNAL_STOP_REASON_DEVICE_THERMAL);
|
JobParameters.INTERNAL_STOP_REASON_DEVICE_THERMAL);
|
||||||
assertEquals(nowElapsed + initialBackoffMs, rescheduledJob.getEarliestRunTime());
|
assertEquals(JobStatus.NO_EARLIEST_RUNTIME, rescheduledJob.getEarliestRunTime());
|
||||||
assertEquals(JobStatus.NO_LATEST_RUNTIME, rescheduledJob.getLatestRunTimeElapsed());
|
assertEquals(JobStatus.NO_LATEST_RUNTIME, rescheduledJob.getLatestRunTimeElapsed());
|
||||||
|
|
||||||
// failure = 0, systemStop = 2
|
// failure = 0, systemStop = 2
|
||||||
rescheduledJob = mService.getRescheduleJobForFailureLocked(rescheduledJob,
|
rescheduledJob = mService.getRescheduleJobForFailureLocked(rescheduledJob,
|
||||||
JobParameters.STOP_REASON_DEVICE_STATE,
|
JobParameters.STOP_REASON_DEVICE_STATE,
|
||||||
JobParameters.INTERNAL_STOP_REASON_PREEMPT);
|
JobParameters.INTERNAL_STOP_REASON_PREEMPT);
|
||||||
|
assertEquals(JobStatus.NO_EARLIEST_RUNTIME, rescheduledJob.getEarliestRunTime());
|
||||||
|
assertEquals(JobStatus.NO_LATEST_RUNTIME, rescheduledJob.getLatestRunTimeElapsed());
|
||||||
// failure = 0, systemStop = 3
|
// failure = 0, systemStop = 3
|
||||||
rescheduledJob = mService.getRescheduleJobForFailureLocked(rescheduledJob,
|
rescheduledJob = mService.getRescheduleJobForFailureLocked(rescheduledJob,
|
||||||
JobParameters.STOP_REASON_CONSTRAINT_CHARGING,
|
JobParameters.STOP_REASON_CONSTRAINT_CHARGING,
|
||||||
|
|||||||
Reference in New Issue
Block a user