summaryrefslogtreecommitdiffstats
path: root/twrp-functions.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'twrp-functions.cpp')
-rw-r--r--twrp-functions.cpp72
1 files changed, 43 insertions, 29 deletions
diff --git a/twrp-functions.cpp b/twrp-functions.cpp
index df7174362..bbd3c4c9f 100644
--- a/twrp-functions.cpp
+++ b/twrp-functions.cpp
@@ -559,13 +559,21 @@ bool TWFunc::Fix_su_Perms(void) {
if (!PartitionManager.Mount_By_Path("/system", true))
return false;
+ string propvalue = System_Property_Get("ro.build.version.sdk");
+ string su_perms = "6755";
+ if (!propvalue.empty()) {
+ int sdk_version = atoi(propvalue.c_str());
+ if (sdk_version >= 18)
+ su_perms = "0755";
+ }
+
string file = "/system/bin/su";
if (TWFunc::Path_Exists(file)) {
if (chown(file.c_str(), 0, 0) != 0) {
LOGERR("Failed to chown '%s'\n", file.c_str());
return false;
}
- if (tw_chmod(file, "6755") != 0) {
+ if (tw_chmod(file, su_perms) != 0) {
LOGERR("Failed to chmod '%s'\n", file.c_str());
return false;
}
@@ -576,7 +584,7 @@ bool TWFunc::Fix_su_Perms(void) {
LOGERR("Failed to chown '%s'\n", file.c_str());
return false;
}
- if (tw_chmod(file, "6755") != 0) {
+ if (tw_chmod(file, su_perms) != 0) {
LOGERR("Failed to chmod '%s'\n", file.c_str());
return false;
}
@@ -587,7 +595,7 @@ bool TWFunc::Fix_su_Perms(void) {
LOGERR("Failed to chown '%s'\n", file.c_str());
return false;
}
- if (tw_chmod(file, "6755") != 0) {
+ if (tw_chmod(file, "0755") != 0) {
LOGERR("Failed to chmod '%s'\n", file.c_str());
return false;
}
@@ -598,7 +606,7 @@ bool TWFunc::Fix_su_Perms(void) {
LOGERR("Failed to chown '%s'\n", file.c_str());
return false;
}
- if (tw_chmod(file, "6755") != 0) {
+ if (tw_chmod(file, su_perms) != 0) {
LOGERR("Failed to chmod '%s'\n", file.c_str());
return false;
}
@@ -980,50 +988,56 @@ string TWFunc::Get_Current_Date() {
return Current_Date;
}
-void TWFunc::Auto_Generate_Backup_Name() {
+string TWFunc::System_Property_Get(string Prop_Name) {
bool mount_state = PartitionManager.Is_Mounted_By_Path("/system");
std::vector<string> buildprop;
- if (!PartitionManager.Mount_By_Path("/system", true)) {
- DataManager::SetValue(TW_BACKUP_NAME, Get_Current_Date());
- return;
- }
+ string propvalue;
+ if (!PartitionManager.Mount_By_Path("/system", true))
+ return propvalue;
if (TWFunc::read_file("/system/build.prop", buildprop) != 0) {
- LOGINFO("Unable to open /system/build.prop for getting backup name.\n");
+ LOGINFO("Unable to open /system/build.prop for getting '%s'.\n", Prop_Name.c_str());
DataManager::SetValue(TW_BACKUP_NAME, Get_Current_Date());
if (!mount_state)
PartitionManager.UnMount_By_Path("/system", false);
- return;
+ return propvalue;
}
int line_count = buildprop.size();
int index;
size_t start_pos = 0, end_pos;
- string propname, propvalue;
+ string propname;
for (index = 0; index < line_count; index++) {
end_pos = buildprop.at(index).find("=", start_pos);
propname = buildprop.at(index).substr(start_pos, end_pos);
- if (propname == "ro.build.display.id") {
+ if (propname == Prop_Name) {
propvalue = buildprop.at(index).substr(end_pos + 1, buildprop.at(index).size());
- string Backup_Name = Get_Current_Date();
- Backup_Name += " " + propvalue;
- if (Backup_Name.size() > MAX_BACKUP_NAME_LEN)
- Backup_Name.resize(MAX_BACKUP_NAME_LEN);
- // Trailing spaces cause problems on some file systems, so remove them
- string space_check, space = " ";
- space_check = Backup_Name.substr(Backup_Name.size() - 1, 1);
- while (space_check == space) {
- Backup_Name.resize(Backup_Name.size() - 1);
- space_check = Backup_Name.substr(Backup_Name.size() - 1, 1);
- }
- DataManager::SetValue(TW_BACKUP_NAME, Backup_Name);
- break;
+ if (!mount_state)
+ PartitionManager.UnMount_By_Path("/system", false);
+ return propvalue;
}
}
+ if (!mount_state)
+ PartitionManager.UnMount_By_Path("/system", false);
+ return propvalue;
+}
+
+void TWFunc::Auto_Generate_Backup_Name() {
+ string propvalue = System_Property_Get("ro.build.display.id");
if (propvalue.empty()) {
- LOGINFO("ro.build.display.id not found in build.prop\n");
DataManager::SetValue(TW_BACKUP_NAME, Get_Current_Date());
+ return;
}
- if (!mount_state)
- PartitionManager.UnMount_By_Path("/system", false);
+ string Backup_Name = Get_Current_Date();
+ Backup_Name += " " + propvalue;
+ if (Backup_Name.size() > MAX_BACKUP_NAME_LEN)
+ Backup_Name.resize(MAX_BACKUP_NAME_LEN);
+ // Trailing spaces cause problems on some file systems, so remove them
+ string space_check, space = " ";
+ space_check = Backup_Name.substr(Backup_Name.size() - 1, 1);
+ while (space_check == space) {
+ Backup_Name.resize(Backup_Name.size() - 1);
+ space_check = Backup_Name.substr(Backup_Name.size() - 1, 1);
+ }
+ DataManager::SetValue(TW_BACKUP_NAME, Backup_Name);
}
void TWFunc::Fixup_Time_On_Boot()