Fix vabc-none option on device am: 730d5d630c am: a4200d86ef

Original change: https://android-review.googlesource.com/c/platform/system/update_engine/+/2818660

Change-Id: Ib830ec8ba7715ab6c5c612b1a37eaf9d6f056d50
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
diff --git a/payload_consumer/delta_performer.cc b/payload_consumer/delta_performer.cc
index 0b4a13e..14a707f 100644
--- a/payload_consumer/delta_performer.cc
+++ b/payload_consumer/delta_performer.cc
@@ -598,6 +598,15 @@
   // new_cow_size per partition = partition_size - (#blocks in Copy
   // operations part of the partition)
   if (install_plan_->vabc_none) {
+    size_t cowOpsize = android::snapshot::GetCowOpSize(
+        manifest_.dynamic_partition_metadata().cow_version());
+    if (cowOpsize == 0) {
+      cowOpsize = sizeof(android::snapshot::CowOperationV2);
+      LOG(WARNING) << "Failed to determine cow op size for COW version "
+                   << manifest_.dynamic_partition_metadata().cow_version()
+                   << ", defaulting to " << cowOpsize;
+    }
+
     LOG(INFO) << "Setting Virtual AB Compression algorithm to none. This "
                  "would also disable VABC XOR as XOR only saves space if "
                  "compression is enabled.";
@@ -628,13 +637,11 @@
       // Every block written to COW device will come with a header which
       // stores src/dst block info along with other data.
       const auto cow_metadata_size = partition.new_partition_info().size() /
-                                     manifest_.block_size() *
-                                     sizeof(android::snapshot::CowOperation);
+                                     manifest_.block_size() * cowOpsize;
       // update_engine will emit a label op every op or every two seconds,
       // whichever one is longer. In the worst case, we add 1 label per
       // InstallOp. So take size of label ops into account.
-      const auto label_ops_size =
-          partition.operations_size() * sizeof(android::snapshot::CowOperation);
+      const auto label_ops_size = partition.operations_size() * cowOpsize;
       // Adding extra 2MB headroom just for any unexpected space usage.
       // If we overrun reserved COW size, entire OTA will fail
       // and no way for user to retry OTA