Added support for Delete Task

Test: tested delete-logical-partition {partition} and flashall on Raven

Change-Id: I04f07c8132159deda42434b9178e8c98d5ab768b
Bug: 194686221
diff --git a/fastboot/fastboot.cpp b/fastboot/fastboot.cpp
index ad9b424..699d406 100644
--- a/fastboot/fastboot.cpp
+++ b/fastboot/fastboot.cpp
@@ -1633,6 +1633,19 @@
         // extents, and will achieve more optimal allocation.
         std::vector<std::unique_ptr<ResizeTask>> resize_tasks;
         for (const auto& [image, slot] : os_images_) {
+            // Retrofit devices have two super partitions, named super_a and super_b.
+            // On these devices, secondary slots must be flashed as physical
+            // partitions (otherwise they would not mount on first boot). To enforce
+            // this, we delete any logical partitions for the "other" slot.
+            if (is_retrofit_device()) {
+                std::string partition_name = image->part_name + "_"s + slot;
+                if (image->IsSecondary() && is_logical(partition_name)) {
+                    fp_->fb->DeletePartition(partition_name);
+                    std::unique_ptr<DeleteTask> delete_task =
+                            std::make_unique<DeleteTask>(fp_, partition_name);
+                    delete_task->Run();
+                }
+            }
             resize_tasks.emplace_back(
                     std::make_unique<ResizeTask>(fp_, image->part_name, "0", slot));
         }
@@ -2352,6 +2365,7 @@
             fb->CreatePartition(partition, size);
         } else if (command == FB_CMD_DELETE_PARTITION) {
             std::string partition = next_arg(&args);
+            auto delete_task = std::make_unique<DeleteTask>(fp.get(), partition);
             fb->DeletePartition(partition);
         } else if (command == FB_CMD_RESIZE_PARTITION) {
             std::string partition = next_arg(&args);
diff --git a/fastboot/task.cpp b/fastboot/task.cpp
index 799b5c5..e55cda5 100644
--- a/fastboot/task.cpp
+++ b/fastboot/task.cpp
@@ -180,3 +180,9 @@
     };
     do_for_partitions(pname_, slot_, resize_partition, false);
 }
+
+DeleteTask::DeleteTask(FlashingPlan* fp, const std::string& pname) : fp_(fp), pname_(pname){};
+
+void DeleteTask::Run() {
+    fp_->fb->DeletePartition(pname_);
+}
\ No newline at end of file
diff --git a/fastboot/task.h b/fastboot/task.h
index 7aa19a3..b90fcd1 100644
--- a/fastboot/task.h
+++ b/fastboot/task.h
@@ -92,3 +92,13 @@
     const std::string size_;
     const std::string slot_;
 };
+
+class DeleteTask : public Task {
+  public:
+    DeleteTask(FlashingPlan* _fp, const std::string& _pname);
+    void Run() override;
+
+  private:
+    FlashingPlan* fp_;
+    const std::string pname_;
+};