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

Commit f675639d authored by Nathan Harold's avatar Nathan Harold Committed by Android (Google) Code Review
Browse files

Merge changes from topic "pick-keepalive-unsupported" into pi-dev

* changes:
  Add a Test for NattKeepalive Unsupported on WLAN
  Return Unsupported for Keepalive Requests on IWLAN
parents 6cc7535c c6da9a6d
Loading
Loading
Loading
Loading
+21 −4
Original line number Diff line number Diff line
@@ -39,6 +39,7 @@ import android.os.Looper;
import android.os.Message;
import android.os.SystemClock;
import android.os.SystemProperties;
import android.telephony.AccessNetworkConstants;
import android.telephony.Rlog;
import android.telephony.ServiceState;
import android.telephony.TelephonyManager;
@@ -1850,10 +1851,26 @@ public class DataConnection extends StateMachine {
                    KeepalivePacketData pkt = (KeepalivePacketData) msg.obj;
                    int slotId = msg.arg1;
                    int intervalMillis = msg.arg2 * 1000;
                    if (mDataServiceManager.getTransportType()
                            == AccessNetworkConstants.TransportType.WWAN) {
                        mPhone.mCi.startNattKeepalive(
                                DataConnection.this.mCid, pkt, intervalMillis,
                                DataConnection.this.obtainMessage(
                                        EVENT_KEEPALIVE_STARTED, slotId, 0, null));
                    } else {
                        // We currently do not support NATT Keepalive requests using the
                        // DataService API, so unless the request is WWAN (always bound via
                        // the CommandsInterface), the request cannot be honored.
                        //
                        // TODO: b/72331356 to add support for Keepalive to the DataService
                        // so that keepalive requests can be handled (if supported) by the
                        // underlying transport.
                        if (mNetworkAgent != null) {
                            mNetworkAgent.onPacketKeepaliveEvent(
                                    msg.arg1,
                                    ConnectivityManager.PacketKeepalive.ERROR_INVALID_NETWORK);
                        }
                    }
                    retVal = HANDLED;
                    break;
                }
+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);