Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit eb32b1ff authored by Ethan Yonker's avatar Ethan Yonker
Browse files

Mount system as read-only by default

Mounting system as rw can prevent future OTA updates. The purpose
of this patch set is to prevent TWRP from mounting sytem as rw on
the first boot. Device maintainers should update their twrp.fstab
files on these devices to include an additional line:
/system_image emmc /dev/block/../system

This line will allow TWRP to create a raw system image backup to
ensure that the user can return to an original state for future
OTA updates.

Change-Id: I8929d85bc3a5b96cc564bc7f734b58d5612ec833
parent f746dbb0
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -852,6 +852,8 @@ void DataManager::SetDefaultValues()
	mConstValues.insert(make_pair("tw_has_mtp", "0"));
	mConstValues.insert(make_pair("tw_mtp_enabled", "0"));
#endif
	mValues.insert(make_pair("tw_mount_system_ro", make_pair("1", 1)));
	mValues.insert(make_pair("tw_never_show_system_ro_page", make_pair("0", 1)));

	pthread_mutex_unlock(&m_valuesLock);
}
+54 −0
Original line number Diff line number Diff line
@@ -196,6 +196,8 @@ GUIAction::GUIAction(xml_node<>* node)
		ADD_ACTION(startmtp);
		ADD_ACTION(stopmtp);
		ADD_ACTION(cancelbackup);
		ADD_ACTION(checkpartitionlifetimewrites);
		ADD_ACTION(mountsystemtoggle);

		// remember actions that run in the caller thread
		for (mapFunc::const_iterator it = mf.begin(); it != mf.end(); ++it)
@@ -1737,3 +1739,55 @@ int GUIAction::getKeyByName(std::string key)

	return atol(key.c_str());
}

int GUIAction::checkpartitionlifetimewrites(std::string arg)
{
	int op_status = 0;
	TWPartition* sys = PartitionManager.Find_Partition_By_Path(arg);

	operation_start("Check Partition Lifetime Writes");
	if (sys) {
		if (sys->Check_Lifetime_Writes() != 0)
			DataManager::SetValue("tw_lifetime_writes", 1);
		else
			DataManager::SetValue("tw_lifetime_writes", 0);
		op_status = 0; // success
	} else {
		DataManager::SetValue("tw_lifetime_writes", 1);
		op_status = 1; // fail
	}

	operation_end(op_status);
	return 0;
}

int GUIAction::mountsystemtoggle(std::string arg)
{
	int op_status = 0;
	bool remount_system = PartitionManager.Is_Mounted_By_Path("/system");

	operation_start("Toggle System Mount");
	if (!PartitionManager.UnMount_By_Path("/system", true)) {
		op_status = 1; // fail
	} else {
		TWPartition* Part = PartitionManager.Find_Partition_By_Path("/system");
		if (Part) {
			if (DataManager::GetIntValue("tw_mount_system_ro")) {
				DataManager::SetValue("tw_mount_system_ro", 0);
				Part->Change_Mount_Read_Only(false);
			} else {
				DataManager::SetValue("tw_mount_system_ro", 1);
				Part->Change_Mount_Read_Only(true);
			}
			if (remount_system) {
				Part->Mount(true);
			}
			op_status = 0; // success
		} else {
			op_status = 1; // fail
		}
	}

	operation_end(op_status);
	return 0;
}
+1 −0
Original line number Diff line number Diff line
@@ -86,6 +86,7 @@
		<variable name="tz_selected_y" value="240" />
		<variable name="tz_set_y" value="1500" />
		<variable name="tz_current_y" value="1425" />
		<variable name="system_ro_y" value="1770" />
		<variable name="col_progressbar_x" value="351" />
		<variable name="row_progressbar_y" value="1650" />
		<variable name="col1_medium_x" value="10" />
+2 −1
Original line number Diff line number Diff line
@@ -174,6 +174,7 @@
		<variable name="row_offset_medium_y" value="206" />
		<variable name="tz_set_y" value="271" />
		<variable name="tz_current_y" value="249" />
		<variable name="system_ro_y" value="216" />
		<variable name="button_fill_color" value="#303030" />
		<variable name="button_fill_full_width" value="308" />
		<variable name="button_fill_main_width" value="150" />
@@ -189,7 +190,7 @@
		<variable name="backup_button_row1" value="214" />
		<variable name="backup_button_row2" value="242" />
		<variable name="mount_list_height" value="190" />
		<variable name="mount_storage_row" value="200" />
		<variable name="mount_storage_row" value="193" />
		<variable name="storage_list_height" value="134" />
		<variable name="wipe_list_height" value="216" />
		<variable name="wipe_button_y" value="170" />
+1 −0
Original line number Diff line number Diff line
@@ -82,6 +82,7 @@
		<variable name="tz_selected_y" value="110" />
		<variable name="tz_set_y" value="580" />
		<variable name="tz_current_y" value="730" />
		<variable name="system_ro_y" value="550" />
		<variable name="col_progressbar_x" value="114" />
		<variable name="row_progressbar_y" value="720" />
		<variable name="col1_medium_x" value="10" />
Loading