Merge "Limit min runtime for downgraded EJs."

This commit is contained in:
TreeHugger Robot
2022-02-02 21:57:45 +00:00
committed by Android (Google) Code Review
2 changed files with 44 additions and 1 deletions

View File

@@ -2768,7 +2768,7 @@ public class JobSchedulerService extends com.android.server.SystemService
return job.getEffectiveStandbyBucket() != RESTRICTED_INDEX
? mConstants.RUNTIME_MIN_EJ_GUARANTEE_MS
: Math.min(mConstants.RUNTIME_MIN_EJ_GUARANTEE_MS, 5 * MINUTE_IN_MILLIS);
} else if (job.getEffectivePriority() == JobInfo.PRIORITY_HIGH) {
} else if (job.getEffectivePriority() >= JobInfo.PRIORITY_HIGH) {
return mConstants.RUNTIME_MIN_HIGH_PRIORITY_GUARANTEE_MS;
} else {
return mConstants.RUNTIME_MIN_GUARANTEE_MS;

View File

@@ -204,6 +204,49 @@ public class JobSchedulerServiceTest {
jobInfoBuilder.build(), callingUid, "com.android.test", 0, testTag);
}
@Test
public void testGetMinJobExecutionGuaranteeMs() {
JobStatus ejMax = createJobStatus("testGetMinJobExecutionGuaranteeMs",
createJobInfo(1).setExpedited(true));
JobStatus ejHigh = createJobStatus("testGetMinJobExecutionGuaranteeMs",
createJobInfo(2).setExpedited(true).setPriority(JobInfo.PRIORITY_HIGH));
JobStatus ejMaxDowngraded = createJobStatus("testGetMinJobExecutionGuaranteeMs",
createJobInfo(3).setExpedited(true));
JobStatus ejHighDowngraded = createJobStatus("testGetMinJobExecutionGuaranteeMs",
createJobInfo(4).setExpedited(true).setPriority(JobInfo.PRIORITY_HIGH));
JobStatus jobHigh = createJobStatus("testGetMinJobExecutionGuaranteeMs",
createJobInfo(5).setPriority(JobInfo.PRIORITY_HIGH));
JobStatus jobDef = createJobStatus("testGetMinJobExecutionGuaranteeMs",
createJobInfo(6));
spyOn(ejMax);
spyOn(ejHigh);
spyOn(ejMaxDowngraded);
spyOn(ejHighDowngraded);
spyOn(jobHigh);
spyOn(jobDef);
when(ejMax.shouldTreatAsExpeditedJob()).thenReturn(true);
when(ejHigh.shouldTreatAsExpeditedJob()).thenReturn(true);
when(ejMaxDowngraded.shouldTreatAsExpeditedJob()).thenReturn(false);
when(ejHighDowngraded.shouldTreatAsExpeditedJob()).thenReturn(false);
when(jobHigh.shouldTreatAsExpeditedJob()).thenReturn(false);
when(jobDef.shouldTreatAsExpeditedJob()).thenReturn(false);
assertEquals(mService.mConstants.RUNTIME_MIN_EJ_GUARANTEE_MS,
mService.getMinJobExecutionGuaranteeMs(ejMax));
assertEquals(mService.mConstants.RUNTIME_MIN_EJ_GUARANTEE_MS,
mService.getMinJobExecutionGuaranteeMs(ejHigh));
assertEquals(mService.mConstants.RUNTIME_MIN_HIGH_PRIORITY_GUARANTEE_MS,
mService.getMinJobExecutionGuaranteeMs(ejMaxDowngraded));
assertEquals(mService.mConstants.RUNTIME_MIN_HIGH_PRIORITY_GUARANTEE_MS,
mService.getMinJobExecutionGuaranteeMs(ejHighDowngraded));
assertEquals(mService.mConstants.RUNTIME_MIN_HIGH_PRIORITY_GUARANTEE_MS,
mService.getMinJobExecutionGuaranteeMs(jobHigh));
assertEquals(mService.mConstants.RUNTIME_MIN_GUARANTEE_MS,
mService.getMinJobExecutionGuaranteeMs(jobDef));
}
/**
* Confirm that {@link JobSchedulerService#getRescheduleJobForPeriodic(JobStatus)} returns a job
* with the correct delay and deadline constraints if the periodic job is scheduled with the