Implement autodetection for SAR, based on the installed system

This will detect whether SAR is present in the currently installed
OS and set the property ro.twrp.sar accordingly.
After setting the property it will call the bootscript
/sbin/sarsetup.sh (if present) to give device maintainers the
option to do setup operations depending on SAR-status, such
as modifiyng the fstab.

If no system is detected and AB_OTA_UPDATER is defined or built with
Android 10 and upwards, it will fallback to using SAR, otherwise it
will use ro.build.system_root_image as basis for deciding whether SAR
is required or not.

The property ro.twrp.sar will also be used by
TWPartitionManager::Get_Android_Root_Path()

This allows maintaining a single TWRP-build for devices switching
to SAR for Android 10.

The default behavior (when no system is installed)
is determined by the build-flags AB_OTA_UPDATER and
BOARD_BUILD_SYSTEM_ROOT_IMAGE

Change-Id: I2a48c6c81a6ea6fad6e452c06bfbe4d9da0f1e5c
This commit is contained in:
Chaosmaster
2020-01-27 00:17:04 +01:00
committed by bigbiff
parent da97480567
commit f6e42ce390
4 changed files with 80 additions and 15 deletions
+24 -8
View File
@@ -272,7 +272,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 TWPartition::Process_Fstab_Line(const char *fstab_line, bool Display_Error, std::map<string, Flags_Map> *twrp_flags, bool Sar_Detect) {
char full_line[MAX_FSTAB_LINE_LENGTH];
char twflags[MAX_FSTAB_LINE_LENGTH] = "";
char* ptr;
@@ -309,11 +309,12 @@ bool TWPartition::Process_Fstab_Line(const char *fstab_line, bool Display_Error,
Mount_Point = ptr;
if (fstab_version == 2) {
additional_entry = PartitionManager.Find_Partition_By_Path(Mount_Point);
if (additional_entry) {
if (!Sar_Detect && additional_entry) {
LOGINFO("Found an additional entry for '%s'\n", Mount_Point.c_str());
}
}
LOGINFO("Processing '%s'\n", Mount_Point.c_str());
if(!Sar_Detect)
LOGINFO("Processing '%s'\n", Mount_Point.c_str());
Backup_Path = Mount_Point;
Storage_Path = Mount_Point;
Display_Name = ptr + 1;
@@ -410,7 +411,12 @@ bool TWPartition::Process_Fstab_Line(const char *fstab_line, bool Display_Error,
if (Primary_Block_Device.find("*") != string::npos)
Wildcard_Block_Device = true;
if (Mount_Point == "auto") {
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") {
Mount_Point = "/auto";
char autoi[5];
sprintf(autoi, "%i", auto_index);
@@ -437,9 +443,6 @@ bool TWPartition::Process_Fstab_Line(const char *fstab_line, bool Display_Error,
Find_Actual_Block_Device();
Setup_File_System(Display_Error);
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_Display_Name = Display_Name;
Storage_Name = Display_Name;
@@ -601,6 +604,19 @@ 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);
}
}
return true;
}
@@ -2911,7 +2927,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);
part->Process_Fstab_Line(buffer, false, NULL, false);
char display[MAX_FSTAB_LINE_LENGTH];
sprintf(display, "%s %i", Storage_Name.c_str(), mount_point_index);
part->Storage_Name = display;