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

Commit 07c9873a authored by Kweku Adams's avatar Kweku Adams
Browse files

Fixing quota buffer upper limit.

Make sure that the quota buffer cannot be greater than allowed time per
period.

Bug: 133892020
Test: atest com.android.server.job.controllers.QuotaControllerTest
Change-Id: I2654a507bf99ac1809eee96e0ebc8e3a94b60bd0
parent ee577653
Loading
Loading
Loading
Loading
+4 −2
Original line number Diff line number Diff line
@@ -2278,8 +2278,10 @@ public final class QuotaController extends StateController {
                    mAllowedTimeIntoQuotaMs = mAllowedTimePerPeriodMs - mQuotaBufferMs;
                    changed = true;
                }
                long newQuotaBufferMs = Math.max(0,
                        Math.min(5 * MINUTE_IN_MILLIS, IN_QUOTA_BUFFER_MS));
                // Make sure quota buffer is non-negative, not greater than allowed time per period,
                // and no more than 5 minutes.
                long newQuotaBufferMs = Math.max(0, Math.min(mAllowedTimePerPeriodMs,
                        Math.min(5 * MINUTE_IN_MILLIS, IN_QUOTA_BUFFER_MS)));
                if (mQuotaBufferMs != newQuotaBufferMs) {
                    mQuotaBufferMs = newQuotaBufferMs;
                    mAllowedTimeIntoQuotaMs = mAllowedTimePerPeriodMs - mQuotaBufferMs;
+10 −0
Original line number Diff line number Diff line
@@ -1892,6 +1892,16 @@ public class QuotaControllerTest {
        assertEquals(1, mQuotaController.getBucketMaxSessionCounts()[RARE_INDEX]);
        assertEquals(0, mQuotaController.getTimingSessionCoalescingDurationMs());

        // Invalid configurations.
        // In_QUOTA_BUFFER should never be greater than ALLOWED_TIME_PER_PERIOD
        mQcConstants.ALLOWED_TIME_PER_PERIOD_MS = 2 * MINUTE_IN_MILLIS;
        mQcConstants.IN_QUOTA_BUFFER_MS = 5 * MINUTE_IN_MILLIS;

        mQcConstants.updateConstants();

        assertTrue(mQuotaController.getInQuotaBufferMs()
                <= mQuotaController.getAllowedTimePerPeriodMs());

        // Test larger than a day. Controller should cap at one day.
        mQcConstants.ALLOWED_TIME_PER_PERIOD_MS = 25 * HOUR_IN_MILLIS;
        mQcConstants.IN_QUOTA_BUFFER_MS = 25 * HOUR_IN_MILLIS;