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

Commit 7abc5fe1 authored by bigbiff's avatar bigbiff Committed by Dees Troy
Browse files

Add cancel backup capability.

This will stop the iteration of the partition objects, kill the
current twrpTar thread and remove the backup directory.

Implement TWAtomicInt class to give us a wrapper that automatically
uses mutexes before the read and write to help ensure that the
reads and writes will be atomic based on documentation.

Change-Id: I645b22bc980a292e9c7202acb24ffd22ebe68c63
parent 3454ade9
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -454,7 +454,7 @@ include $(CLEAR_VARS)
LOCAL_MODULE := libaosprecovery
LOCAL_MODULE_TAGS := eng optional
LOCAL_C_INCLUDES := $(LOCAL_PATH)/libmincrypt/includes
LOCAL_SRC_FILES := adb_install.cpp asn1_decoder.cpp bootloader.cpp legacy_property_service.c verifier.cpp set_metadata.c
LOCAL_SRC_FILES := adb_install.cpp asn1_decoder.cpp bootloader.cpp legacy_property_service.c verifier.cpp set_metadata.c tw_atomic.cpp
LOCAL_SHARED_LIBRARIES += libc liblog libcutils libmtdutils libfusesideload libmincrypttwrp libselinux

ifneq ($(BOARD_RECOVERY_BLDRMSG_OFFSET),)
+43 −9
Original line number Diff line number Diff line
@@ -56,6 +56,7 @@ extern "C" {

#include "rapidxml.hpp"
#include "objects.hpp"
#include "../tw_atomic.hpp"

void curtainClose(void);

@@ -169,6 +170,7 @@ GUIAction::GUIAction(xml_node<>* node)
		mf["fixsu"] = &GUIAction::fixsu;
		mf["startmtp"] = &GUIAction::startmtp;
		mf["stopmtp"] = &GUIAction::stopmtp;
		mf["cancelbackup"] = &GUIAction::cancelbackup;

		// remember actions that run in the caller thread
		for (mapFunc::const_iterator it = mf.begin(); it != mf.end(); ++it)
@@ -314,6 +316,13 @@ void GUIAction::simulate_progress_bar(void)
	gui_print("Simulating actions...\n");
	for (int i = 0; i < 5; i++)
	{
		if (PartitionManager.stop_backup.get_value()) {
			DataManager::SetValue("tw_cancel_backup", 1);
			gui_print("Backup Canceled.\n");
			DataManager::SetValue("ui_progress", 0);
			PartitionManager.stop_backup.set_value(0);
			return;
		}
		usleep(500000);
		DataManager::SetValue("ui_progress", i * 20);
	}
@@ -1087,13 +1096,13 @@ int GUIAction::refreshsizes(std::string arg)

int GUIAction::nandroid(std::string arg)
{
	operation_start("Nandroid");
	int ret = 0;

	if (simulate) {
		DataManager::SetValue("tw_partition", "Simulation");
		simulate_progress_bar();
	} else {
		operation_start("Nandroid");
		int ret = 0;

		if (arg == "backup") {
			string Backup_Name;
			DataManager::GetValue(TW_BACKUP_NAME, Backup_Name);
@@ -1103,7 +1112,6 @@ int GUIAction::nandroid(std::string arg)
			else {
				operation_end(1);
				return -1;

			}
			DataManager::SetValue(TW_BACKUP_NAME, "(Auto Generate)");
		} else if (arg == "restore") {
@@ -1114,13 +1122,39 @@ int GUIAction::nandroid(std::string arg)
			operation_end(1);
			return -1;
		}
			}
		DataManager::SetValue("tw_encrypt_backup", 0);
		if (!PartitionManager.stop_backup.get_value()) {
			if (ret == false)
				ret = 1; // 1 for failure
			else
				ret = 0; // 0 for success
			DataManager::SetValue("tw_cancel_backup", 0);
			operation_end(ret);
		}
		else {
			DataManager::SetValue("tw_cancel_backup", 1);
			gui_print("Backup Canceled.\n");
			ret = 0;
		}
		return ret;
	}
	return 0;
}

int GUIAction::cancelbackup(std::string arg) {
	if (simulate) {
		simulate_progress_bar();
		PartitionManager.stop_backup.set_value(1);
		operation_end(0);
	}
	else {
		operation_start("Cancel Backup");
		int op_status = PartitionManager.Cancel_Backup();
		if (op_status != 0)
			op_status = 1; // failure
		operation_end(op_status);
	}

	return 0;
}

+1 −0
Original line number Diff line number Diff line
@@ -50,6 +50,7 @@
		<variable name="col1_x" value="10" />
		<variable name="col2_x" value="240" />
		<variable name="col_center_x" value="128" />
		<variable name="col_center_medium_x" value="183" />
		<variable name="center_x" value="240" />
		<variable name="row1_y" value="140" />
		<variable name="row2_y" value="290" />
+24 −1
Original line number Diff line number Diff line
@@ -670,7 +670,7 @@
			<object type="button">
				<highlight color="%highlight_color%" />
				<condition var1="tw_has_cancel" var2="1" />
				<placement x="%col4_x%" y="%slider_y%" />
                                <placement x="%col_center_x%" y="%cancel_button_y%" />
				<font resource="font" color="%button_text_color%" />
				<text>Cancel</text>
				<image resource="main_button" />
@@ -2157,6 +2157,17 @@

			<object type="template" name="action_page_console" />

			<object type="button">
				<highlight color="%highlight_color%" />
				<placement x="%col_center_medium_x%" y="%row3_y%" />
				<font resource="font" color="%button_text_color%" />
				<text>Cancel</text>
				<image resource="medium_button" />
				<actions>
					<action function="cancelbackup"></action>
				</actions>
			</object>

			<object type="template" name="progress_bar" />

			<object type="action">
@@ -2165,6 +2176,7 @@

			<object type="action">
				<condition var1="tw_operation_state" var2="1" />
				<condition var1="tw_cancel_backup" var2="0" />
				<actions>
					<action function="set">tw_back=backup</action>
					<action function="set">tw_complete_text1=Backup Complete</action>
@@ -2173,6 +2185,17 @@
				</actions>
			</object>

			<object type="action">
				<condition var1="tw_operation_state" var2="1" />
				<condition var1="tw_cancel_backup" var2="1" />
				<actions>
					<action function="set">tw_back=backup</action>
					<action function="set">tw_complete_text1=Backup Cancelled</action>
					<action function="set">tw_show_reboot=1</action>
					<action function="page">action_complete</action>
				</actions>
			</object>

			<object type="template" name="footer" />
		</page>

+23 −0
Original line number Diff line number Diff line
@@ -1867,6 +1867,17 @@

			<object type="template" name="action_page_console" />

			<object type="button">
				<highlight color="%highlight_color%" />
				<placement x="%col_center_medium_x%" y="%row4_y%" />
				<font resource="font" color="%button_text_color%" />
				<text>Cancel</text>
				<image resource="medium_button" />
				<actions>
					<action function="cancelbackup"></action>
				</actions>
			</object>

			<object type="template" name="progress_bar" />

			<object type="action">
@@ -1875,6 +1886,7 @@

			<object type="action">
				<condition var1="tw_operation_state" var2="1" />
				<condition var1="tw_cancel_backup" var2="0" />
				<actions>
					<action function="set">tw_back=backup</action>
					<action function="set">tw_complete_text1=Backup Complete</action>
@@ -1882,6 +1894,17 @@
					<action function="page">action_complete</action>
				</actions>
			</object>

			<object type="action">
				<condition var1="tw_operation_state" var2="1" />
				<condition var1="tw_cancel_backup" var2="1" />
				<actions>
					<action function="set">tw_back=backup</action>
					<action function="set">tw_complete_text1=Backup Cancelled</action>
					<action function="set">tw_show_reboot=1</action>
					<action function="page">action_complete</action>
				</actions>
			</object>
		</page>

		<page name="restore">
Loading