I\'d like to lower the TCP keepalive time on a Socket I\'m opening from 2 hours to something on the order of ten minutes. I can make it use keepalive with socket.setKeepAliv
Android is based on Linux, and Linux supports the TCP_KEEPIDLE and TCP_KEEPINTVL socket options via the setsocketopt() function, which is wrapped by the java.net.SocketOptions interface. java.net.SocketImpl implements SocketOptions, and java.net.Socket wraps a SocketImpl. What I don't know is whether it is possible to access the SocketImpl of a given Socket object.
What you could try doing is use Socket.setSocketImplFactory() to implement your own custom SocketImplFactory class, which is responsible for creating SocketImpl instances for Socket objects. That way, your factory could call SocketOptions.setOption() for TCP_KEEPIDLE and TCP_KEEPINTVL for any sockets your app creates.