Snap for 10146593 from 9959fa4d403a8125129f0376bcf5297bf1291eea to udc-qpr1-release
Change-Id: I7e8c7243511eab43f9b94be411748d5b0282e44c
diff --git a/common/device/com/android/net/module/util/netlink/InetDiagMessage.java b/common/device/com/android/net/module/util/netlink/InetDiagMessage.java
index d462c53..e69a844 100644
--- a/common/device/com/android/net/module/util/netlink/InetDiagMessage.java
+++ b/common/device/com/android/net/module/util/netlink/InetDiagMessage.java
@@ -468,6 +468,23 @@
&& !isAdbSocket(diagMsg));
}
+ /**
+ * Close tcp sockets that match the following condition
+ * 1. TCP status is one of TCP_ESTABLISHED, TCP_SYN_SENT, and TCP_SYN_RECV
+ * 2. Owner uid of socket is in the targetUids
+ * 3. Socket is not loopback
+ * 4. Socket is not adb socket
+ *
+ * @param ownerUids target uids to close sockets
+ */
+ public static void destroyLiveTcpSocketsByOwnerUids(Set<Integer> ownerUids)
+ throws SocketException, InterruptedIOException, ErrnoException {
+ destroySockets(IPPROTO_TCP, TCP_ALIVE_STATE_FILTER,
+ (diagMsg) -> ownerUids.contains(diagMsg.inetDiagMsg.idiag_uid)
+ && !isLoopback(diagMsg)
+ && !isAdbSocket(diagMsg));
+ }
+
@Override
public String toString() {
return "InetDiagMessage{ "