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

Commit 60820a0e authored by Kweku Adams's avatar Kweku Adams
Browse files

Marking job deferral time in QuotaController.

The deferred job counter relies on a JobStatus being told when
it was deferred due to standby bucketing. QuotaController didn't
make the proper call, which meant that the deferred job metric
wasn't correct.

Bug: 134063509
Test: atest com.android.server.job.controllers.QuotaControllerTest
Change-Id: Iac57f234b6d27ebbbfecd0bcea4eccaa2e953c3f
parent 8a09c7c0
Loading
Loading
Loading
Loading
+0 −2
Original line number Original line Diff line number Diff line
@@ -2280,8 +2280,6 @@ public class JobSchedulerService extends com.android.server.SystemService
                    if (bucket >= mConstants.STANDBY_BEATS.length
                    if (bucket >= mConstants.STANDBY_BEATS.length
                            || (mHeartbeat > appLastRan
                            || (mHeartbeat > appLastRan
                            && mHeartbeat < appLastRan + mConstants.STANDBY_BEATS[bucket])) {
                            && 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 (job.getWhenStandbyDeferred() == 0) {
                            if (DEBUG_STANDBY) {
                            if (DEBUG_STANDBY) {
                                Slog.v(TAG, "Bucket deferral: " + mHeartbeat + " < "
                                Slog.v(TAG, "Bucket deferral: " + mHeartbeat + " < "
+12 −4
Original line number Original line Diff line number Diff line
@@ -617,7 +617,7 @@ public final class QuotaController extends StateController {
        jobStatus.setTrackingController(JobStatus.TRACKING_QUOTA);
        jobStatus.setTrackingController(JobStatus.TRACKING_QUOTA);
        if (mShouldThrottle) {
        if (mShouldThrottle) {
            final boolean isWithinQuota = isWithinQuotaLocked(jobStatus);
            final boolean isWithinQuota = isWithinQuotaLocked(jobStatus);
            jobStatus.setQuotaConstraintSatisfied(isWithinQuota);
            setConstraintSatisfied(jobStatus, isWithinQuota);
            if (!isWithinQuota) {
            if (!isWithinQuota) {
                maybeScheduleStartAlarmLocked(userId, pkgName,
                maybeScheduleStartAlarmLocked(userId, pkgName,
                        getEffectiveStandbyBucket(jobStatus));
                        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
                // 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.
                changed |= js.setQuotaConstraintSatisfied(realInQuota);
                changed |= setConstraintSatisfied(js, realInQuota);
            } 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.
                changed |= js.setQuotaConstraintSatisfied(isWithinQuotaLocked(js));
                changed |= setConstraintSatisfied(js, isWithinQuotaLocked(js));
            }
            }
        }
        }
        if (!realInQuota) {
        if (!realInQuota) {
@@ -1310,7 +1310,7 @@ public final class QuotaController extends StateController {


        @Override
        @Override
        public void accept(JobStatus jobStatus) {
        public void accept(JobStatus jobStatus) {
            wasJobChanged |= jobStatus.setQuotaConstraintSatisfied(isWithinQuotaLocked(jobStatus));
            wasJobChanged |= setConstraintSatisfied(jobStatus, isWithinQuotaLocked(jobStatus));
            final int userId = jobStatus.getSourceUserId();
            final int userId = jobStatus.getSourceUserId();
            final String packageName = jobStatus.getSourcePackageName();
            final String packageName = jobStatus.getSourcePackageName();
            final int realStandbyBucket = jobStatus.getStandbyBucket();
            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 {
    private final class ChargingTracker extends BroadcastReceiver {
        /**
        /**
         * Track whether we're charging. This has a slightly different definition than that of
         * Track whether we're charging. This has a slightly different definition than that of
+4 −0
Original line number Original line Diff line number Diff line
@@ -2450,6 +2450,8 @@ public class QuotaControllerTest {
                timeout(remainingTimeMs + 2 * SECOND_IN_MILLIS).times(1))
                timeout(remainingTimeMs + 2 * SECOND_IN_MILLIS).times(1))
                .onControllerStateChanged();
                .onControllerStateChanged();
        assertFalse(jobStatus.isConstraintSatisfied(JobStatus.CONSTRAINT_WITHIN_QUOTA));
        assertFalse(jobStatus.isConstraintSatisfied(JobStatus.CONSTRAINT_WITHIN_QUOTA));
        assertEquals(JobSchedulerService.sElapsedRealtimeClock.millis(),
                jobStatus.getWhenStandbyDeferred());
    }
    }


    /**
    /**
@@ -2606,6 +2608,8 @@ public class QuotaControllerTest {
                "testStartAlarmScheduled_TimingSessionCount_AllowedTime", 42);
                "testStartAlarmScheduled_TimingSessionCount_AllowedTime", 42);
        mQuotaController.maybeStartTrackingJobLocked(throttledJob, null);
        mQuotaController.maybeStartTrackingJobLocked(throttledJob, null);
        assertFalse(throttledJob.isConstraintSatisfied(JobStatus.CONSTRAINT_WITHIN_QUOTA));
        assertFalse(throttledJob.isConstraintSatisfied(JobStatus.CONSTRAINT_WITHIN_QUOTA));
        assertEquals(JobSchedulerService.sElapsedRealtimeClock.millis(),
                throttledJob.getWhenStandbyDeferred());


        ExecutionStats stats = mQuotaController.getExecutionStatsLocked(SOURCE_USER_ID,
        ExecutionStats stats = mQuotaController.getExecutionStatsLocked(SOURCE_USER_ID,
                SOURCE_PACKAGE, standbyBucket);
                SOURCE_PACKAGE, standbyBucket);