Skip to content

Commit

Permalink
Revert "Implement autodetection for SAR, based on the installed system"
Browse files Browse the repository at this point in the history
This reverts commit d6b7de5.

Signed-off-by: Mohd Faraz <[email protected]>
  • Loading branch information
AndroiableDroid committed May 14, 2022
1 parent 1d1043f commit e8d12e4
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 82 deletions.
37 changes: 8 additions & 29 deletions partition.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ TWPartition::~TWPartition(void) {
// Do nothing
}

bool TWPartition::Process_Fstab_Line(const char *fstab_line, bool Display_Error, std::map<string, Flags_Map> *twrp_flags, bool Sar_Detect) {
bool TWPartition::Process_Fstab_Line(const char *fstab_line, bool Display_Error, std::map<string, Flags_Map> *twrp_flags) {
char full_line[MAX_FSTAB_LINE_LENGTH];
char twflags[MAX_FSTAB_LINE_LENGTH] = "";
char* ptr;
Expand Down Expand Up @@ -339,12 +339,11 @@ bool TWPartition::Process_Fstab_Line(const char *fstab_line, bool Display_Error,
Mount_Point = ptr;
if (fstab_version == 2 && Is_Super == false) {
additional_entry = PartitionManager.Find_Partition_By_Path(Mount_Point);
if (!Sar_Detect && additional_entry) {
if (additional_entry) {
LOGINFO("Found an additional entry for '%s'\n", Mount_Point.c_str());
}
}
if(!Sar_Detect)
LOGINFO("Processing '%s'\n", Mount_Point.c_str());
LOGINFO("Processing '%s'\n", Mount_Point.c_str());
Backup_Path = Mount_Point;
Storage_Path = Mount_Point;
Display_Name = ptr + 1;
Expand Down Expand Up @@ -436,12 +435,7 @@ bool TWPartition::Process_Fstab_Line(const char *fstab_line, bool Display_Error,
if (Primary_Block_Device.find("*") != string::npos)
Wildcard_Block_Device = true;

if (Sar_Detect) {
if(Is_File_System(Fstab_File_System) && (Mount_Point == "/" || Mount_Point == "/system" || Mount_Point == "/system_root"))
Find_Actual_Block_Device();
else
return true;
} else if (Mount_Point == "auto") {
if (Mount_Point == "auto") {
Mount_Point = "/auto";
char autoi[5];
sprintf(autoi, "%i", auto_index);
Expand Down Expand Up @@ -470,6 +464,9 @@ bool TWPartition::Process_Fstab_Line(const char *fstab_line, bool Display_Error,
Setup_File_System(Display_Error);
Backup_Name = Display_Name = Mount_Point.substr(1, Mount_Point.size() - 1);
if (Mount_Point == "/" || Mount_Point == "/system" || Mount_Point == "/system_root") {
Mount_Point = PartitionManager.Get_Android_Root_Path();
Backup_Path = Mount_Point;
Storage_Path = Mount_Point;
Display_Name = "System";
Backup_Name = "system";
Backup_Display_Name = Display_Name;
Expand Down Expand Up @@ -646,24 +643,6 @@ bool TWPartition::Process_Fstab_Line(const char *fstab_line, bool Display_Error,
}
}

if (Is_File_System(Fstab_File_System) && (Mount_Point == "/" || Mount_Point == "/system" || Mount_Point == "/system_root")) {
if (Sar_Detect) {
Mount_Point = "/s";
Mount_Read_Only = true;
Can_Be_Mounted = true;
} else {
Mount_Point = PartitionManager.Get_Android_Root_Path();
Backup_Path = Mount_Point;
Storage_Path = Mount_Point;
Make_Dir(Mount_Point, Display_Error);
}
if (Is_Super) {
Can_Be_Backed_Up = false;
Can_Be_Wiped = false;
Wipe_Available_in_GUI = false;
}
}

return true;
}

Expand Down Expand Up @@ -3101,7 +3080,7 @@ bool TWPartition::Find_Wildcard_Block_Devices(const string& Device) {
TWPartition *part = new TWPartition;
char buffer[MAX_FSTAB_LINE_LENGTH];
sprintf(buffer, "%s %s-%i auto defaults defaults", item.c_str(), Mount_Point.c_str(), ++mount_point_index);
part->Process_Fstab_Line(buffer, false, NULL, false);
part->Process_Fstab_Line(buffer, false, NULL);
char display[MAX_FSTAB_LINE_LENGTH];
sprintf(display, "%s %i", Storage_Name.c_str(), mount_point_index);
part->Storage_Name = display;
Expand Down
11 changes: 4 additions & 7 deletions partitionmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,7 @@ int TWPartitionManager::Set_Crypto_Type(const char* crypto_type) {
return 0;
}

int TWPartitionManager::Process_Fstab(string Fstab_Filename, bool Display_Error, bool recovery_mode,
bool Sar_Detect) {
int TWPartitionManager::Process_Fstab(string Fstab_Filename, bool Display_Error, bool recovery_mode) {
FILE* fstabFile;
char fstab_line[MAX_FSTAB_LINE_LENGTH];
std::map<string, Flags_Map> twrp_flags;
Expand Down Expand Up @@ -239,7 +238,7 @@ int TWPartitionManager::Process_Fstab(string Fstab_Filename, bool Display_Error,
if (fstab_line[line_size - 1] != '\n') fstab_line[line_size] = '\n';

TWPartition* partition = new TWPartition();
if (partition->Process_Fstab_Line(fstab_line, Display_Error, &twrp_flags, Sar_Detect))
if (partition->Process_Fstab_Line(fstab_line, Display_Error, &twrp_flags))
Partitions.push_back(partition);
else
delete partition;
Expand All @@ -255,8 +254,7 @@ int TWPartitionManager::Process_Fstab(string Fstab_Filename, bool Display_Error,
mapit != twrp_flags.end(); mapit++) {
if (Find_Partition_By_Path(mapit->first) == NULL) {
TWPartition* partition = new TWPartition();
if (partition->Process_Fstab_Line(mapit->second.fstab_line, Display_Error, NULL,
Sar_Detect))
if (partition->Process_Fstab_Line(mapit->second.fstab_line, Display_Error, NULL))
Partitions.push_back(partition);
else
delete partition;
Expand Down Expand Up @@ -3363,8 +3361,7 @@ string TWPartitionManager::Get_Active_Slot_Display() {
}

string TWPartitionManager::Get_Android_Root_Path() {
if (property_get_bool("ro.twrp.sar", false)) return "/system_root";
return "/system";
return "/system_root";
}

void TWPartitionManager::Remove_Uevent_Devices(const string& Mount_Point) {
Expand Down
4 changes: 2 additions & 2 deletions partitions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ class TWPartition
void Set_Block_Device(std::string block_device); // Allow super partition setup to change block device

private:
bool Process_Fstab_Line(const char *fstab_line, bool Display_Error, std::map<string, Flags_Map> *twrp_flags, bool Sar_Detect); // Processes a fstab line
bool Process_Fstab_Line(const char *fstab_line, bool Display_Error, std::map<string, Flags_Map> *twrp_flags); // Processes a fstab line
void Setup_Data_Partition(bool Display_Error); // Setup data partition after fstab processed
void Set_FBE_Status(); // Set FBE status of partition
void Setup_Cache_Partition(bool Display_Error); // Setup cache partition after fstab processed
Expand Down Expand Up @@ -317,7 +317,7 @@ class TWPartitionManager
~TWPartitionManager() {}

public:
int Process_Fstab(string Fstab_Filename, bool Display_Error, bool recovery_mode, bool Sar_Detect); // Parses the fstab files
int Process_Fstab(string Fstab_Filename, bool Display_Error, bool recovery_mode); // Parses the fstab files
void Setup_Fstab_Partitions(bool Display_Error); // Populates the partitions
int Write_Fstab(); // Creates /etc/fstab file that's used by the command line for mount commands
void Decrypt_Data(); // Decrypt Data if enabled
Expand Down
46 changes: 2 additions & 44 deletions twrp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -148,51 +148,9 @@ static void process_recovery_mode(twrpAdbBuFifo* adb_bu_fifo, bool skip_decrypti
if (!TWFunc::Path_Exists(fstab_filename))
fstab_filename = "/etc/recovery.fstab";
}

// Begin SAR detection
{
TWPartitionManager SarPartitionManager;
printf("=> Processing %s for SAR-detection\n", fstab_filename.c_str());
if (!SarPartitionManager.Process_Fstab(fstab_filename, 1, 1, 1)) {
LOGERR("Failing out of recovery due to problem with fstab.\n");
return;
}

mkdir("/s", 0755);

#if defined(AB_OTA_UPDATER) || defined(__ANDROID_API_Q__)
bool fallback_sar = true;
#else
bool fallback_sar = property_get_bool("ro.build.system_root_image", false);
#endif

if(SarPartitionManager.Mount_By_Path("/s", false)) {
if (TWFunc::Path_Exists("/s/build.prop")) {
LOGINFO("SAR-DETECT: Non-SAR System detected\n");
property_set("ro.twrp.sar", "0");
rmdir("/system_root");
} else if (TWFunc::Path_Exists("/s/system/build.prop")) {
LOGINFO("SAR-DETECT: SAR System detected\n");
property_set("ro.twrp.sar", "1");
} else {
LOGINFO("SAR-DETECT: No build.prop found, falling back to %s\n", fallback_sar ? "SAR" : "Non-SAR");
property_set("ro.twrp.sar", fallback_sar ? "1" : "0");
}

SarPartitionManager.UnMount_By_Path("/s", false);
} else {
LOGINFO("SAR-DETECT: Could not mount system partition, falling back to %s\n", fallback_sar ? "SAR":"Non-SAR");
property_set("ro.twrp.sar", fallback_sar ? "1" : "0");
}

rmdir("/s");

TWFunc::check_and_run_script("/system/bin/sarsetup.sh", "boot");
}
// End SAR detection

property_set("ro.twrp.sar", "1");
printf("=> Processing %s\n", fstab_filename.c_str());
if (!PartitionManager.Process_Fstab(fstab_filename, 1, true, false)) {
if (!PartitionManager.Process_Fstab(fstab_filename, 1, true)) {
LOGERR("Failing out of recovery due to problem with fstab.\n");
return;
}
Expand Down

0 comments on commit e8d12e4

Please sign in to comment.