Remove duplicate Update_System_Details() function calls

Only run Update_System_Details on boot after decryption is
complete, if device is unencrypted, or if decryption prompt
is cancelled.

This significantly decreases the delay in reaching the
decryption prompt on devices with large used storage
capacity

Use refreshsizes action to update system details when
Cancel button is pressed at decryption prompt

Change-Id: I9e436b1c57664a5269f42dc1cda4f6097f7e3062
diff --git a/gui/theme/common/landscape.xml b/gui/theme/common/landscape.xml
index a3437fb..cf14ace 100755
--- a/gui/theme/common/landscape.xml
+++ b/gui/theme/common/landscape.xml
@@ -4715,10 +4715,7 @@
 			<button style="main_button_half_width_low">
 				<placement x="%indent%" y="%row6_y%"/>
 				<text>{@cancel_btn=Cancel}</text>
-				<actions>
-					<action function="set">tw_page_done=1</action>
-					<action function="page">main</action>
-				</actions>
+				<action function="page">canceldecrypt</action>
 			</button>
 
 			<button style="main_button_half_width_low">
@@ -4795,10 +4792,7 @@
 			<button style="main_button_half_width">
 				<placement x="%col2_x_right%" y="%row15a_y%"/>
 				<text>{@cancel_btn=Cancel}</text>
-				<actions>
-					<action function="set">tw_page_done=1</action>
-					<action function="page">main</action>
-				</actions>
+				<action function="page">canceldecrypt</action>
 			</button>
 		</page>
 
@@ -4846,6 +4840,38 @@
 			</action>
 		</page>
 
+		<page name="canceldecrypt">
+			<template name="page"/>
+
+			<text style="text_l">
+				<placement x="%col1_x_header%" y="%row3_header_y%"/>
+				<text>{@cancel_btn=Cancel}</text>
+			</text>
+
+			<text style="text_m">
+				<placement x="%col1_x_header%" y="%row4_header_y%"/>
+				<text>{@refresh_sizes_btn=Refresh Sizes}</text>
+			</text>
+
+			<template name="console"/>
+
+			<template name="progress_bar"/>
+
+			<action>
+				<action function="refreshsizes"/>
+			</action>
+
+			<action>
+				<conditions>
+					<condition var1="tw_operation_state" var2="1"/>
+				</conditions>
+				<actions>
+					<action function="set">tw_page_done=1</action>
+					<action function="page">main</action>
+				</actions>
+			</action>
+		</page>
+
 		<page name="terminalcommand">
 			<template name="page"/>
 
diff --git a/gui/theme/common/portrait.xml b/gui/theme/common/portrait.xml
index b90902b..de985a6 100755
--- a/gui/theme/common/portrait.xml
+++ b/gui/theme/common/portrait.xml
@@ -4838,10 +4838,7 @@
 			<button style="main_button_half_height">
 				<placement x="%indent%" y="%row10_y%"/>
 				<text>{@cancel_btn=Cancel}</text>
-				<actions>
-					<action function="set">tw_page_done=1</action>
-					<action function="page">main</action>
-				</actions>
+				<action function="page">canceldecrypt</action>
 			</button>
 
 			<button style="main_button_half_height">
@@ -4919,10 +4916,7 @@
 			<button style="main_button_half_height">
 				<placement x="%indent%" y="%row21a_y%"/>
 				<text>{@cancel_btn=Cancel}</text>
-				<actions>
-					<action function="set">tw_page_done=1</action>
-					<action function="page">main</action>
-				</actions>
+				<action function="page">canceldecrypt</action>
 			</button>
 
 			<button style="main_button_half_height">
@@ -4976,6 +4970,38 @@
 			</action>
 		</page>
 
+		<page name="canceldecrypt">
+			<template name="page"/>
+
+			<text style="text_l">
+				<placement x="%col1_x_header%" y="%row3_header_y%"/>
+				<text>{@cancel_btn=Cancel}</text>
+			</text>
+
+			<text style="text_m">
+				<placement x="%col1_x_header%" y="%row4_header_y%"/>
+				<text>{@refresh_sizes_btn=Refresh Sizes}</text>
+			</text>
+
+			<template name="console"/>
+
+			<template name="progress_bar"/>
+
+			<action>
+				<action function="refreshsizes"/>
+			</action>
+
+			<action>
+				<conditions>
+					<condition var1="tw_operation_state" var2="1"/>
+				</conditions>
+				<actions>
+					<action function="set">tw_page_done=1</action>
+					<action function="page">main</action>
+				</actions>
+			</action>
+		</page>
+
 		<page name="terminalcommand">
 			<template name="page"/>
 
diff --git a/gui/theme/common/watch.xml b/gui/theme/common/watch.xml
index 50f3c2b..5520a35 100755
--- a/gui/theme/common/watch.xml
+++ b/gui/theme/common/watch.xml
@@ -5391,10 +5391,7 @@
 			<button style="main_button_half_height">
 				<placement x="%col1_x_right%" y="%row4_y%"/>
 				<text>{@cancel_btn=Cancel}</text>
-				<actions>
-					<action function="set">tw_page_done=1</action>
-					<action function="page">main</action>
-				</actions>
+				<action function="page">canceldecrypt</action>
 			</button>
 
 			<template name="keyboardtemplate"/>
@@ -5455,10 +5452,7 @@
 				<placement x="%back_button_x%" y="%navbar_btn_y%" placement="4"/>
 				<image resource="back"/>
 				<condition var1="tw_busy" var2="0"/>
-				<actions>
-					<action function="set">tw_page_done=1</action>
-					<action function="page">main</action>
-				</actions>
+				<action function="page">canceldecrypt</action>
 			</button>
 
 			<button>
@@ -5559,6 +5553,35 @@
 			</action>
 		</page>
 
+		<page name="canceldecrypt">
+			<template name="page"/>
+
+			<template name="statusbar"/>
+
+			<text style="text_m">
+				<placement x="%col1_x_left%" y="%row1_header_y%"/>
+				<text>{@cancel_btn=Cancel} &gt; {@refresh_sizes_btn=Refresh Sizes}</text>
+			</text>
+
+			<template name="console"/>
+
+			<template name="progress_bar"/>
+
+			<action>
+				<action function="refreshsizes"/>
+			</action>
+
+			<action>
+				<conditions>
+					<condition var1="tw_operation_state" var2="1"/>
+				</conditions>
+				<actions>
+					<action function="set">tw_page_done=1</action>
+					<action function="page">main</action>
+				</actions>
+			</action>
+		</page>
+
 		<page name="terminalcommand">
 			<terminal>
 				<condition var1="tw_hide_kb" var2="0"/>
diff --git a/partitionmanager.cpp b/partitionmanager.cpp
index 3d544e9..399aab7 100755
--- a/partitionmanager.cpp
+++ b/partitionmanager.cpp
@@ -355,7 +355,6 @@
 	Decrypt_Data();
 #endif
 
-	Update_System_Details();
 	if (Get_Super_Status())
 		Setup_Super_Partition();
 	UnMount_Main_Partitions();
@@ -3406,7 +3405,6 @@
 	superPartition->Setup_Image();
 	Add_Partition(superPartition);
 	PartitionManager.Output_Partition(superPartition);
-	Update_System_Details();
 }
 
 bool TWPartitionManager::Get_Super_Status() {
diff --git a/twrp.cpp b/twrp.cpp
index b8aca9a..13f374b 100644
--- a/twrp.cpp
+++ b/twrp.cpp
@@ -77,6 +77,7 @@
 	if (DataManager::GetIntValue(TW_IS_ENCRYPTED) != 0) {
 		if (SkipDecryption) {
 			LOGINFO("Skipping decryption\n");
+			PartitionManager.Update_System_Details();
 		} else if (DataManager::GetIntValue(TW_CRYPTO_PWTYPE) != 0) {
 			LOGINFO("Is encrypted, do decrypt page first\n");
 			if (DataManager::GetIntValue(TW_IS_FBE))
@@ -90,6 +91,7 @@
 			}
 		}
 	} else if (datamedia) {
+		PartitionManager.Update_System_Details();
 		TWFunc::check_selinux_support();
 		if (tw_get_default_metadata(DataManager::GetSettingsStoragePath().c_str()) != 0) {
 			LOGINFO("Failed to get default contexts and file mode for storage files.\n");
@@ -125,7 +127,6 @@
 		LOGERR("Failing out of recovery due to problem with fstab.\n");
 		return;
 	}
-	PartitionManager.Output_Partition_Logging();
 
 // We are doing this here to allow super partition to be set up prior to overriding properties
 #if defined(TW_INCLUDE_LIBRESETPROP) && defined(TW_OVERRIDE_SYSTEM_PROPS)
@@ -177,6 +178,7 @@
 #endif
 
 	Decrypt_Page(skip_decryption, datamedia);
+	PartitionManager.Output_Partition_Logging();
 
 	// Fixup the RTC clock on devices which require it
 	if (crash_counter == 0)