copy log: add option to include logcat

Change-Id: I9689df4560d5209f385fbbc3e233859754b3ebbd
diff --git a/data.cpp b/data.cpp
index f7cd7a2..1fc7f35 100755
--- a/data.cpp
+++ b/data.cpp
@@ -940,6 +940,11 @@
 
 	mData.SetValue("tw_enable_adb_backup", "0");
 
+	if (TWFunc::Path_Exists("/system/bin/logcat"))
+		mConst.SetValue("tw_logcat_exists", "1");
+	else
+		mConst.SetValue("tw_logcat_exists", "0");
+
 	if (TWFunc::Path_Exists("/system/bin/magiskboot"))
 		mConst.SetValue("tw_has_repack_tools", "1");
 	else
diff --git a/gui/action.cpp b/gui/action.cpp
index c63337c..464ed27 100755
--- a/gui/action.cpp
+++ b/gui/action.cpp
@@ -676,8 +676,10 @@
 	{
 		string dst, curr_storage;
 		int copy_kernel_log = 0;
+		int copy_logcat = 1;
 
 		DataManager::GetValue("tw_include_kernel_log", copy_kernel_log);
+		DataManager::GetValue("tw_include_logcat", copy_logcat);
 		PartitionManager.Mount_Current_Storage(true);
 		curr_storage = DataManager::GetCurrentStoragePath();
 		dst = curr_storage + "/recovery.log";
@@ -685,6 +687,8 @@
 		tw_set_default_metadata(dst.c_str());
 		if (copy_kernel_log)
 			TWFunc::copy_kernel_log(curr_storage);
+		if (copy_logcat)
+			TWFunc::copy_logcat(curr_storage);
 		sync();
 		gui_msg(Msg("copy_log=Copied recovery log to {1}")(dst));
 	} else
diff --git a/gui/theme/common/landscape.xml b/gui/theme/common/landscape.xml
index 369c4d8..0367e55 100755
--- a/gui/theme/common/landscape.xml
+++ b/gui/theme/common/landscape.xml
@@ -2993,7 +2993,7 @@
 						<action function="set">tw_slider_text={@swipe_reboot=Swipe to Reboot}</action>
 						<action function="page">rebootcheck</action>
 					</actions>
-				</button>
+				</listitem>
 			</listbox>
 
 			<button style="main_button">
@@ -3616,7 +3616,14 @@
 			</text>
 
 			<checkbox>
+				<condition var1="tw_logcat_exists" var2="1"/>
 				<placement x="%indent%" y="%row4_y%"/>
+				<text>{@include_logcat=Include Logcat}</text>
+				<data variable="tw_include_logcat" value="1"/>
+			</checkbox>
+
+			<checkbox>
+				<placement x="%indent%" y="%row6_y%"/>
 				<text>{@include_kernel_log=Include Kernel Log}</text>
 				<data variable="tw_include_kernel_log" value="1"/>
 			</checkbox>
diff --git a/gui/theme/common/languages/en.xml b/gui/theme/common/languages/en.xml
index 2ff27b2..bf9760f 100755
--- a/gui/theme/common/languages/en.xml
+++ b/gui/theme/common/languages/en.xml
@@ -740,7 +740,9 @@
 		<string name="twrp_adbbu_option">--twrp option is required to enable twrp adb backup</string>
 		<string name="partition_not_found">path: {1} not found in partititon list</string>
 		<string name="copy_kernel_log">Copied kernel log to {1}</string>
+		<string name="copy_logcat">Copied logcat to {1}</string>
 		<string name="include_kernel_log">Include Kernel Log</string>
+		<string name="include_logcat">Include Logcat</string>
 		<string name="sha2_chk">Use SHA2 for hashing</string>
 		<string name="unable_set_boot_slot">Error changing bootloader boot slot to {1}</string>
 		<string name="unmount_sys_install">Unmount System before installing a ZIP</string>
@@ -767,7 +769,7 @@
 		<string name="change_twrp_folder_on_process">Changing TWRP folder</string>
 		<string name="change_twrp_folder_after_process">TWRP folder changed to</string>
 		<string name="tw_folder_exists">A folder with that name already exists!</string>
-		<string name="unmap_super_devices">Unmap Super Devices</strings>
+		<string name="unmap_super_devices">Unmap Super Devices</string>
 		<string name="unmap_super_devices_confirm">Unmap all Super Devices?</string>
 		<string name="unmapping_super_devices">Unmapping Super Devices...</string>
 		<string name="unmap_super_devices_complete">Unmapped all Super Devices</string>
diff --git a/gui/theme/common/portrait.xml b/gui/theme/common/portrait.xml
index 3d6bce7..607e211 100755
--- a/gui/theme/common/portrait.xml
+++ b/gui/theme/common/portrait.xml
@@ -3149,7 +3149,7 @@
 						<action function="set">tw_slider_text={@swipe_reboot=Swipe to Reboot}</action>
 						<action function="page">rebootcheck</action>
 					</actions>
-				</button>
+				</listitem>
 			</listbox>
 
 			<text style="text_m">
@@ -3737,7 +3737,14 @@
 			</text>
 
 			<checkbox>
+				<condition var1="tw_logcat_exists" var2="1"/>
 				<placement x="%indent%" y="%row4_y%"/>
+				<text>{@include_logcat=Include Logcat}</text>
+				<data variable="tw_include_logcat" value="1"/>
+			</checkbox>
+
+			<checkbox>
+				<placement x="%indent%" y="%row6_y%"/>
 				<text>{@include_kernel_log=Include Kernel Log}</text>
 				<data variable="tw_include_kernel_log" value="1"/>
 			</checkbox>
diff --git a/gui/theme/common/watch.xml b/gui/theme/common/watch.xml
index 060d50a..2cea636 100755
--- a/gui/theme/common/watch.xml
+++ b/gui/theme/common/watch.xml
@@ -266,6 +266,13 @@
 				<data variable="tw_include_kernel_log" value="1"/>
 			</checkbox>
 
+			<checkbox>
+				<condition var1="tw_logcat_exists" var2="1"/>
+				<placement x="%indent%" y="%row2_y%"/>
+				<text>{@include_logcat=Include Logcat}</text>
+				<data variable="tw_include_logcat" value="1"/>
+			</checkbox>
+
 			<slider>
 				<text>{@swipe_confirm=   Confirm}</text>
 				<actions>
diff --git a/twrp-functions.cpp b/twrp-functions.cpp
index af211f4..c56e194 100755
--- a/twrp-functions.cpp
+++ b/twrp-functions.cpp
@@ -1165,6 +1165,17 @@
 	tw_set_default_metadata(dmesgDst.c_str());
 }
 
+void TWFunc::copy_logcat(string curr_storage) {
+	std::string logcatDst = curr_storage + "/logcat.txt";
+	std::string logcatCmd = "logcat -d";
+
+	std::string result;
+	Exec_Cmd(logcatCmd, result, false);
+	write_to_file(logcatDst, result);
+	gui_msg(Msg("copy_logcat=Copied logcat to {1}")(logcatDst));
+	tw_set_default_metadata(logcatDst.c_str());
+}
+
 bool TWFunc::isNumber(string strtocheck) {
 	int num = 0;
 	std::istringstream iss(strtocheck);
diff --git a/twrp-functions.hpp b/twrp-functions.hpp
index 8979a66..dc51454 100755
--- a/twrp-functions.hpp
+++ b/twrp-functions.hpp
@@ -108,6 +108,7 @@
 	static void Disable_Stock_Recovery_Replace(); // Disable stock ROMs from replacing TWRP with stock recovery
 	static unsigned long long IOCTL_Get_Block_Size(const char* block_device);
 	static void copy_kernel_log(string curr_storage); // Copy Kernel Log to Current Storage (PSTORE/KMSG)
+	static void copy_logcat(string curr_storage); // Copy Logcat to Current Storage
 	static bool isNumber(string strtocheck); // return true if number, false if not a number
 	static int stream_adb_backup(string &Restore_Name); // Tell ADB Backup to Stream to TWRP from GUI selection
 	static std::string get_log_dir(); // return recovery log storage directory