BACKPORT: Update product treble check for VNDK deprecation

On devices which launched with an earlier version than R, if vndk is
deprecated, /product is no longer added to linker namespaces because
ro.product.vndk.version is gone.
The original change addressed an issue for devices running on U, but
on newer Android releases, /product is always treblelized.

Bug: 341228914
Test: Open any /product app that uses jni libs from /product on a
  device with shipping api level <= 29, observe it no longer crashes

Change-Id: I4e4f8ae5fdff2298bfc85a5e7076f26dcc0f67d6
diff --git a/libnativeloader/Android.bp b/libnativeloader/Android.bp
index e9c26c5..6fcd51a 100644
--- a/libnativeloader/Android.bp
+++ b/libnativeloader/Android.bp
@@ -66,6 +66,7 @@
             ],
             static_libs: [
                 "libPlatformProperties",
+                "libmodules-utils-build",
             ],
         },
     },
diff --git a/libnativeloader/public_libraries.cpp b/libnativeloader/public_libraries.cpp
index 390c298..16efdd2 100644
--- a/libnativeloader/public_libraries.cpp
+++ b/libnativeloader/public_libraries.cpp
@@ -34,6 +34,7 @@
 #include <log/log.h>
 
 #if defined(ART_TARGET_ANDROID)
+#include <android-modules-utils/sdk_level.h>
 #include <android/sysprop/VndkProperties.sysprop.h>
 #endif
 
@@ -426,12 +427,11 @@
 
 bool is_product_treblelized() {
 #if defined(ART_TARGET_ANDROID)
-  // Product is not treblelized iff launching version is prior to R and
-  // ro.product.vndk.version is not defined
-  static bool product_treblelized =
-      !(android::base::GetIntProperty("ro.product.first_api_level", 0) < __ANDROID_API_R__ &&
-        !android::sysprop::VndkProperties::product_vndk_version().has_value());
-  return product_treblelized;
+  // Product is treblelized iff the sdk version is newer than U QPR2
+  // or launching version is R or newer or ro.product.vndk.version is defined
+  return android::modules::sdklevel::IsAtLeastU() ||
+         android::base::GetIntProperty("ro.product.first_api_level", 0) >= __ANDROID_API_R__ ||
+         android::sysprop::VndkProperties::product_vndk_version().has_value();
 #else
   return false;
 #endif