Fix the scheduling of the background dexopt job.

Before this change, when the background dexopt job finishes, it passes
true to jobFinished, which indicates that the job failed and should be
rescheduled.

This CL fixes the bug by always passing false instead. This is correct
because:
- If the job finishes normally, it should not be rescheduled.
- If the job is cancelled by the job scheduler, the job scheduler will
  ignore the jobFinished call. Instead, it will look at the return value
  of onStopJob, which is true.

Bug: 255943027
Test: Presubmit
Change-Id: Ifaabe452aa5fbde9319f84aa8d4e99d7d3350154
This commit is contained in:
Jiakai Zhang
2022-10-27 15:38:36 +01:00
parent 9b45e65e7c
commit 1ea1cf9c33
2 changed files with 6 additions and 6 deletions

View File

@@ -385,7 +385,7 @@ public final class BackgroundDexOptService {
job.jobFinished(params, !completed);
} else {
// Periodic job
job.jobFinished(params, true);
job.jobFinished(params, false /* reschedule */);
}
markDexOptCompleted();
}

View File

@@ -221,7 +221,7 @@ public final class BackgroundDexOptServiceUnitTest {
/* expectedReschedule= */ false, /* expectedStatus= */ STATUS_OK,
/* totalJobFinishedWithParams= */ 1, /* expectedSkippedPackage= */ null);
runFullJob(mJobServiceForIdle, mJobParametersForIdle,
/* expectedReschedule= */ true, /* expectedStatus= */ STATUS_OK,
/* expectedReschedule= */ false, /* expectedStatus= */ STATUS_OK,
/* totalJobFinishedWithParams= */ 1, /* expectedSkippedPackage= */ null);
}
@@ -239,7 +239,7 @@ public final class BackgroundDexOptServiceUnitTest {
assertThat(getFailedPackageNamesSecondary()).isEmpty();
runFullJob(mJobServiceForIdle, mJobParametersForIdle,
/* expectedReschedule= */ true, /* expectedStatus= */ STATUS_OK,
/* expectedReschedule= */ false, /* expectedStatus= */ STATUS_OK,
/* totalJobFinishedWithParams= */ 1, /* expectedSkippedPackage= */ PACKAGE_AAA);
assertThat(getFailedPackageNamesPrimary()).containsExactly(PACKAGE_AAA);
@@ -254,7 +254,7 @@ public final class BackgroundDexOptServiceUnitTest {
mDexOptResultForPackageAAA = PackageDexOptimizer.DEX_OPT_PERFORMED;
runFullJob(mJobServiceForIdle, mJobParametersForIdle,
/* expectedReschedule= */ true, /* expectedStatus= */ STATUS_OK,
/* expectedReschedule= */ false, /* expectedStatus= */ STATUS_OK,
/* totalJobFinishedWithParams= */ 2, /* expectedSkippedPackage= */ null);
assertThat(getFailedPackageNamesPrimary()).isEmpty();
@@ -391,7 +391,7 @@ public final class BackgroundDexOptServiceUnitTest {
mCancelThread.join(TEST_WAIT_TIMEOUT_MS);
// Always reschedule for periodic job
verify(mJobServiceForIdle).jobFinished(mJobParametersForIdle, true);
verify(mJobServiceForIdle).jobFinished(mJobParametersForIdle, false);
verifyLastControlDexOptBlockingCall(false);
}
@@ -419,7 +419,7 @@ public final class BackgroundDexOptServiceUnitTest {
mCancelThread.join(TEST_WAIT_TIMEOUT_MS);
// Always reschedule for periodic job
verify(mJobServiceForIdle).jobFinished(mJobParametersForIdle, true);
verify(mJobServiceForIdle).jobFinished(mJobParametersForIdle, false);
verify(mDexOptHelper, never()).controlDexOptBlocking(true);
}