ota_from_target_files: allow cow version override

With our version compatibility check, overriding our cow version no
longer works. Updating this check to only apply if a command line
vabc_cow_version is not specified.

NOTE: the ota may not successfully apply, depending on device if we
override the cow version

Test: th
Change-Id: Ibbed6cf94cc2e91597d0c249dc8ade314b8341a2
diff --git a/tools/releasetools/ota_from_target_files.py b/tools/releasetools/ota_from_target_files.py
index 432ea19..5a024ce 100755
--- a/tools/releasetools/ota_from_target_files.py
+++ b/tools/releasetools/ota_from_target_files.py
@@ -914,12 +914,13 @@
     # and install time performance. All OTA's with
     # both the source build and target build with VIRTUAL_AB_COW_VERSION = 3
     # can support the new format. Otherwise, fallback on older versions
-    if not source_info.vabc_cow_version or not target_info.vabc_cow_version:
-      logger.info("Source or Target doesn't have VABC_COW_VERSION specified, default to version 2")
-      OPTIONS.vabc_cow_version = 2
-    elif source_info.vabc_cow_version != target_info.vabc_cow_version:
-      logger.info("Source and Target have different cow VABC_COW_VERSION specified, default to minimum version")
-      OPTIONS.vabc_cow_version = min(source_info.vabc_cow_version, target_info.vabc_cow_version)
+    if not OPTIONS.vabc_cow_version:
+      if not source_info.vabc_cow_version or not target_info.vabc_cow_version:
+        logger.info("Source or Target doesn't have VABC_COW_VERSION specified, default to version 2")
+        OPTIONS.vabc_cow_version = 2
+      elif source_info.vabc_cow_version != target_info.vabc_cow_version:
+        logger.info("Source and Target have different cow VABC_COW_VERSION specified, default to minimum version")
+        OPTIONS.vabc_cow_version = min(source_info.vabc_cow_version, target_info.vabc_cow_version)
 
     # Virtual AB Compression was introduced in Androd S.
     # Later, we backported VABC to Android R. But verity support was not
@@ -933,19 +934,20 @@
     assert "ab_partitions" in OPTIONS.info_dict, \
         "META/ab_partitions.txt is required for ab_update."
     source_info = None
-    if not target_info.vabc_cow_version:
+    if not OPTIONS.vabc_cow_version:
+      if not target_info.vabc_cow_version:
+          OPTIONS.vabc_cow_version = 2
+      elif target_info.vabc_cow_version >= "3" and target_info.vendor_api_level < 35:
+        logger.warning(
+              "This full OTA is configured to use VABC cow version"
+              " 3 which is supported since"
+              " Android API level 35, but device is "
+              "launched with {} . If this full OTA is"
+              " served to a device running old build, OTA might fail due to "
+              "unsupported vabc cow version. For safety, version 2 is used because "
+              "it's supported since day 1.".format(
+                  target_info.vendor_api_level))
         OPTIONS.vabc_cow_version = 2
-    elif target_info.vabc_cow_version >= "3" and target_info.vendor_api_level < 35:
-      logger.warning(
-            "This full OTA is configured to use VABC cow version"
-            " 3 which is supported since"
-            " Android API level 35, but device is "
-            "launched with {} . If this full OTA is"
-            " served to a device running old build, OTA might fail due to "
-            "unsupported vabc cow version. For safety, version 2 is used because "
-            "it's supported since day 1.".format(
-                target_info.vendor_api_level))
-      OPTIONS.vabc_cow_version = 2
     if OPTIONS.vabc_compression_param is None and vabc_compression_param:
       minimum_api_level_required = VABC_COMPRESSION_PARAM_SUPPORT[
           vabc_compression_param]