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

Commit c6da9a6d authored by Nathan Harold's avatar Nathan Harold
Browse files

Add a Test for NattKeepalive Unsupported on WLAN

Adds a test that verifies that NATT Keepalive requests
are rejected on WLAN while passed on WWAN.

Bug: 72417084
Test: runtest -x DataConnectionTest.java
Merged-In: I710cd8c47a712aec7211cfd026610bb7449743d8
Change-Id: I710cd8c47a712aec7211cfd026610bb7449743d8
(cherry picked from commit 8e990e5f)
parent 688fc35e
Loading
Loading
Loading
Loading
+31 −0
Original line number Diff line number Diff line
@@ -35,6 +35,7 @@ import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;

@@ -524,6 +525,36 @@ public class DataConnectionTest extends TelephonyTest {
        assertEquals(SetupResult.SUCCESS, setLinkProperties(response, linkProperties));
    }

    @Test
    @SmallTest
    public void testStartKeepaliveWLAN() throws Exception {
        testConnectEvent();
        waitForMs(200);

        DataServiceManager mockDsm = mock(DataServiceManager.class);
        doReturn(TransportType.WLAN).when(mockDsm).getTransportType();
        replaceInstance(DataConnection.class, "mDataServiceManager", mDc, mockDsm);

        final int sessionHandle = 0xF00;
        final int slotId = 3;
        final int interval = 10; // seconds
        // Construct a new KeepalivePacketData request as we would receive from a Network Agent,
        // and check that the packet is sent to the RIL.
        KeepalivePacketData kd = KeepalivePacketData.nattKeepalivePacket(
                NetworkUtils.numericToInetAddress("1.2.3.4"),
                1234,
                NetworkUtils.numericToInetAddress("8.8.8.8"),
                4500);
        mDc.obtainMessage(
                DataConnection.EVENT_KEEPALIVE_START_REQUEST, slotId, interval, kd).sendToTarget();
        waitForMs(100);
        // testStartStopNattKeepalive() verifies that this request is passed with WWAN.
        // Thus, even though we can't see the response in NetworkAgent, we can verify that the
        // CommandsInterface never receives a request and infer that it was dropped due to WLAN.
        verify(mSimulatedCommandsVerifier, times(0))
                .startNattKeepalive(anyInt(), eq(kd), eq(interval * 1000), any(Message.class));
    }

    public void checkStartStopNattKeepalive(boolean useCondensedFlow) throws Exception {
        testConnectEvent();
        waitForMs(200);