Merge changes I82ac2392,Ie0dd7acd,I8018e48f am: bf18673dee

Original change: https://android-review.googlesource.com/c/platform/system/core/+/2433373

Change-Id: I0fde1d0441538acf0fcd22de65e7815bfbc58d27
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
diff --git a/fastboot/fastboot.cpp b/fastboot/fastboot.cpp
index ffd4f67..0979fd2 100644
--- a/fastboot/fastboot.cpp
+++ b/fastboot/fastboot.cpp
@@ -1588,11 +1588,6 @@
     void FlashImages(const std::vector<std::pair<const Image*, std::string>>& images);
     void FlashImage(const Image& image, const std::string& slot, fastboot_buffer* buf);
 
-    // If the image uses the default slot, or the user specified "all", then
-    // the paired string will be empty. If the image requests a specific slot
-    // (for example, system_other) it is specified instead.
-    using ImageEntry = std::pair<const Image*, std::string>;
-
     std::vector<ImageEntry> boot_images_;
     std::vector<ImageEntry> os_images_;
     FlashingPlan* fp_;
@@ -1621,17 +1616,15 @@
     // or in bootloader fastboot.
     FlashImages(boot_images_);
 
-    auto flash_super_task = FlashSuperLayoutTask::Initialize(fp_, os_images_);
+    std::vector<std::unique_ptr<Task>> tasks;
 
-    if (flash_super_task) {
-        flash_super_task->Run();
+    if (auto flash_super_task = FlashSuperLayoutTask::Initialize(fp_, os_images_)) {
+        tasks.emplace_back(std::move(flash_super_task));
     } else {
         // Sync the super partition. This will reboot to userspace fastboot if needed.
-        std::unique_ptr<UpdateSuperTask> update_super_task = std::make_unique<UpdateSuperTask>(fp_);
-        update_super_task->Run();
+        tasks.emplace_back(std::make_unique<UpdateSuperTask>(fp_));
         // Resize any logical partition to 0, so each partition is reset to 0
         // 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
@@ -1641,17 +1634,14 @@
                 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();
                 }
+                tasks.emplace_back(std::make_unique<DeleteTask>(fp_, partition_name));
             }
-            resize_tasks.emplace_back(
-                    std::make_unique<ResizeTask>(fp_, image->part_name, "0", slot));
+            tasks.emplace_back(std::make_unique<ResizeTask>(fp_, image->part_name, "0", slot));
         }
-        for (auto& i : resize_tasks) {
-            i->Run();
-        }
+    }
+    for (auto& task : tasks) {
+        task->Run();
     }
     FlashImages(os_images_);
 }
diff --git a/fastboot/task.cpp b/fastboot/task.cpp
index 44008e5..29befb7 100644
--- a/fastboot/task.cpp
+++ b/fastboot/task.cpp
@@ -20,11 +20,6 @@
 #include "super_flash_helper.h"
 
 using namespace std::string_literals;
-
-FlashTask::FlashTask(const std::string& slot, const std::string& pname, const bool apply_vbmeta)
-    : pname_(pname), fname_(find_item(pname)), slot_(slot), apply_vbmeta_(apply_vbmeta) {
-    if (fname_.empty()) die("cannot determine image filename for '%s'", pname_.c_str());
-}
 FlashTask::FlashTask(const std::string& _slot, const std::string& _pname, const std::string& _fname,
                      const bool apply_vbmeta)
     : pname_(_pname), fname_(_fname), slot_(_slot), apply_vbmeta_(apply_vbmeta) {}
diff --git a/fastboot/task.h b/fastboot/task.h
index 264e43f..8aa4d2f 100644
--- a/fastboot/task.h
+++ b/fastboot/task.h
@@ -32,7 +32,6 @@
 
 class FlashTask : public Task {
   public:
-    FlashTask(const std::string& slot, const std::string& pname, const bool apply_vbmeta);
     FlashTask(const std::string& slot, const std::string& pname, const std::string& fname,
               const bool apply_vbmeta);