Use IsAtLeastS SdkLevel utility implementation
Bug: 175670047
Test: m
Change-Id: Ibbc11e0f1d103016883f67e2720777b43c08d282
diff --git a/staticlibs/native/netjniutils/Android.bp b/staticlibs/native/netjniutils/Android.bp
index d8e6a04..22fd1fa 100644
--- a/staticlibs/native/netjniutils/Android.bp
+++ b/staticlibs/native/netjniutils/Android.bp
@@ -19,6 +19,9 @@
cc_library_static {
name: "libnetjniutils",
srcs: ["netjniutils.cpp"],
+ static_libs: [
+ "libmodules-utils-build",
+ ],
header_libs: ["jni_headers"],
shared_libs: ["liblog"],
export_header_lib_headers: ["jni_headers"],
diff --git a/staticlibs/native/netjniutils/netjniutils.cpp b/staticlibs/native/netjniutils/netjniutils.cpp
index 210c6c3..8b7f903 100644
--- a/staticlibs/native/netjniutils/netjniutils.cpp
+++ b/staticlibs/native/netjniutils/netjniutils.cpp
@@ -15,6 +15,7 @@
#define LOG_TAG "netjniutils"
#include "netjniutils/netjniutils.h"
+#include <android-modules-utils/sdk_level.h>
#include <dlfcn.h>
#include <stdbool.h>
@@ -29,27 +30,6 @@
namespace {
-bool IsAtLeastS() {
- // TODO(b/158749603#comment19): move to android::modules::sdklevel::IsAtLeastS().
- int api_level = android_get_device_api_level();
-
- // Guarded check for branches that do not have __ANDROID_API_S__.
-#ifdef __ANDROID_API_S__
- if (api_level >= __ANDROID_API_S__) {
- return true;
- }
-#endif
-
- if (api_level < __ANDROID_API_R__) {
- return false;
- }
-
- // Device looks like R or above, check codename as it could be (S or above).
- static constexpr const char* kCodenameProperty = "ro.build.version.codename";
- char codename[PROP_VALUE_MAX] = { 0 };
- return (__system_property_get(kCodenameProperty, codename) > 0 &&
- codename[0] >= 'S' && codename[1] == '\0');
-}
int GetNativeFileDescriptorWithoutNdk(JNIEnv* env, jobject javaFd) {
// Prior to Android S, we need to find the descriptor field in the FileDescriptor class. The
@@ -92,7 +72,8 @@
} // namespace
int GetNativeFileDescriptor(JNIEnv* env, jobject javaFd) {
- static const bool preferNdkFileDescriptorApi = []() -> bool { return IsAtLeastS(); }();
+ static const bool preferNdkFileDescriptorApi = []() -> bool
+ { return android::modules::sdklevel::IsAtLeastS(); }();
if (preferNdkFileDescriptorApi) {
return GetNativeFileDescriptorWithNdk(env, javaFd);
} else {