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

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/17527465

Change-Id: Ib232e97a11b78e8d3a5994b251d306d049887a44
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
Kweku Adams
2022-04-01 01:54:06 +00:00
committed by Automerger Merge Worker
3 changed files with 34 additions and 12 deletions

View File

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

View File

@@ -606,7 +606,7 @@ public final class QuotaController extends StateController {
final boolean isWithinQuota = isWithinQuotaLocked(jobStatus); final boolean isWithinQuota = isWithinQuotaLocked(jobStatus);
final boolean isWithinEJQuota = final boolean isWithinEJQuota =
jobStatus.isRequestedExpeditedJob() && isWithinEJQuotaLocked(jobStatus); jobStatus.isRequestedExpeditedJob() && isWithinEJQuotaLocked(jobStatus);
setConstraintSatisfied(jobStatus, nowElapsed, isWithinQuota || isWithinEJQuota); setConstraintSatisfied(jobStatus, nowElapsed, isWithinQuota, isWithinEJQuota);
final boolean outOfEJQuota; final boolean outOfEJQuota;
if (jobStatus.isRequestedExpeditedJob()) { if (jobStatus.isRequestedExpeditedJob()) {
setExpeditedQuotaApproved(jobStatus, nowElapsed, isWithinEJQuota); 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 // 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 // for some reason. Therefore, avoid setting the real value here and check each job
// individually. // individually.
if (setConstraintSatisfied(js, nowElapsed, isWithinEJQuota || realInQuota)) { if (setConstraintSatisfied(js, nowElapsed, realInQuota, isWithinEJQuota)) {
changedJobs.add(js); changedJobs.add(js);
} }
} else { } else {
// This job is somehow exempted. Need to determine its own quota status. // This job is somehow exempted. Need to determine its own quota status.
if (setConstraintSatisfied(js, nowElapsed, if (setConstraintSatisfied(js, nowElapsed,
isWithinEJQuota || isWithinQuotaLocked(js))) { isWithinQuotaLocked(js), isWithinEJQuota)) {
changedJobs.add(js); changedJobs.add(js);
} }
} }
@@ -1676,7 +1676,7 @@ public final class QuotaController extends StateController {
isWithinEJQuota = false; isWithinEJQuota = false;
} }
if (setConstraintSatisfied(jobStatus, mUpdateTimeElapsed, if (setConstraintSatisfied(jobStatus, mUpdateTimeElapsed,
isWithinEJQuota || isWithinQuotaLocked(jobStatus))) { isWithinQuotaLocked(jobStatus), isWithinEJQuota)) {
changedJobs.add(jobStatus); changedJobs.add(jobStatus);
} }
if (setExpeditedQuotaApproved(jobStatus, mUpdateTimeElapsed, isWithinEJQuota)) { if (setExpeditedQuotaApproved(jobStatus, mUpdateTimeElapsed, isWithinEJQuota)) {
@@ -1833,12 +1833,24 @@ public final class QuotaController extends StateController {
} }
private boolean setConstraintSatisfied(@NonNull JobStatus jobStatus, long nowElapsed, private boolean setConstraintSatisfied(@NonNull JobStatus jobStatus, long nowElapsed,
boolean isWithinQuota) { boolean isWithinQuota, boolean isWithinEjQuota) {
if (!isWithinQuota && jobStatus.getWhenStandbyDeferred() == 0) { 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. // Mark that the job is being deferred due to buckets.
jobStatus.setWhenStandbyDeferred(nowElapsed); 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 @NonNull
private ActionBill getRunningBill(JobStatus jobStatus) { private ActionBill getRunningBill(JobStatus jobStatus) {
// TODO: factor in network cost when available // TODO: factor in network cost when available
if (jobStatus.shouldTreatAsExpeditedJob()) { if (jobStatus.shouldTreatAsExpeditedJob() || jobStatus.startedAsExpeditedJob) {
if (jobStatus.getEffectivePriority() == JobInfo.PRIORITY_MAX) { if (jobStatus.getEffectivePriority() == JobInfo.PRIORITY_MAX) {
return BILL_JOB_RUNNING_MAX_EXPEDITED; return BILL_JOB_RUNNING_MAX_EXPEDITED;
} else { } else {
@@ -636,10 +636,6 @@ public class TareController extends StateController {
return true; return true;
} }
if (mService.isCurrentlyRunningLocked(jobStatus)) { if (mService.isCurrentlyRunningLocked(jobStatus)) {
if (jobStatus.isRequestedExpeditedJob()) {
return canAffordBillLocked(jobStatus, getRunningBill(jobStatus))
|| canAffordBillLocked(jobStatus, BILL_JOB_RUNNING_DEFAULT);
}
return canAffordBillLocked(jobStatus, getRunningBill(jobStatus)); return canAffordBillLocked(jobStatus, getRunningBill(jobStatus));
} }