Add netlinkSocketForProto() without buffersize.
Test: atest NetworkStaticLibTests
atest FrameworksNetTests
Change-Id: I34a0a29eb7e78490701872229585e61f7a0c1dd3
diff --git a/staticlibs/device/com/android/net/module/util/netlink/NetlinkUtils.java b/staticlibs/device/com/android/net/module/util/netlink/NetlinkUtils.java
index 61d347c..541a375 100644
--- a/staticlibs/device/com/android/net/module/util/netlink/NetlinkUtils.java
+++ b/staticlibs/device/com/android/net/module/util/netlink/NetlinkUtils.java
@@ -225,7 +225,7 @@
}
/**
- * Create netlink socket with the given netlink protocol type.
+ * Create netlink socket with the given netlink protocol type and buffersize.
*
* @param nlProto the netlink protocol
* @param bufferSize the receive buffer size to set when the value is not 0
@@ -243,10 +243,23 @@
}
/**
+ * Create netlink socket with the given netlink protocol type. Receive buffer size is not set.
+ *
+ * @param nlProto the netlink protocol
+ *
+ * @return fd the fileDescriptor of the socket.
+ * @throws ErrnoException if the FileDescriptor not connect to be created successfully
+ */
+ public static FileDescriptor netlinkSocketForProto(int nlProto)
+ throws ErrnoException {
+ return netlinkSocketForProto(nlProto, 0);
+ }
+
+ /**
* Construct a netlink inet_diag socket.
*/
public static FileDescriptor createNetLinkInetDiagSocket() throws ErrnoException {
- return netlinkSocketForProto(NETLINK_INET_DIAG, 0);
+ return netlinkSocketForProto(NETLINK_INET_DIAG);
}
/**
diff --git a/staticlibs/tests/unit/src/com/android/net/module/util/netlink/NetlinkUtilsTest.java b/staticlibs/tests/unit/src/com/android/net/module/util/netlink/NetlinkUtilsTest.java
index b644a53..f64adb8 100644
--- a/staticlibs/tests/unit/src/com/android/net/module/util/netlink/NetlinkUtilsTest.java
+++ b/staticlibs/tests/unit/src/com/android/net/module/util/netlink/NetlinkUtilsTest.java
@@ -212,7 +212,7 @@
@Test @IgnoreUpTo(Build.VERSION_CODES.R) // getsockoptInt requires > R
public void testNetlinkSocketForProto_defaultBufferSize() throws Exception {
- final FileDescriptor fd = NetlinkUtils.netlinkSocketForProto(NETLINK_ROUTE, 0);
+ final FileDescriptor fd = NetlinkUtils.netlinkSocketForProto(NETLINK_ROUTE);
final int bufferSize = Os.getsockoptInt(fd, SOL_SOCKET, SO_RCVBUF) / 2;
assertTrue("bufferSize: " + bufferSize, bufferSize > 0); // whatever the default value is
diff --git a/thread/service/java/com/android/server/thread/TunInterfaceController.java b/thread/service/java/com/android/server/thread/TunInterfaceController.java
index 619a510..7223b2a 100644
--- a/thread/service/java/com/android/server/thread/TunInterfaceController.java
+++ b/thread/service/java/com/android/server/thread/TunInterfaceController.java
@@ -60,8 +60,7 @@
public void createTunInterface() throws IOException {
mParcelTunFd = ParcelFileDescriptor.adoptFd(nativeCreateTunInterface(mIfName, MTU));
try {
- mNetlinkSocket =
- NetlinkUtils.netlinkSocketForProto(OsConstants.NETLINK_ROUTE, 0);
+ mNetlinkSocket = NetlinkUtils.netlinkSocketForProto(OsConstants.NETLINK_ROUTE);
} catch (ErrnoException e) {
throw new IOException("Failed to create netlink socket", e);
}