Merge "Make sure to stop EJs when quota is finished." into tm-dev

This commit is contained in:
Kweku Adams 2022-04-01 01:02:15 +00:00 committed by Android (Google) Code Review
commit c3e62a40be
3 changed files with 34 additions and 12 deletions

View File

@ -1311,8 +1311,15 @@ public final class JobStatus {
if (mExpeditedQuotaApproved == state) {
return false;
}
final boolean wasReady = !state && isReady();
mExpeditedQuotaApproved = state;
updateExpeditedDependencies();
final boolean isReady = isReady();
if (wasReady && !isReady) {
mReasonReadyToUnready = JobParameters.STOP_REASON_QUOTA;
} else if (!wasReady && isReady) {
mReasonReadyToUnready = JobParameters.STOP_REASON_UNDEFINED;
}
return true;
}
@ -1326,8 +1333,15 @@ public final class JobStatus {
if (mExpeditedTareApproved == state) {
return false;
}
final boolean wasReady = !state && isReady();
mExpeditedTareApproved = state;
updateExpeditedDependencies();
final boolean isReady = isReady();
if (wasReady && !isReady) {
mReasonReadyToUnready = JobParameters.STOP_REASON_QUOTA;
} else if (!wasReady && isReady) {
mReasonReadyToUnready = JobParameters.STOP_REASON_UNDEFINED;
}
return true;
}

View File

@ -606,7 +606,7 @@ public final class QuotaController extends StateController {
final boolean isWithinQuota = isWithinQuotaLocked(jobStatus);
final boolean isWithinEJQuota =
jobStatus.isRequestedExpeditedJob() && isWithinEJQuotaLocked(jobStatus);
setConstraintSatisfied(jobStatus, nowElapsed, isWithinQuota || isWithinEJQuota);
setConstraintSatisfied(jobStatus, nowElapsed, isWithinQuota, isWithinEJQuota);
final boolean outOfEJQuota;
if (jobStatus.isRequestedExpeditedJob()) {
setExpeditedQuotaApproved(jobStatus, nowElapsed, isWithinEJQuota);
@ -1627,13 +1627,13 @@ public final class QuotaController extends StateController {
// An app in the ACTIVE bucket may be out of quota while the job could be in quota
// for some reason. Therefore, avoid setting the real value here and check each job
// individually.
if (setConstraintSatisfied(js, nowElapsed, isWithinEJQuota || realInQuota)) {
if (setConstraintSatisfied(js, nowElapsed, realInQuota, isWithinEJQuota)) {
changedJobs.add(js);
}
} else {
// This job is somehow exempted. Need to determine its own quota status.
if (setConstraintSatisfied(js, nowElapsed,
isWithinEJQuota || isWithinQuotaLocked(js))) {
isWithinQuotaLocked(js), isWithinEJQuota)) {
changedJobs.add(js);
}
}
@ -1676,7 +1676,7 @@ public final class QuotaController extends StateController {
isWithinEJQuota = false;
}
if (setConstraintSatisfied(jobStatus, mUpdateTimeElapsed,
isWithinEJQuota || isWithinQuotaLocked(jobStatus))) {
isWithinQuotaLocked(jobStatus), isWithinEJQuota)) {
changedJobs.add(jobStatus);
}
if (setExpeditedQuotaApproved(jobStatus, mUpdateTimeElapsed, isWithinEJQuota)) {
@ -1833,12 +1833,24 @@ public final class QuotaController extends StateController {
}
private boolean setConstraintSatisfied(@NonNull JobStatus jobStatus, long nowElapsed,
boolean isWithinQuota) {
if (!isWithinQuota && jobStatus.getWhenStandbyDeferred() == 0) {
boolean isWithinQuota, boolean isWithinEjQuota) {
final boolean isSatisfied;
if (jobStatus.startedAsExpeditedJob) {
// If the job started as an EJ, then we should only consider EJ quota for the constraint
// satisfaction.
isSatisfied = isWithinEjQuota;
} else if (mService.isCurrentlyRunningLocked(jobStatus)) {
// Job is running but didn't start as an EJ, so only the regular quota should be
// considered.
isSatisfied = isWithinQuota;
} else {
isSatisfied = isWithinEjQuota || isWithinQuota;
}
if (!isSatisfied && jobStatus.getWhenStandbyDeferred() == 0) {
// Mark that the job is being deferred due to buckets.
jobStatus.setWhenStandbyDeferred(nowElapsed);
}
return jobStatus.setQuotaConstraintSatisfied(nowElapsed, isWithinQuota);
return jobStatus.setQuotaConstraintSatisfied(nowElapsed, isSatisfied);
}
/**

View File

@ -528,7 +528,7 @@ public class TareController extends StateController {
@NonNull
private ActionBill getRunningBill(JobStatus jobStatus) {
// TODO: factor in network cost when available
if (jobStatus.shouldTreatAsExpeditedJob()) {
if (jobStatus.shouldTreatAsExpeditedJob() || jobStatus.startedAsExpeditedJob) {
if (jobStatus.getEffectivePriority() == JobInfo.PRIORITY_MAX) {
return BILL_JOB_RUNNING_MAX_EXPEDITED;
} else {
@ -636,10 +636,6 @@ public class TareController extends StateController {
return true;
}
if (mService.isCurrentlyRunningLocked(jobStatus)) {
if (jobStatus.isRequestedExpeditedJob()) {
return canAffordBillLocked(jobStatus, getRunningBill(jobStatus))
|| canAffordBillLocked(jobStatus, BILL_JOB_RUNNING_DEFAULT);
}
return canAffordBillLocked(jobStatus, getRunningBill(jobStatus));
}