added disable_vabc field to install_plan

Test: tested compilation. Applied OTA to cuttlefish instance with VABC
flag disabled.

Change-Id: I2d5756a58deb3d4bf7e80983294746c91aebeccb
diff --git a/aosp/update_attempter_android.cc b/aosp/update_attempter_android.cc
index d085918..aab6d2d 100644
--- a/aosp/update_attempter_android.cc
+++ b/aosp/update_attempter_android.cc
@@ -346,6 +346,9 @@
               << headers[kPayloadPropertyNetworkProxy];
     fetcher->SetProxies({headers[kPayloadPropertyNetworkProxy]});
   }
+  if (!headers[kPayloadDisableVABC].empty()) {
+    install_plan_.disable_vabc = true;
+  }
 
   BuildUpdateActions(fetcher);
 
@@ -430,7 +433,7 @@
 
   if (!boot_control_->GetDynamicPartitionControl()->ResetUpdate(prefs_)) {
     LOG(WARNING) << "Failed to reset snapshots. UpdateStatus is IDLE but"
-                  << "space might not be freed.";
+                 << "space might not be freed.";
   }
   switch (status_) {
     case UpdateStatus::IDLE: {
diff --git a/common/constants.h b/common/constants.h
index b862549..f27d2db 100644
--- a/common/constants.h
+++ b/common/constants.h
@@ -176,6 +176,8 @@
 // Proxy URL to use for downloading OTA. This will be forwarded to libcurl
 static constexpr const auto& kPayloadPropertyNetworkProxy = "NETWORK_PROXY";
 
+static constexpr const auto& kPayloadDisableVABC = "DISABLE_VABC";
+
 // Set "SWITCH_SLOT_ON_REBOOT=0" to skip marking the updated partitions active.
 // The default is 1 (always switch slot if update succeeded).
 static constexpr const auto& kPayloadPropertySwitchSlotOnReboot =
diff --git a/payload_consumer/delta_performer.cc b/payload_consumer/delta_performer.cc
index 43a3b3c..608c2f3 100644
--- a/payload_consumer/delta_performer.cc
+++ b/payload_consumer/delta_performer.cc
@@ -50,6 +50,7 @@
 #include "update_engine/common/utils.h"
 #include "update_engine/payload_consumer/partition_update_generator_interface.h"
 #include "update_engine/payload_consumer/partition_writer.h"
+#include "update_engine/update_metadata.pb.h"
 #if USE_FEC
 #include "update_engine/payload_consumer/fec_file_descriptor.h"
 #endif  // USE_FEC
@@ -487,6 +488,27 @@
                              metadata_signature_size_))
         << "Unable to save the manifest signature size.";
 
+    // update estimate_cow_size if VABC is disabled
+    // new_cow_size per partition = partition_size - (#blocks in Copy
+    // operations part of the partition)
+    if (install_plan_->disable_vabc) {
+      manifest_.mutable_dynamic_partition_metadata()
+          ->set_vabc_compression_param("none");
+      for (auto& partition : *manifest_.mutable_partitions()) {
+        int new_cow_size = partition.new_partition_info().size();
+        for (const auto& operation : partition.merge_operations()) {
+          if (operation.type() == CowMergeOperation::COW_COPY) {
+            new_cow_size -=
+                operation.dst_extent().num_blocks() * manifest_.block_size();
+          }
+        }
+        // Adding extra 8MB headroom. OTA will sometimes write labels/metadata
+        // to COW image. If we overrun reserved COW size, entire OTA will fail
+        // and no way for user to retry OTA
+        partition.set_estimate_cow_size(new_cow_size + (1024 * 1024 * 8));
+      }
+    }
+
     if (!PrimeUpdateState()) {
       *error = ErrorCode::kDownloadStateInitializationError;
       LOG(ERROR) << "Unable to prime the update state.";
diff --git a/payload_consumer/install_plan.h b/payload_consumer/install_plan.h
index 883aa60..1faa2e4 100644
--- a/payload_consumer/install_plan.h
+++ b/payload_consumer/install_plan.h
@@ -73,6 +73,7 @@
       ErrorCode* error);
 
   bool is_resume{false};
+  bool disable_vabc{false};
   std::string download_url;  // url to download from
   std::string version;       // version we are installing.
 
diff --git a/scripts/update_device.py b/scripts/update_device.py
index 72cee49..950ff3d 100755
--- a/scripts/update_device.py
+++ b/scripts/update_device.py
@@ -444,6 +444,8 @@
                       help='Perform reset slot switch for this OTA package')
   parser.add_argument('--wipe-user-data', action='store_true',
                       help='Wipe userdata after installing OTA')
+  parser.add_argument('--disable-vabc', action='store_true',
+                      help='Disable vabc during OTA')
   args = parser.parse_args()
   logging.basicConfig(
       level=logging.WARNING if args.no_verbose else logging.INFO)
@@ -497,6 +499,8 @@
     args.extra_headers += "\nRUN_POST_INSTALL=0"
   if args.wipe_user_data:
     args.extra_headers += "\nPOWERWASH=1"
+  if args.disable_vabc:
+    args.extra_headers += "\nDISABLE_VABC=1"
 
   with zipfile.ZipFile(args.otafile) as zfp:
     CARE_MAP_ENTRY_NAME = "care_map.pb"