Merge "Set keepalive socket timeout to default value" am: 4c8baa10f9

am: 8d03ba0e98

Change-Id: I5461398bd72c5c649aca862c3613f3ce29161820
This commit is contained in:
Junyu Lai
2019-10-24 02:47:27 -07:00
committed by android-build-merger

View File

@@ -111,9 +111,7 @@ public class ConnectivityManagerTest extends AndroidTestCase {
public static final int TYPE_WIFI = ConnectivityManager.TYPE_WIFI;
private static final int HOST_ADDRESS = 0x7f000001;// represent ip 127.0.0.1
private static final int CONNECT_TIMEOUT_MS = 2000;
private static final int KEEPALIVE_CALLBACK_TIMEOUT_MS = 2000;
private static final int KEEPALIVE_SOCKET_TIMEOUT_MS = 5000;
private static final int INTERVAL_KEEPALIVE_RETRY_MS = 500;
private static final int MAX_KEEPALIVE_RETRY_COUNT = 3;
private static final int MIN_KEEPALIVE_INTERVAL = 10;
@@ -834,15 +832,14 @@ public class ConnectivityManagerTest extends AndroidTestCase {
}
private Socket getConnectedSocket(final Network network, final String host, final int port,
final int socketTimeOut, final int family) throws Exception {
final int family) throws Exception {
final Socket s = network.getSocketFactory().createSocket();
try {
final InetAddress addr = getAddrByName(host, family);
if (addr == null) fail("Fail to get destination address for " + family);
final InetSocketAddress sockAddr = new InetSocketAddress(addr, port);
s.setSoTimeout(socketTimeOut);
s.connect(sockAddr, CONNECT_TIMEOUT_MS);
s.connect(sockAddr);
} catch (Exception e) {
s.close();
throw e;
@@ -967,8 +964,7 @@ public class ConnectivityManagerTest extends AndroidTestCase {
final byte[] requestBytes = CtsNetUtils.HTTP_REQUEST.getBytes("UTF-8");
// So far only ipv4 tcp keepalive offload is supported.
// TODO: add test case for ipv6 tcp keepalive offload when it is supported.
try (Socket s = getConnectedSocket(network, TEST_HOST, HTTP_PORT,
KEEPALIVE_SOCKET_TIMEOUT_MS, AF_INET)) {
try (Socket s = getConnectedSocket(network, TEST_HOST, HTTP_PORT, AF_INET)) {
// Should able to start keep alive offload when socket is idle.
final Executor executor = mContext.getMainExecutor();
@@ -1102,7 +1098,7 @@ public class ConnectivityManagerTest extends AndroidTestCase {
// sockets will be duplicated and kept valid in service side if the keepalives are
// successfully started.
try (Socket tcpSocket = getConnectedSocket(network, TEST_HOST, HTTP_PORT,
0 /* Unused */, AF_INET)) {
AF_INET)) {
return mCm.createSocketKeepalive(network, tcpSocket, executor, callback);
} catch (Exception e) {
fail("Unexpected error when creating TCP socket: " + e);