diff options
| author | 2019-05-31 16:44:23 +0000 | |
|---|---|---|
| committer | 2019-05-31 16:44:23 +0000 | |
| commit | f2079ee257441c907b358fb11f0821c488db7041 (patch) | |
| tree | 8e57711a05f1d7cd2fe77f8c067e0f6ad421517e | |
| parent | 5d35b5039844eec51358df3771d0be32329dd158 (diff) | |
| parent | 60820a0e33e4ab51fdea47cae2dea25da9f2a330 (diff) | |
Merge "Marking job deferral time in QuotaController." into qt-dev
3 files changed, 16 insertions, 6 deletions
diff --git a/services/core/java/com/android/server/job/JobSchedulerService.java b/services/core/java/com/android/server/job/JobSchedulerService.java index ea1c49daefb9..26307cbf7908 100644 --- a/services/core/java/com/android/server/job/JobSchedulerService.java +++ b/services/core/java/com/android/server/job/JobSchedulerService.java @@ -2280,8 +2280,6 @@ public class JobSchedulerService extends com.android.server.SystemService if (bucket >= mConstants.STANDBY_BEATS.length || (mHeartbeat > appLastRan && mHeartbeat < appLastRan + mConstants.STANDBY_BEATS[bucket])) { - // TODO: log/trace that we're deferring the job due to bucketing if we - // hit this if (job.getWhenStandbyDeferred() == 0) { if (DEBUG_STANDBY) { Slog.v(TAG, "Bucket deferral: " + mHeartbeat + " < " diff --git a/services/core/java/com/android/server/job/controllers/QuotaController.java b/services/core/java/com/android/server/job/controllers/QuotaController.java index ef6944e180de..18d193ac68ec 100644 --- a/services/core/java/com/android/server/job/controllers/QuotaController.java +++ b/services/core/java/com/android/server/job/controllers/QuotaController.java @@ -617,7 +617,7 @@ public final class QuotaController extends StateController { jobStatus.setTrackingController(JobStatus.TRACKING_QUOTA); if (mShouldThrottle) { final boolean isWithinQuota = isWithinQuotaLocked(jobStatus); - jobStatus.setQuotaConstraintSatisfied(isWithinQuota); + setConstraintSatisfied(jobStatus, isWithinQuota); if (!isWithinQuota) { maybeScheduleStartAlarmLocked(userId, pkgName, getEffectiveStandbyBucket(jobStatus)); @@ -1282,10 +1282,10 @@ 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. - changed |= js.setQuotaConstraintSatisfied(realInQuota); + changed |= setConstraintSatisfied(js, realInQuota); } else { // This job is somehow exempted. Need to determine its own quota status. - changed |= js.setQuotaConstraintSatisfied(isWithinQuotaLocked(js)); + changed |= setConstraintSatisfied(js, isWithinQuotaLocked(js)); } } if (!realInQuota) { @@ -1310,7 +1310,7 @@ public final class QuotaController extends StateController { @Override public void accept(JobStatus jobStatus) { - wasJobChanged |= jobStatus.setQuotaConstraintSatisfied(isWithinQuotaLocked(jobStatus)); + wasJobChanged |= setConstraintSatisfied(jobStatus, isWithinQuotaLocked(jobStatus)); final int userId = jobStatus.getSourceUserId(); final String packageName = jobStatus.getSourcePackageName(); final int realStandbyBucket = jobStatus.getStandbyBucket(); @@ -1434,6 +1434,14 @@ public final class QuotaController extends StateController { } } + private boolean setConstraintSatisfied(@NonNull JobStatus jobStatus, boolean isWithinQuota) { + if (!isWithinQuota && jobStatus.getWhenStandbyDeferred() == 0) { + // Mark that the job is being deferred due to buckets. + jobStatus.setWhenStandbyDeferred(sElapsedRealtimeClock.millis()); + } + return jobStatus.setQuotaConstraintSatisfied(isWithinQuota); + } + private final class ChargingTracker extends BroadcastReceiver { /** * Track whether we're charging. This has a slightly different definition than that of diff --git a/services/tests/mockingservicestests/src/com/android/server/job/controllers/QuotaControllerTest.java b/services/tests/mockingservicestests/src/com/android/server/job/controllers/QuotaControllerTest.java index 1db6b8e58165..f07a5b554d37 100644 --- a/services/tests/mockingservicestests/src/com/android/server/job/controllers/QuotaControllerTest.java +++ b/services/tests/mockingservicestests/src/com/android/server/job/controllers/QuotaControllerTest.java @@ -2450,6 +2450,8 @@ public class QuotaControllerTest { timeout(remainingTimeMs + 2 * SECOND_IN_MILLIS).times(1)) .onControllerStateChanged(); assertFalse(jobStatus.isConstraintSatisfied(JobStatus.CONSTRAINT_WITHIN_QUOTA)); + assertEquals(JobSchedulerService.sElapsedRealtimeClock.millis(), + jobStatus.getWhenStandbyDeferred()); } /** @@ -2606,6 +2608,8 @@ public class QuotaControllerTest { "testStartAlarmScheduled_TimingSessionCount_AllowedTime", 42); mQuotaController.maybeStartTrackingJobLocked(throttledJob, null); assertFalse(throttledJob.isConstraintSatisfied(JobStatus.CONSTRAINT_WITHIN_QUOTA)); + assertEquals(JobSchedulerService.sElapsedRealtimeClock.millis(), + throttledJob.getWhenStandbyDeferred()); ExecutionStats stats = mQuotaController.getExecutionStatsLocked(SOURCE_USER_ID, SOURCE_PACKAGE, standbyBucket); |