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

Commit 956e9819 authored by Lorenzo Colitti's avatar Lorenzo Colitti Committed by Automerger Merge Worker
Browse files

[BOT.9] Add unit test for data warning in BpfCoordinator am: 28b57263

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/11818918

Change-Id: I6c4be934204ece434c5b1f5f27ff4e022650ee93
parents 564b36de 28b57263
Loading
Loading
Loading
Loading
+39 −0
Original line number Original line Diff line number Diff line
@@ -23,6 +23,7 @@ import static android.net.NetworkStats.SET_DEFAULT;
import static android.net.NetworkStats.TAG_NONE;
import static android.net.NetworkStats.TAG_NONE;
import static android.net.NetworkStats.UID_ALL;
import static android.net.NetworkStats.UID_ALL;
import static android.net.NetworkStats.UID_TETHERING;
import static android.net.NetworkStats.UID_TETHERING;
import static android.net.netstats.provider.NetworkStatsProvider.QUOTA_UNLIMITED;


import static com.android.networkstack.tethering.BpfCoordinator
import static com.android.networkstack.tethering.BpfCoordinator
        .DEFAULT_PERFORM_POLL_INTERVAL_MS;
        .DEFAULT_PERFORM_POLL_INTERVAL_MS;
@@ -204,4 +205,42 @@ public class BpfCoordinatorTest {
        waitForIdle();
        waitForIdle();
        verify(mNetd, never()).tetherOffloadGetStats();
        verify(mNetd, never()).tetherOffloadGetStats();
    }
    }

    @Test
    public void testOnSetAlert() throws Exception {
        setupFunctioningNetdInterface();

        final BpfCoordinator coordinator = makeBpfCoordinator();
        coordinator.start();

        final String mobileIface = "rmnet_data0";
        final Integer mobileIfIndex = 100;
        coordinator.addUpstreamNameToLookupTable(mobileIfIndex, mobileIface);

        // Verify that set quota to 0 will immediately triggers a callback.
        mTetherStatsProvider.onSetAlert(0);
        waitForIdle();
        mTetherStatsProviderCb.expectNotifyAlertReached();

        // Verify that notifyAlertReached never fired if quota is not yet reached.
        when(mNetd.tetherOffloadGetStats()).thenReturn(
                new TetherStatsParcel[] {buildTestTetherStatsParcel(mobileIfIndex, 0, 0, 0, 0)});
        mTetherStatsProvider.onSetAlert(100);
        mTestLooper.moveTimeForward(DEFAULT_PERFORM_POLL_INTERVAL_MS);
        waitForIdle();
        mTetherStatsProviderCb.assertNoCallback();

        // Verify that notifyAlertReached fired when quota is reached.
        when(mNetd.tetherOffloadGetStats()).thenReturn(
                new TetherStatsParcel[] {buildTestTetherStatsParcel(mobileIfIndex, 50, 0, 50, 0)});
        mTestLooper.moveTimeForward(DEFAULT_PERFORM_POLL_INTERVAL_MS);
        waitForIdle();
        mTetherStatsProviderCb.expectNotifyAlertReached();

        // Verify that set quota with UNLIMITED won't trigger any callback.
        mTetherStatsProvider.onSetAlert(QUOTA_UNLIMITED);
        mTestLooper.moveTimeForward(DEFAULT_PERFORM_POLL_INTERVAL_MS);
        waitForIdle();
        mTetherStatsProviderCb.assertNoCallback();
    }
}
}