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

Commit d39cb044 authored by Matías Hernández's avatar Matías Hernández
Browse files

Tweak RateEstimator's alpha value

The original value of 0.8 was not sensitive enough for blocking misbehaving apps, but 0.5 broke a test that updates notifications rapidly. Let's settle for something in the middle.

Test: atest CaptivePortalLoginTests:com.android.captiveportallogin.DownloadServiceTest --iterations 5
Bug: 280098361
Fixes: 285559860
Change-Id: I85dbdf49684d58e20b6032a83a5da24d1399bd3c
parent a45422d0
Loading
Loading
Loading
Loading
+1 −1
Original line number Original line Diff line number Diff line
@@ -23,7 +23,7 @@ package com.android.server.notification;
 * {@hide}
 * {@hide}
 */
 */
class RateEstimator {
class RateEstimator {
    private static final double RATE_ALPHA = 0.5;
    private static final double RATE_ALPHA = 0.7;
    private static final double MINIMUM_DT = 0.0005;
    private static final double MINIMUM_DT = 0.0005;


    private Long mLastEventTime;
    private Long mLastEventTime;
+7 −7
Original line number Original line Diff line number Diff line
@@ -138,22 +138,22 @@ public class RateEstimatorTest extends UiServiceTestCase {


    @Test
    @Test
    public void testEstimateCatchesUpQuickly() {
    public void testEstimateCatchesUpQuickly() {
        long nextEventTime = postEvents(mTestStartTime, 10, 20); // 20 events at 100Hz
        long nextEventTime = postEvents(mTestStartTime, 100, 30); // 30 events at 10Hz


        final float firstBurstRate = mEstimator.getRate(nextEventTime);
        final float firstBurstRate = mEstimator.getRate(nextEventTime);
        assertThat(firstBurstRate).isWithin(10f).of(100);
        assertThat(firstBurstRate).isWithin(2f).of(10);


        nextEventTime += HOURS.toMillis(3); // 3 hours later...
        nextEventTime += HOURS.toMillis(3); // 3 hours later...
        nextEventTime = postEvents(nextEventTime, 10, 20); // same burst of 20 events at 100Hz
        nextEventTime = postEvents(nextEventTime, 100, 30); // same burst of 30 events at 10Hz


        // Catching up. Rate is not yet 100, since we had a long period of inactivity...
        // Catching up. Rate is not yet 10, since we had a long period of inactivity...
        float secondBurstRate = mEstimator.getRate(nextEventTime);
        float secondBurstRate = mEstimator.getRate(nextEventTime);
        assertThat(secondBurstRate).isWithin(10f).of(60);
        assertThat(secondBurstRate).isWithin(1f).of(6);


        // ... but after a few more events, we are there.
        // ... but after a few more events, we are there.
        nextEventTime = postEvents(nextEventTime, 10, 10); // 10 more events at 100Hz
        nextEventTime = postEvents(nextEventTime, 100, 10); // 10 more events at 10Hz
        secondBurstRate = mEstimator.getRate(nextEventTime);
        secondBurstRate = mEstimator.getRate(nextEventTime);
        assertThat(secondBurstRate).isWithin(10f).of(100);
        assertThat(secondBurstRate).isWithin(1f).of(10);
    }
    }


    /** @return the next event time. */
    /** @return the next event time. */