Commit 6277c797 authored by Ethan Yonker's avatar Ethan Yonker Committed by Matt Mower

Attempt to automatically identify data/media devices

Change-Id: Ia3007fbced9ce3bc94efdb3dacc582a5e68a49a4
parent 1eff6cd5
This diff is collapsed.
......@@ -47,12 +47,6 @@ ifeq ($(TWRP_EVENT_LOGGING), true)
LOCAL_CFLAGS += -D_EVENT_LOGGING
endif
ifneq ($(RECOVERY_SDCARD_ON_DATA),)
LOCAL_CFLAGS += -DRECOVERY_SDCARD_ON_DATA
endif
ifneq ($(TW_EXTERNAL_STORAGE_PATH),)
LOCAL_CFLAGS += -DTW_EXTERNAL_STORAGE_PATH=$(TW_EXTERNAL_STORAGE_PATH)
endif
ifneq ($(TW_NO_SCREEN_BLANK),)
LOCAL_CFLAGS += -DTW_NO_SCREEN_BLANK
endif
......
......@@ -73,6 +73,7 @@ extern "C" {
using namespace std;
extern struct selabel_handle *selinux_handle;
extern bool datamedia;
struct flag_list {
const char *name;
......@@ -160,6 +161,7 @@ TWPartition::TWPartition(int *id) {
#ifdef TW_INCLUDE_CRYPTO_SAMSUNG
EcryptFS_Password = "";
#endif
mtpid = 0;
}
TWPartition::~TWPartition(void) {
......@@ -272,27 +274,8 @@ bool TWPartition::Process_Fstab_Line(string Line, bool Display_Error) {
Can_Be_Backed_Up = true;
Can_Encrypt_Backup = true;
Use_Userdata_Encryption = true;
#ifdef RECOVERY_SDCARD_ON_DATA
Storage_Name = "Internal Storage";
Has_Data_Media = true;
Is_Storage = true;
Is_Settings_Storage = true;
Storage_Path = "/data/media";
Symlink_Path = Storage_Path;
if (strcmp(EXPAND(TW_EXTERNAL_STORAGE_PATH), "/sdcard") == 0) {
Make_Dir("/emmc", Display_Error);
Symlink_Mount_Point = "/emmc";
} else {
Make_Dir("/sdcard", Display_Error);
Symlink_Mount_Point = "/sdcard";
}
if (Mount(false) && TWFunc::Path_Exists("/data/media/0")) {
Storage_Path = "/data/media/0";
Symlink_Path = Storage_Path;
DataManager::SetValue(TW_INTERNAL_PATH, "/data/media/0");
UnMount(true);
}
#endif
if (datamedia)
Setup_Data_Media(0);
#ifdef TW_INCLUDE_CRYPTO
Can_Be_Encrypted = true;
char crypto_blkdev[255];
......@@ -343,14 +326,11 @@ bool TWPartition::Process_Fstab_Line(string Line, bool Display_Error) {
// unmounted state
UnMount(false);
}
#ifdef RECOVERY_SDCARD_ON_DATA
if (!Is_Encrypted || (Is_Encrypted && Is_Decrypted))
if (datamedia && (!Is_Encrypted || (Is_Encrypted && Is_Decrypted)))
Recreate_Media_Folder();
#endif
#else
#ifdef RECOVERY_SDCARD_ON_DATA
Recreate_Media_Folder();
#endif
if (datamedia)
Recreate_Media_Folder();
#endif
} else if (Mount_Point == "/cache") {
Display_Name = "Cache";
......@@ -702,6 +682,34 @@ void TWPartition::Setup_AndSec(void) {
Mount_Storage_Retry();
}
void TWPartition::Setup_Data_Media(int mtp) {
LOGINFO("Setting up '%s' as data/media emulated storage.\n", Mount_Point.c_str());
Storage_Name = "Internal Storage";
Has_Data_Media = true;
Is_Storage = true;
Is_Settings_Storage = true;
Storage_Path = "/data/media";
Symlink_Path = Storage_Path;
if (strcmp(EXPAND(TW_EXTERNAL_STORAGE_PATH), "/sdcard") == 0) {
Make_Dir("/emmc", false);
Symlink_Mount_Point = "/emmc";
} else {
Make_Dir("/sdcard", false);
Symlink_Mount_Point = "/sdcard";
}
if (Mount(false) && TWFunc::Path_Exists("/data/media/0")) {
Storage_Path = "/data/media/0";
Symlink_Path = Storage_Path;
DataManager::SetValue(TW_INTERNAL_PATH, "/data/media/0");
UnMount(true);
}
if (mtp)
mtpid = mtp;
DataManager::SetValue("tw_has_internal", 1);
DataManager::SetValue("tw_has_data_media", 1);
du.add_absolute_dir("/data/media");
}
void TWPartition::Find_Real_Block_Device(string& Block, bool Display_Error) {
char device[512], realDevice[512];
......
......@@ -56,6 +56,8 @@ extern "C" {
#endif
#endif
extern bool datamedia;
TWPartitionManager::TWPartitionManager(void) {
mtpid = 100;
mtp_was_enabled = false;
......@@ -100,6 +102,16 @@ int TWPartitionManager::Process_Fstab(string Fstab_Filename, bool Display_Error)
}
}
fclose(fstabFile);
if (!datamedia && !settings_partition && Find_Partition_By_Path("/sdcard") == NULL && Find_Partition_By_Path("/internal_sd") == NULL && Find_Partition_By_Path("/internal_sdcard") == NULL && Find_Partition_By_Path("/emmc") == NULL) {
// Attempt to automatically identify /data/media emulated storage devices
TWPartition* Dat = Find_Partition_By_Path("/data");
if (Dat) {
LOGINFO("Using automatic handling for /data/media emulated storage device.\n");
datamedia = true;
Dat->Setup_Data_Media(++mtpid);
settings_partition = Dat;
}
}
if (!settings_partition) {
std::vector<TWPartition*>::iterator iter;
for (iter = Partitions.begin(); iter != Partitions.end(); iter++) {
......@@ -168,10 +180,8 @@ void TWPartitionManager::Setup_Settings_Storage_Partition(TWPartition* Part) {
void TWPartitionManager::Setup_Android_Secure_Location(TWPartition* Part) {
if (Part->Has_Android_Secure)
Part->Setup_AndSec();
#ifndef RECOVERY_SDCARD_ON_DATA
else
else if (!datamedia)
Part->Setup_AndSec();
#endif
}
void TWPartitionManager::Output_Partition_Logging(void) {
......@@ -270,9 +280,12 @@ void TWPartitionManager::Output_Partition(TWPartition* Part) {
if (!Part->MTD_Name.empty())
printf(" MTD_Name: %s\n", Part->MTD_Name.c_str());
string back_meth = Part->Backup_Method_By_Name();
printf(" Backup_Method: %s\n\n", back_meth.c_str());
printf(" Backup_Method: %s\n", back_meth.c_str());
if (Part->Mount_Flags || !Part->Mount_Options.empty())
printf(" Mount_Flags=0x%8x, Mount_Options=%s\n", Part->Mount_Flags, Part->Mount_Options.c_str());
if (Part->mtpid)
printf(" MTP Storage ID: %i\n", Part->mtpid);
printf("\n");
}
int TWPartitionManager::Mount_By_Path(string Path, bool Display_Error) {
......@@ -1660,15 +1673,13 @@ int TWPartitionManager::Decrypt_Device(string Password) {
// Sleep for a bit so that the device will be ready
sleep(1);
#ifdef RECOVERY_SDCARD_ON_DATA
if (dat->Mount(false) && TWFunc::Path_Exists("/data/media/0")) {
if (dat->Has_Data_Media && dat->Mount(false) && TWFunc::Path_Exists("/data/media/0")) {
dat->Storage_Path = "/data/media/0";
dat->Symlink_Path = dat->Storage_Path;
DataManager::SetValue("tw_storage_path", "/data/media/0");
dat->UnMount(false);
Output_Partition(dat);
}
#endif
Update_System_Details();
UnMount_Main_Partitions();
} else
......@@ -1843,9 +1854,9 @@ void TWPartitionManager::UnMount_Main_Partitions(void) {
TWPartition* Boot_Partition = Find_Partition_By_Path("/boot");
UnMount_By_Path("/system", true);
#ifndef RECOVERY_SDCARD_ON_DATA
UnMount_By_Path("/data", true);
#endif
if (!datamedia)
UnMount_By_Path("/data", true);
if (Boot_Partition != NULL && Boot_Partition->Can_Be_Mounted)
Boot_Partition->UnMount(true);
}
......
......@@ -76,6 +76,7 @@ public:
protected:
bool Has_Data_Media; // Indicates presence of /data/media, may affect wiping and backup methods
void Setup_Data_Media(int mtp); // Sets up a partition as a /data/media emulated storage partition
private:
bool Process_Fstab_Line(string Line, bool Display_Error); // Processes a fstab line
......
......@@ -51,6 +51,7 @@ struct selabel_handle *selinux_handle;
TWPartitionManager PartitionManager;
int Log_Offset;
bool datamedia;
twrpDU du;
static void Print_Prop(const char *key, const char *name, void *cookie) {
......@@ -76,6 +77,10 @@ int main(int argc, char **argv) {
return 0;
}
#ifdef RECOVERY_SDCARD_ON_DATA
datamedia = true;
#endif
char crash_prop_val[PROPERTY_VALUE_MAX];
int crash_counter;
property_get("twrp.crash_counter", crash_prop_val, "-1");
......
......@@ -33,14 +33,13 @@ extern "C" {
using namespace std;
extern bool datamedia;
twrpDU::twrpDU() {
add_relative_dir(".");
add_relative_dir("..");
add_relative_dir("lost+found");
add_absolute_dir("/data/data/com.google.android.music/files");
#ifdef RECOVERY_SDCARD_ON_DATA
add_absolute_dir("/data/media");
#endif
add_relative_dir(".");
add_relative_dir("..");
add_relative_dir("lost+found");
add_absolute_dir("/data/data/com.google.android.music/files");
}
void twrpDU::add_relative_dir(const string& dir) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment