Skip to content

Commit

Permalink
System_Property_Get: Allow specifying multiple prop file paths
Browse files Browse the repository at this point in the history
Some OEMs include prop files in custom locations. Add these to
a list and parse when setting properties.

Use the flag TW_SYSTEM_BUILD_PROP_ADDITIONAL_PATHS followed
by a semi-colon-separated list of paths (relative to /system)
where the additional prop files can be found.

The standard build.prop file does not need to be specified and
will always be parsed.

Example:
TW_SYSTEM_BUILD_PROP_ADDITIONAL_PATHS := etc/buildinfo/oem_build.prop;etc/prop.default

Change-Id: Ie0e25c7d2575d928310ff1b4fc1aef44a83784ca
  • Loading branch information
CaptainThrowback committed Jan 2, 2022
1 parent 922b121 commit a185252
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 15 deletions.
4 changes: 4 additions & 0 deletions Android.mk
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,10 @@ ifeq ($(PRODUCT_USE_DYNAMIC_PARTITIONS),true)
endif
endif

ifneq ($(TW_SYSTEM_BUILD_PROP_ADDITIONAL_PATHS),)
LOCAL_CFLAGS += -DTW_SYSTEM_BUILD_PROP_ADDITIONAL_PATHS='"$(TW_SYSTEM_BUILD_PROP_ADDITIONAL_PATHS)"'
endif

ifeq ($(TW_USES_VENDOR_LIBS),true)
LOCAL_CFLAGS += -DUSE_VENDOR_LIBS=1
endif
Expand Down
14 changes: 8 additions & 6 deletions twrp-functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -855,20 +855,22 @@ 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());
return System_Property_Get(Prop_Name, PartitionManager, PartitionManager.Get_Android_Root_Path(), "");
}

string TWFunc::System_Property_Get(string Prop_Name, TWPartitionManager &PartitionManager, string Mount_Point) {
string TWFunc::System_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;
if (!PartitionManager.Mount_By_Path(Mount_Point, true))
return propvalue;
string prop_file = Mount_Point + "/build.prop";
if (!TWFunc::Path_Exists(prop_file))
prop_file = Mount_Point + "/system/build.prop"; // for devices with system as a root file system (e.g. Pixel)
string prop_file = Mount_Point + "/system/" + prop_file_name;
if (!TWFunc::Path_Exists(prop_file)) {
LOGINFO("Unable to locate file: %s\n", prop_file.c_str());
return propvalue;
}
if (TWFunc::read_file(prop_file, buildprop) != 0) {
LOGINFO("Unable to open build.prop for getting '%s'.\n", Prop_Name.c_str());
LOGINFO("Unable to open %s for getting '%s'.\n", prop_file_name.c_str(), Prop_Name.c_str());
DataManager::SetValue(TW_BACKUP_NAME, Get_Current_Date());
if (!mount_state)
PartitionManager.UnMount_By_Path(Mount_Point, false);
Expand Down
2 changes: 1 addition & 1 deletion twrp-functions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,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); // 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 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
25 changes: 17 additions & 8 deletions twrp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,11 @@ static void process_recovery_mode(twrpAdbBuFifo* adb_bu_fifo, bool skip_decrypti
} 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) {
Expand All @@ -184,15 +189,19 @@ static void process_recovery_mode(twrpAdbBuFifo* adb_bu_fifo, bool skip_decrypti
}
other_prop = android::base::Trim(other_prop);
current_prop = android::base::Trim(current_prop);
string sys_val = TWFunc::System_Property_Get(other_prop, PartitionManager, PartitionManager.Get_Android_Root_Path().c_str());
if (!sys_val.empty()) {
LOGINFO("Overriding %s with value: \"%s\" from system property %s\n", current_prop.c_str(), sys_val.c_str(), other_prop.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);

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);
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());
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;
} 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());
}
} else {
LOGINFO("Not overriding %s with empty value from system property %s\n", current_prop.c_str(), other_prop.c_str());
}
}
PartitionManager.UnMount_By_Path(PartitionManager.Get_Android_Root_Path(), false);
Expand Down

0 comments on commit a185252

Please sign in to comment.