Revert "Map all partitions before calling FinishUpdate for VAB as well"

This reverts commit b88b4ba12ade135e251139f4ed42ba6f3ead5d3f.

Reason for revert: Staging revert to test as a fix for b/394735624
(cherry picked from https://android-review.googlesource.com/q/commit:1cbbbb0772a666f60427dbbd122ff5189db424f8)

ATTENTION: Conflicts occurred while applying the patch.
Please resolve conflict markers.
(cherry picked from https://googleplex-android-review.googlesource.com/q/commit:6de5633f32f83cd0c2a4cc54c7a8846ee0712b52)
Merged-In: Id1da2bce7689a41e1154272e8032526d171183f5
Change-Id: Id1da2bce7689a41e1154272e8032526d171183f5
diff --git a/aosp/update_attempter_android.cc b/aosp/update_attempter_android.cc
index b46f584..943c3e4 100644
--- a/aosp/update_attempter_android.cc
+++ b/aosp/update_attempter_android.cc
@@ -1363,7 +1363,6 @@
   // previous ApplyPayload() call may have requested powerwash, these
   // settings would be saved in `this->install_plan_`. Inherit that setting.
   install_plan_.powerwash_required = this->install_plan_.powerwash_required;
-  install_plan_.switch_slot_on_reboot = true;
 
   CHECK_NE(install_plan_.source_slot, UINT32_MAX);
   CHECK_NE(install_plan_.target_slot, UINT32_MAX);
diff --git a/common/fake_boot_control.h b/common/fake_boot_control.h
index 82d4827..8a68501 100644
--- a/common/fake_boot_control.h
+++ b/common/fake_boot_control.h
@@ -40,11 +40,6 @@
     dynamic_partition_control_.reset(new DynamicPartitionControlStub());
   }
 
-  void SetDynamicPartitionControl(
-      std::unique_ptr<DynamicPartitionControlInterface> dynamic_control) {
-    dynamic_partition_control_ = std::move(dynamic_control);
-  }
-
   // BootControlInterface overrides.
   unsigned int GetNumSlots() const override { return num_slots_; }
   BootControlInterface::Slot GetCurrentSlot() const override {
diff --git a/payload_consumer/postinstall_runner_action.cc b/payload_consumer/postinstall_runner_action.cc
index 84237b1..ff47171 100644
--- a/payload_consumer/postinstall_runner_action.cc
+++ b/payload_consumer/postinstall_runner_action.cc
@@ -105,6 +105,7 @@
   CHECK(boot_control_);
   install_plan_ = GetInputObject();
 
+<<<<<<< HEAD
   auto dynamic_control = boot_control_->GetDynamicPartitionControl();
   CHECK(dynamic_control);
 
@@ -120,6 +121,24 @@
       if (!dynamic_control->MapAllPartitions()) {
         LOG(ERROR) << "Failed to map all partitions, this would cause "
                       "FinishUpdate to fail. Abort early.";
+=======
+  auto dynamic_control = boot_control_->GetDynamicPartitionControl();
+  CHECK(dynamic_control);
+
+  // Mount snapshot partitions for Virtual AB Compression Compression.
+  if (dynamic_control->UpdateUsesSnapshotCompression()) {
+    // If we are switching slots, then we are required to MapAllPartitions,
+    // as FinishUpdate() requires all partitions to be mapped.
+    // And switching slots requires FinishUpdate() to be called first
+    if (!install_plan_.partitions.empty() ||
+        install_plan_.switch_slot_on_reboot) {
+      if (!dynamic_control->MapAllPartitions()) {
+        return CompletePostinstall(ErrorCode::kPostInstallMountError);
+      }
+    }
+  }
+
+>>>>>>> PATCH
         return CompletePostinstall(ErrorCode::kPostInstallMountError);
       }
     }
@@ -328,10 +347,10 @@
 
 void PostinstallRunnerAction::OnProgressFdReady() {
   char buf[1024];
-  size_t bytes_read{};
+  size_t bytes_read;
   do {
     bytes_read = 0;
-    bool eof = false;
+    bool eof;
     bool ok =
         utils::ReadAll(progress_fd_, buf, std::size(buf), &bytes_read, &eof);
     progress_buffer_.append(buf, bytes_read);
diff --git a/payload_consumer/postinstall_runner_action_unittest.cc b/payload_consumer/postinstall_runner_action_unittest.cc
index 74775ad..2f2ae38 100644
--- a/payload_consumer/postinstall_runner_action_unittest.cc
+++ b/payload_consumer/postinstall_runner_action_unittest.cc
@@ -44,14 +44,10 @@
 #include "update_engine/common/subprocess.h"
 #include "update_engine/common/test_utils.h"
 #include "update_engine/common/utils.h"
-#include "update_engine/common/mock_dynamic_partition_control.h"
 
 using brillo::MessageLoop;
 using chromeos_update_engine::test_utils::ScopedLoopbackDeviceBinder;
 using std::string;
-using testing::_;
-using testing::AtLeast;
-using testing::Return;
 
 namespace chromeos_update_engine {
 
@@ -96,6 +92,7 @@
     async_signal_handler_.Init();
     subprocess_.Init(&async_signal_handler_);
     // These tests use the postinstall files generated by "generate_images.sh"
+<<<<<<< HEAD
     // stored in the "disk_ext2_unittest.img" image.
     postinstall_image_ =
         test_utils::GetBuildArtifactsPath("gen/disk_ext2_unittest.img");
@@ -115,6 +112,14 @@
     ON_CALL(*mock_dynamic_control_, GetVirtualAbFeatureFlag)
         .WillByDefault(Return(FeatureFlag(FeatureFlag::Value::NONE)));
   }
+=======
+    // stored in the "disk_ext2_unittest.img" image.
+    postinstall_image_ =
+        test_utils::GetBuildArtifactsPath("gen/disk_ext2_unittest.img");
+  }
+
+  // Setup an action processor and run the PostinstallRunnerAction with a single
+>>>>>>> PATCH
 
   // Setup an action processor and run the PostinstallRunnerAction with a single
   // partition |device_path|, running the |postinstall_program| command from
@@ -192,7 +197,6 @@
 
   FakeBootControl fake_boot_control_;
   FakeHardware fake_hardware_;
-  MockDynamicPartitionControl* mock_dynamic_control_;
   PostinstActionProcessorDelegate processor_delegate_;
 
   // The PostinstallRunnerAction delegate receiving the progress updates.
@@ -415,6 +419,7 @@
 TEST_F(PostinstallRunnerActionTest, RunAsRootSuspendResumeActionTest) {
   ScopedLoopbackDeviceBinder loop(postinstall_image_, false, nullptr);
 
+<<<<<<< HEAD
   // We need to wait for the child to run and setup its signal handler.
   loop_.PostTask(FROM_HERE,
                  base::Bind(&PostinstallRunnerActionTest::SuspendRunningAction,
@@ -422,6 +427,15 @@
   RunPostinstallAction(loop.dev(), "bin/postinst_suspend", false, false);
   // postinst_suspend returns 0 only if it was suspended at some point.
   EXPECT_EQ(ErrorCode::kSuccess, processor_delegate_.code_);
+=======
+// Test that we can cancel a postinstall action while it is running.
+TEST_F(PostinstallRunnerActionTest, RunAsRootCancelPostinstallActionTest) {
+  ScopedLoopbackDeviceBinder loop(postinstall_image_, false, nullptr);
+
+<<<<<<< HEAD
+  // Wait for the action to start and then cancel it.
+  CancelWhenStarted();
+>>>>>>> PATCH
   EXPECT_TRUE(processor_delegate_.processing_done_called_);
 }
 
@@ -429,6 +443,14 @@
 TEST_F(PostinstallRunnerActionTest, RunAsRootCancelPostinstallActionTest) {
   ON_CALL(*mock_dynamic_control_, GetVirtualAbFeatureFlag)
       .WillByDefault(Return(FeatureFlag(FeatureFlag::Value::LAUNCH)));
+=======
+// Test that we parse and process the progress reports from the progress
+// file descriptor.
+TEST_F(PostinstallRunnerActionTest, RunAsRootProgressUpdatesTest) {
+  testing::StrictMock<MockPostinstallRunnerActionDelegate> mock_delegate_;
+  testing::InSequence s;
+  EXPECT_CALL(mock_delegate_, ProgressUpdate(0));
+>>>>>>> PATCH
   ScopedLoopbackDeviceBinder loop(postinstall_image_, false, nullptr);
   EXPECT_CALL(*mock_dynamic_control_, MapAllPartitions()).Times(AtLeast(1));