sdcard: only bind mount sdcard after successful preparation of data

Change-Id: I589f48a019f90a60ad48f93c5f5555aae4b8a5c9
(cherry picked from commit cda1588bc5971afbca5420160d433ca2e0379e42)
diff --git a/partitionmanager.cpp b/partitionmanager.cpp
index 8d1b6c4..b24beb3 100755
--- a/partitionmanager.cpp
+++ b/partitionmanager.cpp
@@ -421,8 +421,12 @@
 	TWPartition* Decrypt_Data = Find_Partition_By_Path("/data");
 	if (Decrypt_Data && Decrypt_Data->Is_Encrypted && !Decrypt_Data->Is_Decrypted) {
 		Set_Crypto_State();
-		if (!Decrypt_Data->Key_Directory.empty() && Mount_By_Path(Decrypt_Data->Key_Directory, false)) {
-		Set_Crypto_Type("file");
+		TWPartition* Key_Directory_Partition = Find_Partition_By_Path(Decrypt_Data->Key_Directory);
+		if (Key_Directory_Partition != nullptr)
+			if (!Key_Directory_Partition->Is_Mounted())
+				Mount_By_Path(Decrypt_Data->Key_Directory, false);
+		if (!Decrypt_Data->Key_Directory.empty()) {
+			Set_Crypto_Type("file");
 #ifdef TW_INCLUDE_FBE_METADATA_DECRYPT
 #ifdef USE_FSCRYPT
 			if (fscrypt_mount_metadata_encrypted(Decrypt_Data->Actual_Block_Device, Decrypt_Data->Mount_Point, false)) {
@@ -477,8 +481,7 @@
 			}
 		}
 	}
-	if (Decrypt_Data && (!Decrypt_Data->Is_Encrypted || Decrypt_Data->Is_Decrypted) &&
-	Decrypt_Data->Mount(false)) {
+	if (Decrypt_Data && (!Decrypt_Data->Is_Encrypted || Decrypt_Data->Is_Decrypted)) {
 		Decrypt_Adopted();
 	}
 #endif
@@ -1817,8 +1820,10 @@
 		DataManager::LoadTWRPFolderInfo();
 		Update_System_Details();
 		Output_Partition(dat);
-		if (!dat->Bind_Mount(false))
-			LOGERR("Unable to bind mount /sdcard to %s\n", dat->Storage_Path.c_str());
+		if (!android::base::StartsWith(dat->Actual_Block_Device, "/dev/block/mmcblk")) {
+			if (!dat->Bind_Mount(false))
+				LOGERR("Unable to bind mount /sdcard to %s\n", dat->Storage_Path.c_str());
+		}
 	} else
 		LOGERR("Unable to locate data partition.\n");
 }