From c544667c3c43d1ad34d8996787e2257df1361f0d 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 Merged-In: Ic1a1811ffb9a1c207f562a180417e99df31e3502 --- Tethering/Android.bp | 3 +++ Tethering/jni/android_net_util_TetheringUtils.cpp | 5 +++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/Tethering/Android.bp b/Tethering/Android.bp index 83a4ebc72b..0957526125 100644 --- a/Tethering/Android.bp +++ b/Tethering/Android.bp @@ -66,6 +66,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 60dacd4f74..7bfb6dab4a 100644 --- a/Tethering/jni/android_net_util_TetheringUtils.cpp +++ b/Tethering/jni/android_net_util_TetheringUtils.cpp @@ -20,6 +20,7 @@ #include #include #include +#include #include #include #include @@ -56,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)); @@ -78,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;