Add cli option to enable multi-threaded compression

Test: update_device.py --enable-threading, make sure threading is being
turned on

Change-Id: I1d0e5ab5c2e65cc48b5126fb186f770b68188351
diff --git a/aosp/dynamic_partition_control_android.cc b/aosp/dynamic_partition_control_android.cc
index 7818086..ca3473c 100644
--- a/aosp/dynamic_partition_control_android.cc
+++ b/aosp/dynamic_partition_control_android.cc
@@ -1428,7 +1428,7 @@
 DynamicPartitionControlAndroid::OpenCowWriter(
     const std::string& partition_name,
     const std::optional<std::string>& source_path,
-    bool is_append) {
+    bool) {
   auto suffix = SlotSuffixForSlotNumber(target_slot_);
 
   auto super_device = GetSuperDevice();
diff --git a/aosp/update_attempter_android.cc b/aosp/update_attempter_android.cc
index 617edab..ea0b0d9 100644
--- a/aosp/update_attempter_android.cc
+++ b/aosp/update_attempter_android.cc
@@ -350,6 +350,12 @@
   if (!headers[kPayloadDisableVABC].empty()) {
     install_plan_.disable_vabc = true;
   }
+  if (!headers[kPayloadEnableThreading].empty()) {
+    install_plan_.enable_threading = true;
+  }
+  if (!headers[kPayloadBatchedWrites].empty()) {
+    install_plan_.batched_writes = true;
+  }
 
   BuildUpdateActions(fetcher);
 
diff --git a/common/constants.h b/common/constants.h
index 11be740..36c4476 100644
--- a/common/constants.h
+++ b/common/constants.h
@@ -179,6 +179,10 @@
 // Set Virtual AB Compression's compression algorithm to "none", but still use
 // userspace snapshots and snapuserd for update installation.
 static constexpr const auto& kPayloadDisableVABC = "DISABLE_VABC";
+// Enable multi-threaded compression for VABC
+static constexpr const auto& kPayloadEnableThreading = "ENABLE_THREADING";
+// Enable batched writes for VABC
+static constexpr const auto& kPayloadBatchedWrites = "BATCHED_WRITES";
 
 // Max retry count for download
 static constexpr const auto& kPayloadDownloadRetry = "DOWNLOAD_RETRY";
diff --git a/payload_consumer/delta_performer.cc b/payload_consumer/delta_performer.cc
index e61870b..d5d5263 100644
--- a/payload_consumer/delta_performer.cc
+++ b/payload_consumer/delta_performer.cc
@@ -487,6 +487,18 @@
         partition.set_estimate_cow_size(new_cow_size + (1024 * 1024 * 8));
       }
     }
+    if (install_plan_->enable_threading) {
+      manifest_.mutable_dynamic_partition_metadata()
+          ->mutable_vabc_feature_set()
+          ->set_threaded(true);
+      LOG(INFO) << "Attempting to enable multi-threaded compression for VABC";
+    }
+    if (install_plan_->batched_writes) {
+      manifest_.mutable_dynamic_partition_metadata()
+          ->mutable_vabc_feature_set()
+          ->set_batch_writes(true);
+      LOG(INFO) << "Attempting to enable batched writes for VABC";
+    }
 
     // This populates |partitions_| and the |install_plan.partitions| with the
     // list of partitions from the manifest.
diff --git a/payload_consumer/install_plan.h b/payload_consumer/install_plan.h
index 1faa2e4..926af98 100644
--- a/payload_consumer/install_plan.h
+++ b/payload_consumer/install_plan.h
@@ -195,6 +195,12 @@
   // The name of dynamic partitions not included in the payload. Only used
   // for partial updates.
   std::vector<std::string> untouched_dynamic_partitions;
+
+  // Whether to batch write operations for COW
+  bool batched_writes = false;
+
+  // Whether to enable multi-threaded compression on COW writes
+  bool enable_threading = false;
 };
 
 class InstallPlanAction;
diff --git a/scripts/update_device.py b/scripts/update_device.py
index 7cf66a5..8f4e583 100755
--- a/scripts/update_device.py
+++ b/scripts/update_device.py
@@ -483,6 +483,10 @@
                       help='Wipe userdata after installing OTA')
   parser.add_argument('--disable-vabc', action='store_true',
                       help='Disable vabc during OTA')
+  parser.add_argument('--enable-threading', action='store_true',
+                      help='Enable multi-threaded compression for VABC')
+  parser.add_argument('--batched-writes', action='store_true',
+                      help='Enable batched writes for VABC')
   parser.add_argument('--speed-limit', type=str,
                       help='Speed limit for serving payloads over HTTP. For '
                       'example: 10K, 5m, 1G, input is case insensitive')
@@ -545,6 +549,10 @@
     args.extra_headers += "\nPOWERWASH=1"
   if args.disable_vabc:
     args.extra_headers += "\nDISABLE_VABC=1"
+  if args.enable_threading:
+    args.extra_headers += "\nENABLE_THREADING=1"
+  if args.batched_writes:
+    args.extra_headers += "\nBATCHED_WRITES=1"
 
   with zipfile.ZipFile(args.otafile) as zfp:
     CARE_MAP_ENTRY_NAME = "care_map.pb"