do not map partitions on A/B devices

For pure AB devices(no VAB), MapAllPartitions() should not be called

Test: th
Bug: 393082101
Change-Id: I3ad44acb83d34d457a05ac8a165604afc19c150f
diff --git a/payload_consumer/postinstall_runner_action.cc b/payload_consumer/postinstall_runner_action.cc
index 1717dd7..84237b1 100644
--- a/payload_consumer/postinstall_runner_action.cc
+++ b/payload_consumer/postinstall_runner_action.cc
@@ -111,12 +111,17 @@
   // 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.";
-      return CompletePostinstall(ErrorCode::kPostInstallMountError);
+  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.";
+        return CompletePostinstall(ErrorCode::kPostInstallMountError);
+      }
     }
   }
 
diff --git a/payload_consumer/postinstall_runner_action_unittest.cc b/payload_consumer/postinstall_runner_action_unittest.cc
index 7416e66..74775ad 100644
--- a/payload_consumer/postinstall_runner_action_unittest.cc
+++ b/payload_consumer/postinstall_runner_action_unittest.cc
@@ -112,6 +112,8 @@
         .WillByDefault(Return(true));
     ON_CALL(*mock_dynamic_control_, UnmapAllPartitions())
         .WillByDefault(Return(true));
+    ON_CALL(*mock_dynamic_control_, GetVirtualAbFeatureFlag)
+        .WillByDefault(Return(FeatureFlag(FeatureFlag::Value::NONE)));
   }
 
   // Setup an action processor and run the PostinstallRunnerAction with a single
@@ -291,6 +293,8 @@
 // /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_);
@@ -302,12 +306,16 @@
 }
 
 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(),
@@ -324,6 +332,8 @@
 // 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_);
 
@@ -334,6 +344,8 @@
 }
 
 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";
@@ -415,6 +427,8 @@
 
 // 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)));
   ScopedLoopbackDeviceBinder loop(postinstall_image_, false, nullptr);
   EXPECT_CALL(*mock_dynamic_control_, MapAllPartitions()).Times(AtLeast(1));
 
@@ -430,6 +444,8 @@
 // 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));