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

Commit 2845f177 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Fixing quota buffer upper limit."

parents 4b235cb0 07c9873a
Loading
Loading
Loading
Loading
+4 −2
Original line number Diff line number Diff line
@@ -2291,8 +2291,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
@@ -1925,6 +1925,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;