Add DynamicPartitionControlInterface::CleanupSuccessfulUpdate

This is a wrapper over SnapshotManager::WaitForMerge. It waits until the
previous update is merged, then return.

Bug: 138808328
Test: manual with update_engine_client

Change-Id: If44854810f37dd959ffdf3f62f26528867a71fc8
diff --git a/dynamic_partition_control_android.cc b/dynamic_partition_control_android.cc
index bd07165..881ff11 100644
--- a/dynamic_partition_control_android.cc
+++ b/dynamic_partition_control_android.cc
@@ -53,6 +53,7 @@
 using android::snapshot::Return;
 using android::snapshot::SnapshotManager;
 using android::snapshot::SourceCopyOperationIsClone;
+using android::snapshot::UpdateState;
 
 namespace chromeos_update_engine {
 
@@ -697,4 +698,19 @@
   mapped_devices_ = fake;
 }
 
+ErrorCode DynamicPartitionControlAndroid::CleanupSuccessfulUpdate() {
+  // Already reboot into new boot. Clean up.
+  if (!GetVirtualAbFeatureFlag().IsEnabled()) {
+    return ErrorCode::kSuccess;
+  }
+  auto ret = snapshot_->WaitForMerge();
+  if (ret.is_ok()) {
+    return ErrorCode::kSuccess;
+  }
+  if (ret.error_code() == Return::ErrorCode::NEEDS_REBOOT) {
+    return ErrorCode::kError;
+  }
+  return ErrorCode::kDeviceCorrupted;
+}
+
 }  // namespace chromeos_update_engine