Partition_Property_Get: Get props from additional partitions

Use the TW_OVERRIDE_PROPS_ADDITIONAL_PARTITIONS flag to
specify a space-separated list of additional partitions
that should be parsed when trying to locate props
for overriding.

Example:
TW_OVERRIDE_PROPS_ADDITIONAL_PARTITIONS := vendor odm

Requires TW_OVERRIDE_SYSTEM_PROPS to be defined.

Change-Id: I7baf4c15628789fe525976d9de0251bba6882395
(cherry picked from commit aafc82e8e263a9e323d789da1193c0de4c77347c)
diff --git a/Android.mk b/Android.mk
index c459fbe..69f2386 100755
--- a/Android.mk
+++ b/Android.mk
@@ -390,6 +390,9 @@
     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 f30206b..73399b3 100755
--- a/twrp-functions.cpp
+++ b/twrp-functions.cpp
@@ -881,16 +881,21 @@
 }
 
 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<string> 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 7bec5a6..4c25cf4 100755
--- a/twrp-functions.hpp
+++ b/twrp-functions.hpp
@@ -98,7 +98,7 @@
 	static bool write_to_file(const string& fn, const std::vector<string> 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 c84c99e..dcc5764 100644
--- a/twrp.cpp
+++ b/twrp.cpp
@@ -172,42 +172,62 @@
 
 // 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<std::string> build_prop_list = {"build.prop"};
-#ifdef TW_SYSTEM_BUILD_PROP_ADDITIONAL_PATHS
-		std::vector<std::string> 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);
+	stringstream override_props(EXPAND(TW_OVERRIDE_SYSTEM_PROPS));
+	string current_prop;
 
+	std::vector<std::string> partition_list;
+	partition_list.push_back (PartitionManager.Get_Android_Root_Path().c_str());
+#ifdef TW_OVERRIDE_PROPS_ADDITIONAL_PARTITIONS
+	std::vector<std::string> 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<std::string> build_prop_list = {"build.prop"};
+#ifdef TW_SYSTEM_BUILD_PROP_ADDITIONAL_PATHS
+	std::vector<std::string> 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);
+
+		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