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

Commit f56ff048 authored by Lorenzo Colitti's avatar Lorenzo Colitti
Browse files

Minor improvements to verifyTcpBufferSizeChange.

1. Remove "throws Exception" from the signature so it can be used
   in tests that do not already throw Exception.
2. Update comment to reflect the fact that TCP buffer sizes are
   set on default network switch, not on connect.
3. Move into the method a class-level static constant that is
   only used in that method.

Test: atest ConnectivityServiceTest
Change-Id: Ic2e4fbedc23065efc20e45ea84996b577a8e94b6
parent f2cf09c9
Loading
Loading
Loading
Loading
+13 −9
Original line number Diff line number Diff line
@@ -17,10 +17,10 @@
package com.android.server;

import static android.net.ConnectivityManager.CONNECTIVITY_ACTION;
import static android.net.ConnectivityManager.NETID_UNSET;
import static android.net.ConnectivityManager.PRIVATE_DNS_MODE_OFF;
import static android.net.ConnectivityManager.PRIVATE_DNS_MODE_OPPORTUNISTIC;
import static android.net.ConnectivityManager.PRIVATE_DNS_MODE_PROVIDER_HOSTNAME;
import static android.net.ConnectivityManager.NETID_UNSET;
import static android.net.ConnectivityManager.TYPE_ETHERNET;
import static android.net.ConnectivityManager.TYPE_MOBILE;
import static android.net.ConnectivityManager.TYPE_MOBILE_FOTA;
@@ -5224,30 +5224,34 @@ public class ConnectivityServiceTest {
        mCm.unregisterNetworkCallback(networkCallback);
    }

    private static final String TEST_TCP_BUFFER_SIZES = "1,2,3,4,5,6";

    private void verifyTcpBufferSizeChange(String tcpBufferSizes) throws Exception {
    private void verifyTcpBufferSizeChange(String tcpBufferSizes) {
        String[] values = tcpBufferSizes.split(",");
        String rmemValues = String.join(" ", values[0], values[1], values[2]);
        String wmemValues = String.join(" ", values[3], values[4], values[5]);
        waitForIdle();
        try {
            verify(mMockNetd, atLeastOnce()).setTcpRWmemorySize(rmemValues, wmemValues);
        } catch (RemoteException e) {
            fail("mMockNetd should never throw RemoteException");
        }
        reset(mMockNetd);
    }

    @Test
    public void testTcpBufferReset() throws Exception {
    public void testTcpBufferReset() {
        final String testTcpBufferSizes = "1,2,3,4,5,6";

        mCellNetworkAgent = new MockNetworkAgent(TRANSPORT_CELLULAR);
        reset(mMockNetd);
        // Simple connection should have updated tcp buffer size.
        // Switching default network updates TCP buffer sizes.
        mCellNetworkAgent.connect(false);
        verifyTcpBufferSizeChange(ConnectivityService.DEFAULT_TCP_BUFFER_SIZES);

        // Change link Properties should have updated tcp buffer size.
        LinkProperties lp = new LinkProperties();
        lp.setTcpBufferSizes(TEST_TCP_BUFFER_SIZES);
        lp.setTcpBufferSizes(testTcpBufferSizes);
        mCellNetworkAgent.sendLinkProperties(lp);
        verifyTcpBufferSizeChange(TEST_TCP_BUFFER_SIZES);
        verifyTcpBufferSizeChange(testTcpBufferSizes);
    }

    @Test