Merge "twrp: use ANDROID_ROOT environment variable" into android-9.0

This commit is contained in:
big biff
2018-12-24 16:08:07 +01:00
committed by Gerrit Code Review
8 changed files with 41 additions and 33 deletions
+10 -10
View File
@@ -1819,14 +1819,14 @@ int GUIAction::checkpartitionlifetimewrites(std::string arg)
int GUIAction::mountsystemtoggle(std::string arg)
{
int op_status = 0;
bool remount_system = PartitionManager.Is_Mounted_By_Path("/system");
bool remount_system = PartitionManager.Is_Mounted_By_Path(PartitionManager.Get_Android_Root_Path());
bool remount_vendor = PartitionManager.Is_Mounted_By_Path("/vendor");
operation_start("Toggle System Mount");
if (!PartitionManager.UnMount_By_Path("/system", true)) {
if (!PartitionManager.UnMount_By_Path(PartitionManager.Get_Android_Root_Path(), true)) {
op_status = 1; // fail
} else {
TWPartition* Part = PartitionManager.Find_Partition_By_Path("/system");
TWPartition* Part = PartitionManager.Find_Partition_By_Path(PartitionManager.Get_Android_Root_Path());
if (Part) {
if (arg == "0") {
DataManager::SetValue("tw_mount_system_ro", 0);
@@ -1910,9 +1910,9 @@ int GUIAction::checkforapp(std::string arg __unused)
DataManager::SetValue("tw_app_install_status", 1); // 0 = no status, 1 = not installed, 2 = already installed or do not install
goto exit;
}
if (PartitionManager.Mount_By_Path("/system", false)) {
string base_path = "/system";
if (TWFunc::Path_Exists("/system/system"))
if (PartitionManager.Mount_By_Path(PartitionManager.Get_Android_Root_Path(), false)) {
string base_path = PartitionManager.Get_Android_Root_Path();
if (TWFunc::Path_Exists(PartitionManager.Get_Android_Root_Path() + "/system"))
base_path += "/system"; // For devices with system as a root file system (e.g. Pixel)
string install_path = base_path + "/priv-app";
if (!TWFunc::Path_Exists(install_path))
@@ -2007,9 +2007,9 @@ int GUIAction::installapp(std::string arg __unused)
sync();
}
} else {
if (PartitionManager.Mount_By_Path("/system", true)) {
string base_path = "/system";
if (TWFunc::Path_Exists("/system/system"))
if (PartitionManager.Mount_By_Path(PartitionManager.Get_Android_Root_Path(), true)) {
string base_path = PartitionManager.Get_Android_Root_Path();
if (TWFunc::Path_Exists(PartitionManager.Get_Android_Root_Path() + "/system"))
base_path += "/system"; // For devices with system as a root file system (e.g. Pixel)
string install_path = base_path + "/priv-app";
string context = "u:object_r:system_file:s0";
@@ -2034,7 +2034,7 @@ int GUIAction::installapp(std::string arg __unused)
}
sync();
sync();
PartitionManager.UnMount_By_Path("/system", true);
PartitionManager.UnMount_By_Path(PartitionManager.Get_Android_Root_Path(), true);
op_status = 0;
} else {
LOGERR("Error making app directory '%s': %s\n", strerror(errno));
+5 -5
View File
@@ -147,8 +147,8 @@ int OpenRecoveryScript::run_script_file(void) {
// Wipe
if (strcmp(value, "cache") == 0 || strcmp(value, "/cache") == 0) {
PartitionManager.Wipe_By_Path("/cache");
} else if (strcmp(value, "system") == 0 || strcmp(value, "/system") == 0) {
PartitionManager.Wipe_By_Path("/system");
} else if (strcmp(value, PartitionManager.Get_Android_Root_Path().c_str()) == 0 || strcmp(value, PartitionManager.Get_Android_Root_Path().c_str()) == 0) {
PartitionManager.Wipe_By_Path(PartitionManager.Get_Android_Root_Path());
} else if (strcmp(value, "dalvik") == 0 || strcmp(value, "dalvick") == 0 || strcmp(value, "dalvikcache") == 0 || strcmp(value, "dalvickcache") == 0) {
PartitionManager.Wipe_Dalvik_Cache();
} else if (strcmp(value, "data") == 0 || strcmp(value, "/data") == 0 || strcmp(value, "factory") == 0 || strcmp(value, "factoryreset") == 0) {
@@ -667,14 +667,14 @@ void OpenRecoveryScript::Run_CLI_Command(const char* command) {
int OpenRecoveryScript::remountrw(void)
{
bool remount_system = PartitionManager.Is_Mounted_By_Path("/system");
bool remount_system = PartitionManager.Is_Mounted_By_Path(PartitionManager.Get_Android_Root_Path());
int op_status;
TWPartition* Part;
if (!PartitionManager.UnMount_By_Path("/system", true)) {
if (!PartitionManager.UnMount_By_Path(PartitionManager.Get_Android_Root_Path(), true)) {
op_status = 1; // fail
} else {
Part = PartitionManager.Find_Partition_By_Path("/system");
Part = PartitionManager.Find_Partition_By_Path(PartitionManager.Get_Android_Root_Path());
if (Part) {
DataManager::SetValue("tw_mount_system_ro", 0);
Part->Change_Mount_Read_Only(false);
+3 -3
View File
@@ -430,7 +430,7 @@ bool TWPartition::Process_Fstab_Line(const char *fstab_line, bool Display_Error,
} else if (Is_File_System(Fstab_File_System)) {
Find_Actual_Block_Device();
Setup_File_System(Display_Error);
if (Mount_Point == "/system") {
if (Mount_Point == PartitionManager.Get_Android_Root_Path()) {
Display_Name = "System";
Backup_Display_Name = Display_Name;
Storage_Name = Display_Name;
@@ -1504,7 +1504,7 @@ bool TWPartition::UnMount(bool Display_Error) {
int never_unmount_system;
DataManager::GetValue(TW_DONT_UNMOUNT_SYSTEM, never_unmount_system);
if (never_unmount_system == 1 && Mount_Point == "/system")
if (never_unmount_system == 1 && Mount_Point == PartitionManager.Get_Android_Root_Path())
return true; // Never unmount system if you're not supposed to unmount it
if (Is_Storage && MTP_Storage_ID > 0)
@@ -2624,7 +2624,7 @@ bool TWPartition::Restore_Tar(PartitionSettings *part_settings) {
ret = true;
#ifdef HAVE_CAPABILITIES
// Restore capabilities to the run-as binary
if (Mount_Point == "/system" && Mount(true) && TWFunc::Path_Exists("/system/bin/run-as")) {
if (Mount_Point == PartitionManager.Get_Android_Root_Path() && Mount(true) && TWFunc::Path_Exists("/system/bin/run-as")) {
struct vfs_cap_data cap_data;
uint64_t capabilities = (1 << CAP_SETUID) | (1 << CAP_SETGID);
+10 -3
View File
@@ -1104,7 +1104,7 @@ int TWPartitionManager::Run_Restore(const string& Restore_Name) {
}
}
TWFunc::GUI_Operation_Text(TW_UPDATE_SYSTEM_DETAILS_TEXT, gui_parse_text("{@updating_system_details}"));
UnMount_By_Path("/system", false);
UnMount_By_Path(Get_Android_Root_Path(), false);
Update_System_Details();
UnMount_Main_Partitions();
time(&rStop);
@@ -1490,7 +1490,7 @@ void TWPartitionManager::Update_System_Details(void) {
for (iter = Partitions.begin(); iter != Partitions.end(); iter++) {
(*iter)->Update_Size(true);
if ((*iter)->Can_Be_Mounted) {
if ((*iter)->Mount_Point == "/system") {
if ((*iter)->Mount_Point == Get_Android_Root_Path()) {
int backup_display_size = (int)((*iter)->Backup_Size / 1048576LLU);
DataManager::SetValue(TW_BACKUP_SYSTEM_SIZE, backup_display_size);
} else if ((*iter)->Mount_Point == "/data" || (*iter)->Mount_Point == "/datadata") {
@@ -1859,7 +1859,7 @@ void TWPartitionManager::UnMount_Main_Partitions(void) {
TWPartition* Boot_Partition = Find_Partition_By_Path("/boot");
UnMount_By_Path("/system", true);
UnMount_By_Path(Get_Android_Root_Path(), true);
if (!datamedia)
UnMount_By_Path("/data", true);
@@ -2726,6 +2726,13 @@ string TWPartitionManager::Get_Active_Slot_Display() {
return Active_Slot_Display;
}
string TWPartitionManager::Get_Android_Root_Path() {
std::string Android_Root = getenv("ANDROID_ROOT");
if (Android_Root == "")
Android_Root = "/system";
return Android_Root;
}
void TWPartitionManager::Remove_Uevent_Devices(const string& Mount_Point) {
std::vector<TWPartition*>::iterator iter;
+1
View File
@@ -332,6 +332,7 @@ public:
void Set_Active_Slot(const string& Slot); // Sets the active slot to A or B
string Get_Active_Slot_Suffix(); // Returns active slot _a or _b
string Get_Active_Slot_Display(); // Returns active slot A or B for display purposes
string Get_Android_Root_Path(); // Returns path of ANDROID_ROOT environment variable
struct pollfd uevent_pfd; // Used for uevent code
void Remove_Uevent_Devices(const string& sysfs_path); // Removes subpartitions from the Partitions vector for a matched uevent device
void Handle_Uevent(const Uevent_Block_Data& uevent_data); // Handle uevent data
+10 -10
View File
@@ -407,7 +407,7 @@ string TWFunc::Get_Root_Path(const string& Path) {
void TWFunc::install_htc_dumlock(void) {
int need_libs = 0;
if (!PartitionManager.Mount_By_Path("/system", true))
if (!PartitionManager.Mount_By_Path(PartitionManager.Get_Android_Root_Path(), true))
return;
if (!PartitionManager.Mount_By_Path("/data", true))
@@ -809,19 +809,19 @@ string TWFunc::Get_Current_Date() {
}
string TWFunc::System_Property_Get(string Prop_Name) {
bool mount_state = PartitionManager.Is_Mounted_By_Path("/system");
bool mount_state = PartitionManager.Is_Mounted_By_Path(PartitionManager.Get_Android_Root_Path());
std::vector<string> buildprop;
string propvalue;
if (!PartitionManager.Mount_By_Path("/system", true))
if (!PartitionManager.Mount_By_Path(PartitionManager.Get_Android_Root_Path(), true))
return propvalue;
string prop_file = "/system/build.prop";
if (!TWFunc::Path_Exists(prop_file))
prop_file = "/system/system/build.prop"; // for devices with system as a root file system (e.g. Pixel)
prop_file = PartitionManager.Get_Android_Root_Path() + "/system/build.prop"; // for devices with system as a root file system (e.g. Pixel)
if (TWFunc::read_file(prop_file, buildprop) != 0) {
LOGINFO("Unable to open /system/build.prop for getting '%s'.\n", Prop_Name.c_str());
LOGINFO("Unable to open 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);
PartitionManager.UnMount_By_Path(PartitionManager.Get_Android_Root_Path(), false);
return propvalue;
}
int line_count = buildprop.size();
@@ -834,12 +834,12 @@ string TWFunc::System_Property_Get(string Prop_Name) {
if (propname == Prop_Name) {
propvalue = buildprop.at(index).substr(end_pos + 1, buildprop.at(index).size());
if (!mount_state)
PartitionManager.UnMount_By_Path("/system", false);
PartitionManager.UnMount_By_Path(PartitionManager.Get_Android_Root_Path(), false);
return propvalue;
}
}
if (!mount_state)
PartitionManager.UnMount_By_Path("/system", false);
PartitionManager.UnMount_By_Path(PartitionManager.Get_Android_Root_Path(), false);
return propvalue;
}
@@ -1095,14 +1095,14 @@ std::string TWFunc::to_string(unsigned long value) {
}
void TWFunc::Disable_Stock_Recovery_Replace(void) {
if (PartitionManager.Mount_By_Path("/system", false)) {
if (PartitionManager.Mount_By_Path(PartitionManager.Get_Android_Root_Path(), false)) {
// Disable flashing of stock recovery
if (TWFunc::Path_Exists("/system/recovery-from-boot.p")) {
rename("/system/recovery-from-boot.p", "/system/recovery-from-boot.bak");
gui_msg("rename_stock=Renamed stock recovery file in /system to prevent the stock ROM from replacing TWRP.");
sync();
}
PartitionManager.UnMount_By_Path("/system", false);
PartitionManager.UnMount_By_Path(PartitionManager.Get_Android_Root_Path(), false);
}
}
+1 -1
View File
@@ -333,7 +333,7 @@ int main(int argc, char **argv) {
#ifndef TW_OEM_BUILD
// Check if system has never been changed
TWPartition* sys = PartitionManager.Find_Partition_By_Path("/system");
TWPartition* sys = PartitionManager.Find_Partition_By_Path(PartitionManager.Get_Android_Root_Path());
TWPartition* ven = PartitionManager.Find_Partition_By_Path("/vendor");
if (sys) {
+1 -1
View File
@@ -309,7 +309,7 @@ bool twrpAdbBuFifo::Restore_ADB_Backup(void) {
part_settings.Part->Set_Backup_FileName(Backup_FileName);
PartitionManager.Set_Restore_Files(path);
if (path.compare("/system") == 0) {
if (path.compare(PartitionManager.Get_Android_Root_Path()) == 0) {
if (part_settings.Part->Is_Read_Only()) {
if (!twadbbu::Write_TWERROR())
LOGERR("Unable to write to TWRP ADB Backup.\n");