Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 37eaca4f authored by Kweku Adams's avatar Kweku Adams Committed by android-build-merger
Browse files

Merge "Marking job deferral time in QuotaController." into qt-dev am: f2079ee2

am: c2d83422

Change-Id: I4f206808641a10e1709ed0715ae67df41f19767a
parents 30d88c05 c2d83422
Loading
Loading
Loading
Loading
+0 −2
Original line number Diff line number Diff line
@@ -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 + " < "
+12 −4
Original line number Diff line number Diff line
@@ -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
+4 −0
Original line number Diff line number Diff line
@@ -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);