vab support: merges and unmapping super devices

- check for merges before formatting data
- add advanced option for unmapping super devices

Change-Id: I38d4d3bbdfa071969016c3e000c86a4d03c71e45
diff --git a/partition.cpp b/partition.cpp
index ba4c9dd..343ccb2 100755
--- a/partition.cpp
+++ b/partition.cpp
@@ -32,6 +32,8 @@
 #include <libgen.h>
 #include <zlib.h>
 #include <sstream>
+#include <android-base/properties.h>
+#include <libsnapshot/snapshot.h>
 
 #include "cutils/properties.h"
 #include "libblkid/include/blkid.h"
@@ -1714,7 +1716,6 @@
 		recreate_media = false;
 	} else {
 		DataManager::GetValue(TW_RM_RF_VAR, check);
-
 		if (check || Use_Rm_Rf)
 			wiped = Wipe_RMRF();
 		else if (New_File_System == "ext4")
@@ -3473,3 +3474,24 @@
 bool TWPartition::Is_SlotSelect() {
 	return SlotSelect;
 }
+
+bool TWPartition::Check_Pending_Merges() {
+	auto sm = android::snapshot::SnapshotManager::NewForFirstStageMount();
+	if (!sm) {
+		LOGERR("Unable to call snapshot manager\n");
+		return false;
+	}
+
+	auto callback = [&]() -> void {
+		double progress;
+		sm->GetUpdateState(&progress);
+		LOGINFO("waiting for merge to complete: %.2f\n", progress);
+	};
+
+	LOGINFO("checking for merges\n");
+	if (!sm->HandleImminentDataWipe(callback)) {
+		LOGERR("Unable to check merge status\n");
+		return false;
+	}
+	return true;
+}
\ No newline at end of file