From 63573b550ffb6e35458a80e7012125dd93f6d653 Mon Sep 17 00:00:00 2001 From: Captain Throwback Date: Sat, 2 Oct 2021 20:47:33 -0400 Subject: [PATCH] mtp: don't create storage device after format data Since we don't re-create data/media on FBE devices, don't create an MTP storage device for it. This fixes the bug when, after formatting data on and FBE device, an empty Internal Storage appears on the PC. This also prevents an empty storage device from being created if recovery is rebooted after formatting data before booting to Android. A warning will appear in the console that MTP is disabled in that case. Currently the path is hardcoded to data/media; this should probably be adjusted for cases where adoptable storage is being used. Change-Id: Iaafc5e3cde54c3ef6ffaf33f76d14c626b6e590d --- gui/theme/common/languages/en.xml | 1 + partition.cpp | 11 ++++++----- partitionmanager.cpp | 6 ++++++ 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/gui/theme/common/languages/en.xml b/gui/theme/common/languages/en.xml index f1b93b55..f58a76e9 100755 --- a/gui/theme/common/languages/en.xml +++ b/gui/theme/common/languages/en.xml @@ -615,6 +615,7 @@ MTP already enabled Failed to enable MTP MTP support not included + Media storage not found. Unable to enable MTP. [IMAGE FLASH STARTED] Image to flash: '{1}' Unable to locate '{1}' partition for flashing. diff --git a/partition.cpp b/partition.cpp index bc60e385..f71f36fb 100755 --- a/partition.cpp +++ b/partition.cpp @@ -1733,7 +1733,7 @@ bool TWPartition::Wipe(string New_File_System) { } } - if (Is_Storage && Mount(false)) + if (Is_Storage && Mount(false) && !Is_FBE) PartitionManager.Add_MTP_Storage(MTP_Storage_ID); } @@ -2048,16 +2048,17 @@ bool TWPartition::Wipe_Encryption() { Is_Encrypted = false; if (Wipe(Fstab_File_System)) { Has_Data_Media = Save_Data_Media; - if (Has_Data_Media && !Symlink_Mount_Point.empty()) { - if (Mount(false)) - PartitionManager.Add_MTP_Storage(MTP_Storage_ID); - } DataManager::SetValue(TW_IS_ENCRYPTED, 0); #ifndef TW_OEM_BUILD gui_msg("format_data_msg=You may need to reboot recovery to be able to use /data again."); #endif if (Is_FBE) { gui_msg(Msg(msg::kWarning, "data_media_fbe_msg=TWRP will not recreate /data/media on an FBE device. Please reboot into your rom to create /data/media.")); + } else { + if (Has_Data_Media && !Symlink_Mount_Point.empty()) { + if (Mount(false)) + PartitionManager.Add_MTP_Storage(MTP_Storage_ID); + } } ret = true; diff --git a/partitionmanager.cpp b/partitionmanager.cpp index 285b92a4..4bd7a7dd 100755 --- a/partitionmanager.cpp +++ b/partitionmanager.cpp @@ -2573,6 +2573,12 @@ TWPartition *TWPartitionManager::Get_Default_Storage_Partition() bool TWPartitionManager::Enable_MTP(void) { #ifdef TW_HAS_MTP + string mtp_base_path = "/data/media"; + if (!TWFunc::Path_Exists(mtp_base_path)) { + gui_msg(Msg(msg::kWarning, "mtp_base_path_missing=Media storage not found. Unable to enable MTP.")); + return false; + } + if (mtppid) { gui_err("mtp_already_enabled=MTP already enabled"); return true;