[coastguard skipped] Merge sparse cherrypicks from sparse-13018634-L05100030009413150 into 25Q2-release.

COASTGUARD_SKIP: I14c16acf12b86fc6fa7040c5397a4e55790f0ab7
COASTGUARD_SKIP: Id1da2bce7689a41e1154272e8032526d171183f5

Change-Id: I66008c7a3e13f53081135ba9a702b3c38e3f0b1e
diff --git a/aosp/update_attempter_android.cc b/aosp/update_attempter_android.cc
index 943c3e4..b46f584 100644
--- a/aosp/update_attempter_android.cc
+++ b/aosp/update_attempter_android.cc
@@ -1363,6 +1363,7 @@
   // 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 8a68501..82d4827 100644
--- a/common/fake_boot_control.h
+++ b/common/fake_boot_control.h
@@ -40,6 +40,11 @@
     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 ff47171..1717dd7 100644
--- a/payload_consumer/postinstall_runner_action.cc
+++ b/payload_consumer/postinstall_runner_action.cc
@@ -105,42 +105,18 @@
   CHECK(boot_control_);
   install_plan_ = GetInputObject();
 
-<<<<<<< HEAD
   auto dynamic_control = boot_control_->GetDynamicPartitionControl();
   CHECK(dynamic_control);
 
   // 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 (dynamic_control->GetVirtualAbFeatureFlag().IsEnabled()) {
-    // 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()) {
-        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);
-      }
+  if (!install_plan_.partitions.empty() ||
+      install_plan_.switch_slot_on_reboot) {
+    if (!dynamic_control->MapAllPartitions()) {
+      LOG(ERROR) << "Failed to map all partitions, this would cause "
+                    "FinishUpdate to fail. Abort early.";
+      return CompletePostinstall(ErrorCode::kPostInstallMountError);
     }
   }
 
@@ -347,10 +323,10 @@
 
 void PostinstallRunnerAction::OnProgressFdReady() {
   char buf[1024];
-  size_t bytes_read;
+  size_t bytes_read{};
   do {
     bytes_read = 0;
-    bool eof;
+    bool eof = false;
     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 2f2ae38..7416e66 100644
--- a/payload_consumer/postinstall_runner_action_unittest.cc
+++ b/payload_consumer/postinstall_runner_action_unittest.cc
@@ -44,10 +44,14 @@
 #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 {
 
@@ -92,7 +96,6 @@
     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");
@@ -109,17 +112,7 @@
         .WillByDefault(Return(true));
     ON_CALL(*mock_dynamic_control_, UnmapAllPartitions())
         .WillByDefault(Return(true));
-    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
@@ -197,6 +190,7 @@
 
   FakeBootControl fake_boot_control_;
   FakeHardware fake_hardware_;
+  MockDynamicPartitionControl* mock_dynamic_control_;
   PostinstActionProcessorDelegate processor_delegate_;
 
   // The PostinstallRunnerAction delegate receiving the progress updates.
@@ -297,8 +291,6 @@
 // /postinst command which only exits 0.
 TEST_F(PostinstallRunnerActionTest, RunAsRootSimpleTest) {
   ScopedLoopbackDeviceBinder loop(postinstall_image_, false, nullptr);
-  ON_CALL(*mock_dynamic_control_, GetVirtualAbFeatureFlag)
-      .WillByDefault(Return(FeatureFlag(FeatureFlag::Value::LAUNCH)));
 
   RunPostinstallAction(loop.dev(), kPostinstallDefaultScript, false, false);
   EXPECT_EQ(ErrorCode::kSuccess, processor_delegate_.code_);
@@ -310,16 +302,12 @@
 }
 
 TEST_F(PostinstallRunnerActionTest, RunAsRootRunSymlinkFileTest) {
-  ON_CALL(*mock_dynamic_control_, GetVirtualAbFeatureFlag)
-      .WillByDefault(Return(FeatureFlag(FeatureFlag::Value::LAUNCH)));
   ScopedLoopbackDeviceBinder loop(postinstall_image_, false, nullptr);
   RunPostinstallAction(loop.dev(), "bin/postinst_link", false, false);
   EXPECT_EQ(ErrorCode::kSuccess, processor_delegate_.code_);
 }
 
 TEST_F(PostinstallRunnerActionTest, RunAsRootPowerwashRequiredTest) {
-  ON_CALL(*mock_dynamic_control_, GetVirtualAbFeatureFlag)
-      .WillByDefault(Return(FeatureFlag(FeatureFlag::Value::LAUNCH)));
   ScopedLoopbackDeviceBinder loop(postinstall_image_, false, nullptr);
   // Run a simple postinstall program but requiring a powerwash.
   RunPostinstallAction(loop.dev(),
@@ -336,8 +324,6 @@
 // Runs postinstall from a partition file that doesn't mount, so it should
 // fail.
 TEST_F(PostinstallRunnerActionTest, RunAsRootCantMountTest) {
-  ON_CALL(*mock_dynamic_control_, GetVirtualAbFeatureFlag)
-      .WillByDefault(Return(FeatureFlag(FeatureFlag::Value::LAUNCH)));
   RunPostinstallAction("/dev/null", kPostinstallDefaultScript, false, false);
   EXPECT_EQ(ErrorCode::kPostInstallMountError, processor_delegate_.code_);
 
@@ -348,8 +334,6 @@
 }
 
 TEST_F(PostinstallRunnerActionTest, RunAsRootSkipOptionalPostinstallTest) {
-  ON_CALL(*mock_dynamic_control_, GetVirtualAbFeatureFlag)
-      .WillByDefault(Return(FeatureFlag(FeatureFlag::Value::LAUNCH)));
   ScopedLoopbackDeviceBinder loop(postinstall_image_, false, nullptr);
   InstallPlan::Partition part;
   part.name = "part";
@@ -419,7 +403,6 @@
 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,
@@ -427,30 +410,11 @@
   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_);
 }
 
 // Test that we can cancel a postinstall action while it is running.
 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));
 
@@ -466,8 +430,6 @@
 // Test that we parse and process the progress reports from the progress
 // file descriptor.
 TEST_F(PostinstallRunnerActionTest, RunAsRootProgressUpdatesTest) {
-  ON_CALL(*mock_dynamic_control_, GetVirtualAbFeatureFlag)
-      .WillByDefault(Return(FeatureFlag(FeatureFlag::Value::LAUNCH)));
   EXPECT_CALL(*mock_dynamic_control_, MapAllPartitions())
       .Times(AtLeast(1))
       .WillRepeatedly(Return(true));