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

Commit 8bb04428 authored by Kai Shi's avatar Kai Shi
Browse files

Cap BW estimation sample by per-RAT static BW

Sometimes the byte count reported in TrafficStats is abnormally high.  This may result in a very high BW estimation value. The maximum value allowed by current codes is 2000Gbps which is too high. Although this happens quite rarely, it will skew the estimation value. To filter out these cases, invalidate BW estimation samples if the estimation value is above ratio * per-RAT static BW value. The ratio is currently set to 15.

Bug: 197667077
Test: atest FrameworksTelephonyTests:com.android.internal.telephony
Change-Id: I9fa315a2b92761ece329da0ecb51da63b9c86149
Merged-In: I9fa315a2b92761ece329da0ecb51da63b9c86149
parent d8567308
Loading
Loading
Loading
Loading
+3 −1
Original line number Diff line number Diff line
@@ -133,6 +133,7 @@ public class LinkBandwidthEstimator extends Handler {
    // Used to derive byte count threshold from avg BW
    private static final int LOW_BW_TO_AVG_BW_RATIO_NUM = 3;
    private static final int LOW_BW_TO_AVG_BW_RATIO_DEN = 8;
    private static final int MAX_BW_TO_STATIC_BW_RATIO = 15;
    private static final int BYTE_DELTA_THRESHOLD_MIN_KB = 10;
    private static final int MAX_ERROR_PERCENT = 100 * 100;
    private static final String[] AVG_BW_PER_RAT = {
@@ -606,7 +607,8 @@ public class LinkBandwidthEstimator extends Handler {
                return;
            }
            long linkBandwidthLongKbps = bytesDelta * 8 / timeDeltaMs * 1000 / 1024;
            if (linkBandwidthLongKbps > Integer.MAX_VALUE || linkBandwidthLongKbps < 0) {
            if (linkBandwidthLongKbps > (long) mStaticBwKbps * MAX_BW_TO_STATIC_BW_RATIO
                    || linkBandwidthLongKbps < 0) {
                return;
            }
            int linkBandwidthKbps = (int) linkBandwidthLongKbps;
+5 −4
Original line number Diff line number Diff line
@@ -634,7 +634,7 @@ public class LinkBandwidthEstimatorTest extends TelephonyTest {


    @Test
    public void testVeryHighByteCountReturnNonNegativeValue() throws Exception {
    public void testVeryHighRxLinkBandwidthEstimationIgnored() throws Exception {
        mLBE.obtainMessage(MSG_SCREEN_STATE_CHANGED, true).sendToTarget();
        processAllMessages();
        mLBE.obtainMessage(MSG_SIGNAL_STRENGTH_CHANGED, mSignalStrength).sendToTarget();
@@ -650,11 +650,12 @@ public class LinkBandwidthEstimatorTest extends TelephonyTest {
            processAllMessages();
        }

        // This will result in link bandwidth estimation value 128Gbps which is too high for LTE.
        // So it will be ignored by the estimator.
        LinkBandwidthEstimator.NetworkBandwidth network = mLBE.lookupNetwork("310260", 366, "LTE");

        assertEquals(BW_STATS_COUNT_THRESHOLD + 4, network.getCount(LINK_RX, 1));
        assertEquals(0, network.getCount(LINK_RX, 1));
        assertEquals(0, network.getValue(LINK_TX, 1));
        assertEquals(16_000_000_000L * 8 / 1024 * (BW_STATS_COUNT_THRESHOLD + 4),
                network.getValue(LINK_RX, 1));
        assertEquals(0, network.getValue(LINK_RX, 1));
    }
}