Snap for 11383711 from b16f63eebc6e028e3ea76f96393325d05a2d12d8 to mainline-cellbroadcast-release

Change-Id: Idb714d8181bb66e36e47c6c50c65dedd57c0535e
diff --git a/treble/vintf/DeviceMatrixTest.cpp b/treble/vintf/DeviceMatrixTest.cpp
index 2d39c96..cca2377 100644
--- a/treble/vintf/DeviceMatrixTest.cpp
+++ b/treble/vintf/DeviceMatrixTest.cpp
@@ -16,7 +16,9 @@
 
 #include "DeviceMatrixTest.h"
 
+#include <android-base/parseint.h>
 #include <android-base/properties.h>
+#include <android/api-level.h>
 #include <vintf/VintfObject.h>
 
 using android::base::GetProperty;
@@ -36,14 +38,46 @@
 }
 
 TEST_F(DeviceMatrixTest, VndkVersion) {
-  if (GetBoardApiLevel() < 28) {
+  if (GetBoardApiLevel() < __ANDROID_API_P__) {
     GTEST_SKIP()
         << "VNDK version doesn't need to be set on devices before Android P";
   }
 
   std::string syspropVndkVersion = GetProperty(kVndkVersionProp, "");
+
+  // TODO(b/306081093) As of VNDK deprecation, there is no good property to
+  // check which platform version is used to build vendor. For now, let's assume
+  // that any device running board api level Android R or above can be a
+  // candidate of Android V, and skip test for those devices. This should be
+  // revisited once we have a new property to check platform version used to
+  // build vendor.
+  if (GetBoardApiLevel() >= __ANDROID_API_R__) {
+    // TODO(b/306081093) When vendor's target platform is greater or equal than
+    // V, check if vendor VNDK version (both sysprop and VINTF) is empty and
+    // fail if not.
+    if (syspropVndkVersion.empty()) {
+      GTEST_SKIP() << "VNDK version doesn't need to be set on devices built "
+                      "with Android V";
+    }
+
+    uint64_t syspropVndkVersionNumber;
+    if (!android::base::ParseUint(syspropVndkVersion, &syspropVndkVersionNumber)) {
+      syspropVndkVersionNumber = 0;
+    }
+
+    ASSERT_LE(syspropVndkVersionNumber, __ANDROID_API_V__)
+        << kVndkVersionProp << " must be less or equal than "
+        << __ANDROID_API_V__;
+
+    if (syspropVndkVersionNumber == __ANDROID_API_V__) {
+      GTEST_SKIP()
+          << "VNDK version 35 may not have matching VINTF VNDK version.";
+    }
+  }
+
   ASSERT_NE("", syspropVndkVersion)
       << kVndkVersionProp << " must not be empty.";
+
   std::string vintfVndkVersion = vendor_matrix_->getVendorNdkVersion();
   ASSERT_NE("", vintfVndkVersion)
       << "Device compatibility matrix does not declare proper VNDK version.";