Refine version test to tolerate missing first_api_level and check sdk
level

Test: run the test
Change-Id: I429518ec6cd51328532179448eca8f04b961de14
Fixes: 62496616
(cherry picked from commit 18b35a6f2b4ba1003d070c36ad25be42a5262312)
diff --git a/treble/platform_version/VtsTreblePlatformVersionTest.py b/treble/platform_version/VtsTreblePlatformVersionTest.py
index 9fc0dae..a5e6728 100644
--- a/treble/platform_version/VtsTreblePlatformVersionTest.py
+++ b/treble/platform_version/VtsTreblePlatformVersionTest.py
@@ -32,13 +32,18 @@
         self.dut = self.registerController(android_device)[0]
         self.dut.shell.InvokeTerminal("VtsTreblePlatformVersionTest")
 
-    def getProp(self, prop):
+    def getProp(self, prop, required=True):
         """Helper to retrieve a property from device."""
 
         results = self.dut.shell.VtsTreblePlatformVersionTest.Execute(
             "getprop " + prop)
-        asserts.assertEqual(results[const.EXIT_CODE][0], 0,
-            "getprop must succeed")
+        if required:
+            asserts.assertEqual(results[const.EXIT_CODE][0], 0,
+                "getprop must succeed")
+        else:
+            if results[const.EXIT_CODE][0] != 0:
+                logging.info("sysprop %s undefined", prop)
+                return None
 
         result = results[const.STDOUT][0].strip()
 
@@ -46,11 +51,14 @@
 
         return result
 
-    def testPlatformVersion(self):
+    def testFirstApiLevel(self):
         """Test that device launched with O or later."""
-
         try:
-            firstApiLevel = int(self.getProp("ro.product.first_api_level"))
+            firstApiLevel = self.getProp("ro.product.first_api_level",
+                                         required=False)
+            if firstApiLevel is None:
+                asserts.skip("ro.product.first_api_level undefined")
+            firstApiLevel = int(firstApiLevel)
             asserts.assertTrue(firstApiLevel >= ANDROID_O_API_VERSION,
                 "VTS can only be run for new launches in O or above")
         except ValueError:
@@ -58,11 +66,19 @@
 
     def testTrebleEnabled(self):
         """Test that device has Treble enabled."""
-
         trebleIsEnabledStr = self.getProp("ro.treble.enabled")
         asserts.assertEqual(trebleIsEnabledStr, "true",
             "VTS can only be run for Treble enabled devices")
 
+    def testSdkVersion(self):
+        """Test that SDK version >= O (26)."""
+        try:
+            sdkVersion = int(self.getProp("ro.build.version.sdk"))
+            asserts.assertTrue(sdkVersion >= ANDROID_O_API_VERSION,
+                "VTS is for devices launching in O or above")
+        except ValueError:
+            asserts.fail("Unexpected value returned from getprop")
+
     def testVndkVersion(self):
         """Test that VNDK version is specified."""
         vndkVersion = self.getProp("ro.vendor.vndk.version")