Skip to content

Commit

Permalink
Partition_Property_Get: Get props from additional partitions
Browse files Browse the repository at this point in the history
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
  • Loading branch information
CaptainThrowback authored and SIDDK24 committed Mar 3, 2022
1 parent d5eb830 commit 4eb88d8
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 27 deletions.
3 changes: 3 additions & 0 deletions Android.mk
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 8 additions & 3 deletions twrp-functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<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;
Expand Down
2 changes: 1 addition & 1 deletion twrp-functions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ class TWFunc
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)
Expand Down
66 changes: 43 additions & 23 deletions twrp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::string> build_prop_list = {"build.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());
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);
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

Expand Down

0 comments on commit 4eb88d8

Please sign in to comment.