Provide getVsrApiLevel() to read the Vsr API level of DUT

The VSR requirements need to know the API level for both device and
board to run or skip the tests. It is complicated to find the API
level with existing functions.
Provide a function to easily get the API level for the tests of VSR
requirements.

Bug: 202919753
Test: manual test
Change-Id: I518c6a9ad65de4534893aa9208bfc774d649e51b
diff --git a/common/host-side/util/src/com/android/compatibility/common/util/PropertyUtil.java b/common/host-side/util/src/com/android/compatibility/common/util/PropertyUtil.java
index aff2086..2f89086 100644
--- a/common/host-side/util/src/com/android/compatibility/common/util/PropertyUtil.java
+++ b/common/host-side/util/src/com/android/compatibility/common/util/PropertyUtil.java
@@ -34,12 +34,14 @@
      * shipped. Property should be undefined for factory ROM products.
      */
     public static final String FIRST_API_LEVEL = "ro.product.first_api_level";
+
+    private static final String BOARD_API_LEVEL = "ro.board.api_level";
+    private static final String BOARD_FIRST_API_LEVEL = "ro.board.first_api_level";
     private static final String BUILD_TAGS_PROPERTY = "ro.build.tags";
     private static final String BUILD_TYPE_PROPERTY = "ro.build.type";
     private static final String MANUFACTURER_PROPERTY = "ro.product.manufacturer";
     private static final String TAG_DEV_KEYS = "dev-keys";
-    private static final String VENDOR_API_LEVEL = "ro.board.api_level";
-    private static final String VENDOR_FIRST_API_LEVEL = "ro.board.first_api_level";
+    private static final String VENDOR_BUILD_VERSION_SDK = "ro.vendor.build.version.sdk";
     private static final String VNDK_VERSION = "ro.vndk.version";
 
     /** Value to be returned by getPropertyInt() if property is not found */
@@ -79,6 +81,25 @@
     }
 
     /**
+     * Return the API level that the VSR requirement must be fulfilled. It reads
+     * ro.product.first_api_level, ro.board.first_api_level, and ro.board.api_level to find the
+     * minimum required VSR api_level for the DUT.
+     */
+    public static int getVsrApiLevel(ITestDevice device) throws DeviceNotAvailableException {
+        // Api level properties of the board. The order of the properties must be kept.
+        String[] boardApiLevelProps = {
+            BOARD_API_LEVEL, BOARD_FIRST_API_LEVEL, VENDOR_BUILD_VERSION_SDK
+        };
+        for (String apiLevelProp : boardApiLevelProps) {
+            int apiLevel = getPropertyInt(device, apiLevelProp);
+            if (apiLevel != INT_VALUE_IF_UNSET) {
+                return Math.min(apiLevel, getFirstApiLevel(device));
+            }
+        }
+        return getFirstApiLevel(device);
+    }
+
+    /**
      * Return the API level of the vendor partition. It will read the following properties in order
      * and returns the value of the first defined property. If none of them are defined, or the
      * value is a VERSION CODENAME, returns the current API level which is defined in
@@ -93,7 +114,7 @@
     public static int getVendorApiLevel(ITestDevice device) throws DeviceNotAvailableException {
         String[] vendorApiLevelProps = {
             // Use the properties in order.
-            VENDOR_API_LEVEL, VENDOR_FIRST_API_LEVEL, VNDK_VERSION,
+            BOARD_API_LEVEL, BOARD_FIRST_API_LEVEL, VNDK_VERSION,
         };
         for (String prop : vendorApiLevelProps) {
             int apiLevel = getPropertyInt(device, prop);