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

Commit ede7c417 authored by Kai Shi's avatar Kai Shi Committed by Jack Yu
Browse files

Bug fix of bandwidth estimator overflow

Fix an overflow bug in bandwidth estimation filter. When the device is
up more than 25 days, there is a chance to hit overflow in time delta calculation. The chance is about 0.2% according to the metrics.

Bug: 238921804
Test: atest FrameworksTelephonyTests:com.android.internal.telephony.data.LinkBandwidthEstimatorTest
Merged-In: I36f6e7a9995af093a22bfb5d6e604448a1359acb
Change-Id: I36f6e7a9995af093a22bfb5d6e604448a1359acb
parent d2985886
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -715,7 +715,7 @@ public class LinkBandwidthEstimator extends Handler {
            int filterInKbps = mBwSampleValid ? mBwSampleKbps : avgKbps;

            long currTimeMs = mTelephonyFacade.getElapsedSinceBootMillis();
            int timeDeltaSec = (int) (currTimeMs - mBwSampleValidTimeMs) / 1000;
            int timeDeltaSec = (int) ((currTimeMs - mBwSampleValidTimeMs) / 1000);

            // If the operation condition changes significantly since the last update
            // or the sample has higher BW, use a faster filter. Otherwise, use a slow filter
+26 −0
Original line number Diff line number Diff line
@@ -467,6 +467,32 @@ public class LinkBandwidthEstimatorTest extends TelephonyTest {
        verifyUpdateBandwidth(-1, 19_597);
    }

    @Test
    public void testNoOverflowAfterLargeTimeGap() throws Exception {
        mLBE.obtainMessage(MSG_SCREEN_STATE_CHANGED, true).sendToTarget();
        processAllMessages();

        for (int i = 0; i < BW_STATS_COUNT_THRESHOLD + 2; i++) {
            addTxBytes(10_000L);
            addRxBytes(500_000L);
            if (i == BW_STATS_COUNT_THRESHOLD) {
                addElapsedTime(26 * 24 * 3_600_000L);
                moveTimeForward(26 * 24 * 3_600_000L);
            } else {
                addElapsedTime(5_100);
                moveTimeForward(5_100);
            }
            processAllMessages();
            mLBE.obtainMessage(MSG_MODEM_ACTIVITY_RETURNED, new ModemActivityInfo(
                    i * 5_100L, 0, 0, TX_TIME_2_MS, i * RX_TIME_2_MS)).sendToTarget();
            processAllMessages();
        }

        verify(mTelephonyManager, times(BW_STATS_COUNT_THRESHOLD + 2))
                .requestModemActivityInfo(any(), any());
        verifyUpdateBandwidth(-1, 19_531);
    }

    @Test
    public void testAbnormalTrafficCountTriggerLessBwUpdate() throws Exception {
        mLBE.obtainMessage(MSG_SCREEN_STATE_CHANGED, true).sendToTarget();