From e5bd0dba21413062121e162e162722ba3224c5ef Mon Sep 17 00:00:00 2001 From: Orion Hodson Date: Tue, 8 Dec 2020 09:57:42 +0000 Subject: [PATCH] Use libnetjniutils for JNI File Descriptor info Drops use of deprecated API in libnativehelper and uses a common helper that will be stable across releases. Bug: 158749603 Test: m Change-Id: Ic1a1811ffb9a1c207f562a180417e99df31e3502 --- Tethering/Android.bp | 3 +++ Tethering/jni/android_net_util_TetheringUtils.cpp | 6 +++--- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/Tethering/Android.bp b/Tethering/Android.bp index 23aa7f8d51..d8557adc61 100644 --- a/Tethering/Android.bp +++ b/Tethering/Android.bp @@ -67,6 +67,9 @@ cc_library { "liblog", "libnativehelper_compat_libc++", ], + static_libs: [ + "libnetjniutils", + ], // We cannot use plain "libc++" here to link libc++ dynamically because it results in: // java.lang.UnsatisfiedLinkError: dlopen failed: library "libc++_shared.so" not found diff --git a/Tethering/jni/android_net_util_TetheringUtils.cpp b/Tethering/jni/android_net_util_TetheringUtils.cpp index 94c871d8a3..7bfb6dab4a 100644 --- a/Tethering/jni/android_net_util_TetheringUtils.cpp +++ b/Tethering/jni/android_net_util_TetheringUtils.cpp @@ -19,8 +19,8 @@ #include #include #include -#include #include +#include #include #include #include @@ -57,7 +57,7 @@ static void android_net_util_setupIcmpFilter(JNIEnv *env, jobject javaFd, uint32 filter_code, }; - int fd = jniGetFDFromFileDescriptor(env, javaFd); + int fd = netjniutils::GetNativeFileDescriptor(env, javaFd); if (setsockopt(fd, SOL_SOCKET, SO_ATTACH_FILTER, &filter, sizeof(filter)) != 0) { jniThrowExceptionFmt(env, "java/net/SocketException", "setsockopt(SO_ATTACH_FILTER): %s", strerror(errno)); @@ -79,7 +79,7 @@ static void android_net_util_setupRaSocket(JNIEnv *env, jobject clazz, jobject j { static const int kLinkLocalHopLimit = 255; - int fd = jniGetFDFromFileDescriptor(env, javaFd); + int fd = netjniutils::GetNativeFileDescriptor(env, javaFd); // Set an ICMPv6 filter that only passes Router Solicitations. struct icmp6_filter rs_only;