diff --git a/Android.mk b/Android.mk index 98ae85537..ef6f8267e 100755 --- a/Android.mk +++ b/Android.mk @@ -624,6 +624,9 @@ ifneq ($(TW_OVERRIDE_SYSTEM_PROPS),) TW_INCLUDE_LIBRESETPROP := true LOCAL_CFLAGS += -DTW_OVERRIDE_SYSTEM_PROPS=$(TW_OVERRIDE_SYSTEM_PROPS) endif +ifneq ($(TW_OVERRIDE_PROPS_ADDITIONAL_PARTITIONS),) + LOCAL_CFLAGS += -DTW_OVERRIDE_PROPS_ADDITIONAL_PARTITIONS='"$(TW_OVERRIDE_PROPS_ADDITIONAL_PARTITIONS)"' +endif ifneq ($(TW_INCLUDE_LIBRESETPROP),) LOCAL_SHARED_LIBRARIES += libresetprop LOCAL_C_INCLUDES += external/magisk-prebuilt/include diff --git a/twrp-functions.cpp b/twrp-functions.cpp index ba0551bea..7eefb1be5 100755 --- a/twrp-functions.cpp +++ b/twrp-functions.cpp @@ -898,16 +898,21 @@ string TWFunc::Get_Current_Date() { } string TWFunc::System_Property_Get(string Prop_Name) { - return System_Property_Get(Prop_Name, PartitionManager, PartitionManager.Get_Android_Root_Path(), "build.prop"); + return Partition_Property_Get(Prop_Name, PartitionManager, PartitionManager.Get_Android_Root_Path(), "build.prop"); } -string TWFunc::System_Property_Get(string Prop_Name, TWPartitionManager &PartitionManager, string Mount_Point, string prop_file_name) { +string TWFunc::Partition_Property_Get(string Prop_Name, TWPartitionManager &PartitionManager, string Mount_Point, string prop_file_name) { bool mount_state = PartitionManager.Is_Mounted_By_Path(Mount_Point); std::vector buildprop; string propvalue; + string prop_file; if (!PartitionManager.Mount_By_Path(Mount_Point, true)) return propvalue; - string prop_file = Mount_Point + "/system/" + prop_file_name; + if (Mount_Point == PartitionManager.Get_Android_Root_Path()) { + prop_file = Mount_Point + "/system/" + prop_file_name; + } else { + prop_file = Mount_Point + "/" + prop_file_name; + } if (!TWFunc::Path_Exists(prop_file)) { LOGINFO("Unable to locate file: %s\n", prop_file.c_str()); return propvalue; diff --git a/twrp-functions.hpp b/twrp-functions.hpp index 3252c0167..9a21358fc 100755 --- a/twrp-functions.hpp +++ b/twrp-functions.hpp @@ -98,7 +98,7 @@ class TWFunc static bool write_to_file(const string& fn, const std::vector lines); // write vector of strings line by line with newlines static bool Try_Decrypting_Backup(string Restore_Path, string Password); // true for success, false for failed to decrypt static string System_Property_Get(string Prop_Name); // Returns value of Prop_Name from reading /system/build.prop - static string System_Property_Get(string Prop_Name, TWPartitionManager &PartitionManager, string Mount_Point, string prop_file_name); // Returns value of Prop_Name from reading provided prop file + static string Partition_Property_Get(string Prop_Name, TWPartitionManager &PartitionManager, string Mount_Point, string prop_file_name); // Returns value of Prop_Name from reading provided prop file static string Get_Current_Date(void); // Returns the current date in ccyy-m-dd--hh-nn-ss format static void Auto_Generate_Backup_Name(); // Populates TW_BACKUP_NAME with a backup name based on current date and ro.build.display.id from /system/build.prop static void Fixup_Time_On_Boot(const string& time_paths = ""); // Fixes time on devices which need it (time_paths is a space separated list of paths to check for ats_* files) diff --git a/twrp.cpp b/twrp.cpp index bc4745ff1..adbec866d 100644 --- a/twrp.cpp +++ b/twrp.cpp @@ -186,42 +186,62 @@ static void process_recovery_mode(twrpAdbBuFifo* adb_bu_fifo, bool skip_decrypti // We are doing this here to allow super partition to be set up prior to overriding properties #if defined(TW_INCLUDE_LIBRESETPROP) && defined(TW_OVERRIDE_SYSTEM_PROPS) - if (!PartitionManager.Mount_By_Path(PartitionManager.Get_Android_Root_Path(), true)) { - LOGERR("Unable to mount %s\n", PartitionManager.Get_Android_Root_Path().c_str()); - } else { - stringstream override_props(EXPAND(TW_OVERRIDE_SYSTEM_PROPS)); - string current_prop; - std::vector build_prop_list = {"build.prop"}; + stringstream override_props(EXPAND(TW_OVERRIDE_SYSTEM_PROPS)); + string current_prop; + + std::vector partition_list; + partition_list.push_back (PartitionManager.Get_Android_Root_Path().c_str()); +#ifdef TW_OVERRIDE_PROPS_ADDITIONAL_PARTITIONS + std::vector additional_partition_list = TWFunc::Split_String(TW_OVERRIDE_PROPS_ADDITIONAL_PARTITIONS, " "); + partition_list.insert(partition_list.end(), additional_partition_list.begin(), additional_partition_list.end()); +#endif + std::vector build_prop_list = {"build.prop"}; #ifdef TW_SYSTEM_BUILD_PROP_ADDITIONAL_PATHS - std::vector additional_build_prop_list = TWFunc::Split_String(TW_SYSTEM_BUILD_PROP_ADDITIONAL_PATHS, ";"); - build_prop_list.insert(build_prop_list.end(), additional_build_prop_list.begin(), additional_build_prop_list.end()); + std::vector additional_build_prop_list = TWFunc::Split_String(TW_SYSTEM_BUILD_PROP_ADDITIONAL_PATHS, ";"); + build_prop_list.insert(build_prop_list.end(), additional_build_prop_list.begin(), additional_build_prop_list.end()); #endif - while (getline(override_props, current_prop, ';')) { - string other_prop; - if (current_prop.find("=") != string::npos) { - other_prop = current_prop.substr(current_prop.find("=") + 1); - current_prop = current_prop.substr(0, current_prop.find("=")); - } else { - other_prop = current_prop; - } - other_prop = android::base::Trim(other_prop); - current_prop = android::base::Trim(current_prop); + while (getline(override_props, current_prop, ';')) { + string other_prop; + if (current_prop.find("=") != string::npos) { + other_prop = current_prop.substr(current_prop.find("=") + 1); + current_prop = current_prop.substr(0, current_prop.find("=")); + } else { + other_prop = current_prop; + } + other_prop = android::base::Trim(other_prop); + current_prop = android::base::Trim(current_prop); + for (auto&& partition_mount_point:partition_list) { for (auto&& prop_file:build_prop_list) { - string sys_val = TWFunc::System_Property_Get(other_prop, PartitionManager, PartitionManager.Get_Android_Root_Path().c_str(), prop_file); + string sys_val = TWFunc::Partition_Property_Get(other_prop, PartitionManager, partition_mount_point.c_str(), prop_file); if (!sys_val.empty()) { - LOGINFO("Overriding %s with value: \"%s\" from system property %s from %s\n", current_prop.c_str(), sys_val.c_str(), other_prop.c_str(), prop_file.c_str()); + if (partition_mount_point == "/system_root") { + LOGINFO("Overriding %s with value: \"%s\" from property %s in /system/%s\n", current_prop.c_str(), sys_val.c_str(), other_prop.c_str(), + prop_file.c_str()); + } else { + LOGINFO("Overriding %s with value: \"%s\" from property %s in /%s/%s\n", current_prop.c_str(), sys_val.c_str(), other_prop.c_str(), + partition_mount_point.c_str(), prop_file.c_str()); + } int error = TWFunc::Property_Override(current_prop, sys_val); if (error) { LOGERR("Failed overriding property %s, error_code: %d\n", current_prop.c_str(), error); } - break; + if (partition_mount_point == partition_list.back()) { + PartitionManager.UnMount_By_Path(partition_mount_point, false); + } + goto exit; } else { - LOGINFO("Not overriding %s with empty value from system property %s from %s\n", current_prop.c_str(), other_prop.c_str(), prop_file.c_str()); + if (partition_mount_point == "/system_root") { + LOGINFO("Unable to override property %s: property not found in /system/%s\n", current_prop.c_str(), prop_file.c_str()); + } else { + LOGINFO("Unable to override property %s: property not found in /%s/%s\n", current_prop.c_str(), partition_mount_point.c_str(), prop_file.c_str()); + } } } + PartitionManager.UnMount_By_Path(partition_mount_point, false); } - PartitionManager.UnMount_By_Path(PartitionManager.Get_Android_Root_Path(), false); + exit: + continue; } #endif