Add TWRP app install to landscape and watch themes

Change-Id: Id48245218dc3ee3c6506521ce0134e6a579b6f4a
diff --git a/gui/action.cpp b/gui/action.cpp
index 3899f50..a395158 100644
--- a/gui/action.cpp
+++ b/gui/action.cpp
@@ -1892,7 +1892,7 @@
 				LOGINFO("Unable to read sdk version from build prop\n");
 			else
 				LOGINFO("SDK version too low for TWRP app (%i < 14)\n", sdkver);
-			DataManager::SetValue("tw_app_install_status", 1); // 0 = no status, 1 = not installed, 2 = already installed
+			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)) {
@@ -1905,7 +1905,7 @@
 			install_path += "/twrpapp";
 			if (TWFunc::Path_Exists(install_path)) {
 				LOGINFO("App found at '%s'\n", install_path.c_str());
-				DataManager::SetValue("tw_app_install_status", 2); // 0 = no status, 1 = not installed, 2 = already installed
+				DataManager::SetValue("tw_app_install_status", 2); // 0 = no status, 1 = not installed, 2 = already installed or do not install
 				goto exit;
 			}
 		}
@@ -1920,11 +1920,14 @@
 						continue;
 					closedir(d);
 					LOGINFO("App found at '%s/%s'\n", parent_path, p->d_name);
-					DataManager::SetValue("tw_app_install_status", 2); // 0 = no status, 1 = not installed, 2 = already installed
+					DataManager::SetValue("tw_app_install_status", 2); // 0 = no status, 1 = not installed, 2 = already installed or do not install
 					goto exit;
 				}
 				closedir(d);
 			}
+		} else {
+			LOGINFO("Data partition cannot be mounted during app check\n");
+			DataManager::SetValue("tw_app_install_status", 2); // 0 = no status, 1 = not installed, 2 = already installed or do not install
 		}
 	} else
 		simulate_progress_bar();
diff --git a/gui/theme/common/landscape.xml b/gui/theme/common/landscape.xml
index 8ca508f..6d54483 100644
--- a/gui/theme/common/landscape.xml
+++ b/gui/theme/common/landscape.xml
@@ -726,7 +726,7 @@
 		<page name="reboot_system_routine">
 			<action>
 				<action function="set">tw_action=reboot</action>
-				<action function="set">tw_action_param=system</action>
+				<action function="set">tw_reboot_param=system</action>
 				<action function="set">tw_has_action2=0</action>
 				<action function="set">tw_text1={@no_os1=No OS Installed! Are you}</action>
 				<action function="set">tw_text2={@no_osrb=sure you wish to reboot?}</action>
@@ -972,7 +972,7 @@
 		<page name="rebootcheck">
 			<action>
 				<condition var1="tw_backup_system_size" op="&gt;=" var2="%tw_min_system%"/>
-				<action function="reboot">%tw_action_param%</action>
+				<action function="page">appcheck</action>
 			</action>
 
 			<action>
@@ -981,6 +981,28 @@
 			</action>
 		</page>
 
+		<page name="appcheck">
+			<action>
+				<condition var1="tw_app_prompt" var2="1"/>
+				<action function="checkforapp"></action>
+			</action>
+
+			<action>
+				<condition var1="tw_app_prompt" op="!=" var2="1"/>
+				<action function="reboot">%tw_reboot_param%</action>
+			</action>
+
+			<action>
+				<condition var1="tw_app_install_status" var2="1"/>
+				<action function="page">rebootapp</action>
+			</action>
+
+			<action>
+				<condition var1="tw_app_install_status" var2="2"/>
+				<action function="reboot">%tw_reboot_param%</action>
+			</action>
+		</page>
+
 		<page name="wipe">
 			<template name="page"/>
 
@@ -2595,7 +2617,7 @@
 				<actions>
 					<action function="set">tw_back=reboot</action>
 					<action function="set">tw_action=reboot</action>
-					<action function="set">tw_action_param=poweroff</action>
+					<action function="set">tw_reboot_param=poweroff</action>
 					<action function="set">tw_has_action2=0</action>
 					<action function="set">tw_text1={@no_os1=No OS Installed! Are you}</action>
 					<action function="set">tw_text2={@no_ospo=sure you wish to power off?}</action>
@@ -2613,7 +2635,7 @@
 				<actions>
 					<action function="set">tw_back=reboot</action>
 					<action function="set">tw_action=reboot</action>
-					<action function="set">tw_action_param=recovery</action>
+					<action function="set">tw_reboot_param=recovery</action>
 					<action function="set">tw_has_action2=0</action>
 					<action function="set">tw_text1={@no_os1=No OS Installed! Are you}</action>
 					<action function="set">tw_text2={@no_osrb=sure you wish to reboot?}</action>
@@ -2631,7 +2653,7 @@
 				<actions>
 					<action function="set">tw_back=reboot</action>
 					<action function="set">tw_action=reboot</action>
-					<action function="set">tw_action_param=bootloader</action>
+					<action function="set">tw_reboot_param=bootloader</action>
 					<action function="set">tw_has_action2=0</action>
 					<action function="set">tw_text1={@no_os1=No OS Installed! Are you}</action>
 					<action function="set">tw_text2={@no_osrb=sure you wish to reboot?}</action>
@@ -2649,7 +2671,7 @@
 				<actions>
 					<action function="set">tw_back=reboot</action>
 					<action function="set">tw_action=reboot</action>
-					<action function="set">tw_action_param=download</action>
+					<action function="set">tw_reboot_param=download</action>
 					<action function="set">tw_has_action2=0</action>
 					<action function="set">tw_text1={@no_os1=No OS Installed! Are you}</action>
 					<action function="set">tw_text2={@no_osrb=sure you wish to reboot?}</action>
@@ -2671,6 +2693,80 @@
 			</action>
 		</page>
 
+		<page name="rebootapp">
+			<template name="page"/>
+
+			<text style="text_l">
+				<placement x="%col1_x_header%" y="%row3_header_y%"/>
+				<text>{@reboot_hdr=Reboot}</text>
+			</text>
+
+			<text style="text_m">
+				<placement x="%col1_x_header%" y="%row4_header_y%"/>
+				<text>{@reboot_install_app_hdr=Install TWRP App?}</text>
+			</text>
+
+			<text style="text_m_accent">
+				<placement x="%center_x%" y="%row2_y%" placement="5"/>
+				<text>{@reboot_install_app1=Would you like to install the Official TWRP App?}</text>
+			</text>
+
+			<text style="text_m_accent">
+				<placement x="%center_x%" y="%row3_y%" placement="5"/>
+				<text>{@reboot_install_app2=The app can check for new TWRP versions.}</text>
+			</text>
+
+			<checkbox>
+				<placement x="%indent%" y="%row5_y%"/>
+				<text>{@reboot_install_app_prompt_install=Prompt to install TWRP app if not installed}</text>
+				<data variable="tw_app_prompt"/>
+			</checkbox>
+
+			<checkbox>
+				<condition var1="tw_mount_system_ro" var2="0"/>
+				<placement x="%indent%" y="%row7_y%"/>
+				<text>{@reboot_install_app_system=Install as a System App}</text>
+				<data variable="tw_app_install_system"/>
+			</checkbox>
+
+			<button style="main_button_half_width">
+				<placement x="%col2_x_left%" y="%row15a_y%"/>
+				<text>{@su_cancel=Do not Install}</text>
+				<action function="reboot">%tw_reboot_param%</action>
+			</button>
+
+			<slider>
+				<text>{@swipe_to_install_app=Swipe to Install TWRP App}</text>
+				<actions>
+					<action function="set">tw_back=reboot</action>
+					<action function="set">tw_action=installapp</action>
+					<action function="set">tw_action_text1={@reboot_installing_app=Installing App...}</action>
+					<action function="set">tw_action_text2=</action>
+					<action function="set">tw_has_action2=1</action>
+					<action function="set">tw_action2=reboot</action>
+					<action function="set">tw_action2_param=%tw_reboot_param%</action>
+					<action function="set">tw_complete_text1={@rebooting=Rebooting...}</action>
+					<action function="page">action_page</action>
+				</actions>
+			</slider>
+
+			<action>
+				<touch key="home"/>
+				<actions>
+					<action function="set">tw_app_install_status=0</action>
+					<action function="page">main</action>
+				</actions>
+			</action>
+
+			<action>
+				<touch key="back"/>
+				<actions>
+					<action function="set">tw_app_install_status=0</action>
+					<action function="page">reboot</action>
+				</actions>
+			</action>
+		</page>
+
 		<page name="system_readonly">
 			<template name="page"/>
 
@@ -2775,6 +2871,9 @@
 				<listitem name="{@use24clock_chk=Use 24-hour clock}">
 					<data variable="tw_military_time"/>
 				</listitem>
+				<listitem name="{@reboot_install_app_prompt_install=Prompt to install TWRP app on every reboot}">
+					<data variable="tw_app_prompt"/>
+				</listitem>
 				<listitem name="{@simact_chk=Simulate actions for theme testing}">
 					<data variable="tw_simulate_actions"/>
 				</listitem>
diff --git a/gui/theme/common/watch.xml b/gui/theme/common/watch.xml
index 6a7e6eb..ebfe497 100644
--- a/gui/theme/common/watch.xml
+++ b/gui/theme/common/watch.xml
@@ -944,7 +944,7 @@
 			<action>
 				<action function="set">tw_back=main2</action>
 				<action function="set">tw_action=reboot</action>
-				<action function="set">tw_action_param=system</action>
+				<action function="set">tw_reboot_param=system</action>
 				<action function="set">tw_has_action2=0</action>
 				<action function="set">tw_text1={@no_os1=No OS Installed! Are you}</action>
 				<action function="set">tw_text2={@no_osrb=sure you wish to reboot?}</action>
@@ -1192,7 +1192,7 @@
 		<page name="rebootcheck">
 			<action>
 				<condition var1="tw_backup_system_size" op="&gt;=" var2="%tw_min_system%"/>
-				<action function="reboot">%tw_action_param%</action>
+				<action function="page">appcheck</action>
 			</action>
 
 			<action>
@@ -1201,6 +1201,28 @@
 			</action>
 		</page>
 
+		<page name="appcheck">
+			<action>
+				<condition var1="tw_app_prompt" var2="1"/>
+				<action function="checkforapp"></action>
+			</action>
+
+			<action>
+				<condition var1="tw_app_prompt" op="!=" var2="1"/>
+				<action function="reboot">%tw_reboot_param%</action>
+			</action>
+
+			<action>
+				<condition var1="tw_app_install_status" var2="1"/>
+				<action function="page">rebootapp</action>
+			</action>
+
+			<action>
+				<condition var1="tw_app_install_status" var2="2"/>
+				<action function="reboot">%tw_reboot_param%</action>
+			</action>
+		</page>
+
 		<page name="wipe_type1">
 			<template name="page"/>
 
@@ -3250,7 +3272,7 @@
 				<actions>
 					<action function="set">tw_back=reboot</action>
 					<action function="set">tw_action=reboot</action>
-					<action function="set">tw_action_param=poweroff</action>
+					<action function="set">tw_reboot_param=poweroff</action>
 					<action function="set">tw_has_action2=0</action>
 					<action function="set">tw_text1={@no_os1=No OS Installed! Are you}</action>
 					<action function="set">tw_text2={@no_ospo=sure you wish to power off?}</action>
@@ -3268,7 +3290,7 @@
 				<actions>
 					<action function="set">tw_back=reboot</action>
 					<action function="set">tw_action=reboot</action>
-					<action function="set">tw_action_param=recovery</action>
+					<action function="set">tw_reboot_param=recovery</action>
 					<action function="set">tw_has_action2=0</action>
 					<action function="set">tw_text1={@no_os1=No OS Installed! Are you}</action>
 					<action function="set">tw_text2={@no_osrb=sure you wish to reboot?}</action>
@@ -3286,7 +3308,7 @@
 				<actions>
 					<action function="set">tw_back=reboot</action>
 					<action function="set">tw_action=reboot</action>
-					<action function="set">tw_action_param=bootloader</action>
+					<action function="set">tw_reboot_param=bootloader</action>
 					<action function="set">tw_has_action2=0</action>
 					<action function="set">tw_text1={@no_os1=No OS Installed! Are you}</action>
 					<action function="set">tw_text2={@no_osrb=sure you wish to reboot?}</action>
@@ -3304,7 +3326,7 @@
 				<actions>
 					<action function="set">tw_back=reboot</action>
 					<action function="set">tw_action=reboot</action>
-					<action function="set">tw_action_param=download</action>
+					<action function="set">tw_reboot_param=download</action>
 					<action function="set">tw_has_action2=0</action>
 					<action function="set">tw_text1={@no_os1=No OS Installed! Are you}</action>
 					<action function="set">tw_text2={@no_osrb=sure you wish to reboot?}</action>
@@ -3326,6 +3348,77 @@
 			</action>
 		</page>
 
+		<page name="rebootapp">
+			<template name="page"/>
+
+			<template name="statusbar"/>
+
+			<text style="text_m">
+				<placement x="%col1_x_left%" y="%row1_header_y%"/>
+				<text>{@reboot_hdr=Reboot} &gt; {@reboot_install_app_hdr=Install TWRP App?}</text>
+			</text>
+
+			<text style="text_m_accent">
+				<placement x="%center_x%" y="%row1_y%" placement="5"/>
+				<text>{@reboot_install_app1=Would you like to install the Official TWRP App?}</text>
+			</text>
+
+			<text style="text_m">
+				<placement x="%center_x%" y="%row2_y%" placement="5"/>
+				<text>{@reboot_install_app2=The app can check for new TWRP versions.}</text>
+			</text>
+
+			<checkbox>
+				<placement x="%indent%" y="%row3_y%"/>
+				<text>{@reboot_install_app_prompt_install=Prompt to install TWRP app if not installed}</text>
+				<data variable="tw_app_prompt"/>
+			</checkbox>
+
+			<checkbox>
+				<condition var1="tw_mount_system_ro" var2="0"/>
+				<placement x="%indent%" y="%row5_y%"/>
+				<text>{@reboot_install_app_system=Install as a System App}</text>
+				<data variable="tw_app_install_system"/>
+			</checkbox>
+
+			<button style="main_button_half_height">
+				<placement x="%indent%" y="%row7_y%"/>
+				<text>{@su_cancel=Do not Install}</text>
+				<action function="reboot">%tw_reboot_param%</action>
+			</button>
+
+			<slider>
+				<text>{@swipe_su_install=   Install}</text>
+				<actions>
+					<action function="set">tw_back=reboot</action>
+					<action function="set">tw_action=installapp</action>
+					<action function="set">tw_action_text1={@reboot_installing_app=Installing App...}</action>
+					<action function="set">tw_action_text2=</action>
+					<action function="set">tw_has_action2=1</action>
+					<action function="set">tw_action2=reboot</action>
+					<action function="set">tw_action2_param=%tw_reboot_param%</action>
+					<action function="set">tw_complete_text1={@rebooting=Rebooting...}</action>
+					<action function="page">action_page</action>
+				</actions>
+			</slider>
+
+			<action>
+				<touch key="home"/>
+				<actions>
+					<action function="set">tw_app_install_status=0</action>
+					<action function="page">main</action>
+				</actions>
+			</action>
+
+			<action>
+				<touch key="back"/>
+				<actions>
+					<action function="set">tw_app_install_status=0</action>
+					<action function="page">reboot</action>
+				</actions>
+			</action>
+		</page>
+
 		<page name="system_readonly">
 			<template name="page"/>
 
@@ -3496,6 +3589,9 @@
 				<listitem name="{@use24clock_chk=Use 24-hour clock}">
 					<data variable="tw_military_time"/>
 				</listitem>
+				<listitem name="{@reboot_install_app_prompt_install=Prompt to install TWRP app on every reboot}">
+					<data variable="tw_app_prompt"/>
+				</listitem>
 				<listitem name="{@simact_chk=Simulate actions for theme testing}">
 					<data variable="tw_simulate_actions"/>
 				</listitem>