diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/notification/Notifications.kt b/app/src/main/java/eu/kanade/tachiyomi/data/notification/Notifications.kt
index b55b53fed..97a4b2ef3 100644
--- a/app/src/main/java/eu/kanade/tachiyomi/data/notification/Notifications.kt
+++ b/app/src/main/java/eu/kanade/tachiyomi/data/notification/Notifications.kt
@@ -62,6 +62,12 @@ object Notifications {
const val ID_BACKUP_COMPLETE = -502
const val ID_RESTORE_COMPLETE = -504
+ /**
+ * Notification channel used for crash log file sharing.
+ */
+ const val CHANNEL_CRASH_LOGS = "crash_logs_channel"
+ const val ID_CRASH_LOGS = -601
+
private val deprecatedChannels = listOf(
"downloader_channel",
"backup_restore_complete_channel"
@@ -143,7 +149,12 @@ object Notifications {
group = GROUP_BACKUP_RESTORE
setShowBadge(false)
setSound(null, null)
- }
+ },
+ NotificationChannel(
+ CHANNEL_CRASH_LOGS,
+ context.getString(R.string.channel_crash_logs),
+ NotificationManager.IMPORTANCE_HIGH
+ )
).forEach(context.notificationManager::createNotificationChannel)
// Delete old notification channels
diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsAdvancedController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsAdvancedController.kt
index 00d7ad744..69cb08033 100644
--- a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsAdvancedController.kt
+++ b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsAdvancedController.kt
@@ -17,6 +17,7 @@ import eu.kanade.tachiyomi.data.library.LibraryUpdateService
import eu.kanade.tachiyomi.data.library.LibraryUpdateService.Target
import eu.kanade.tachiyomi.network.NetworkHelper
import eu.kanade.tachiyomi.ui.base.controller.DialogController
+import eu.kanade.tachiyomi.util.CrashLogUtil
import eu.kanade.tachiyomi.util.preference.defaultValue
import eu.kanade.tachiyomi.util.preference.onClick
import eu.kanade.tachiyomi.util.preference.preference
@@ -49,6 +50,16 @@ class SettingsAdvancedController : SettingsController() {
defaultValue = true
}
+ preference {
+ key = "dump_crash_logs"
+ titleRes = R.string.pref_dump_crash_logs
+ summaryRes = R.string.pref_dump_crash_logs_summary
+
+ onClick {
+ CrashLogUtil(context).dumpLogs()
+ }
+ }
+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
preference {
key = "pref_disable_battery_optimization"
diff --git a/app/src/main/java/eu/kanade/tachiyomi/util/CrashLogUtil.kt b/app/src/main/java/eu/kanade/tachiyomi/util/CrashLogUtil.kt
new file mode 100644
index 000000000..751bd8cd0
--- /dev/null
+++ b/app/src/main/java/eu/kanade/tachiyomi/util/CrashLogUtil.kt
@@ -0,0 +1,54 @@
+package eu.kanade.tachiyomi.util
+
+import android.content.Context
+import android.net.Uri
+import eu.kanade.tachiyomi.R
+import eu.kanade.tachiyomi.data.notification.NotificationReceiver
+import eu.kanade.tachiyomi.data.notification.Notifications
+import eu.kanade.tachiyomi.util.storage.getUriCompat
+import eu.kanade.tachiyomi.util.system.notificationBuilder
+import eu.kanade.tachiyomi.util.system.notificationManager
+import eu.kanade.tachiyomi.util.system.toast
+import java.io.File
+import java.io.IOException
+
+class CrashLogUtil(private val context: Context) {
+
+ private val notificationBuilder = context.notificationBuilder(Notifications.CHANNEL_CRASH_LOGS) {
+ setSmallIcon(R.drawable.ic_tachi)
+ }
+
+ fun dumpLogs() {
+ try {
+ val file = File(context.externalCacheDir, "tachiyomi_crash_logs.txt")
+ if (file.exists()) {
+ file.delete()
+ }
+ file.createNewFile()
+ Runtime.getRuntime().exec("logcat *:E -d -f ${file.absolutePath}")
+
+ showNotification(file.getUriCompat(context))
+ } catch (e: IOException) {
+ context.toast("Failed to get logs")
+ }
+ }
+
+ private fun showNotification(uri: Uri) {
+ context.notificationManager.cancel(Notifications.ID_CRASH_LOGS)
+
+ with(notificationBuilder) {
+ setContentTitle(context.getString(R.string.crash_log_saved))
+
+ // Clear old actions if they exist
+ clearActions()
+
+ addAction(
+ R.drawable.ic_folder_24dp,
+ context.getString(R.string.action_open_log),
+ NotificationReceiver.openErrorLogPendingActivity(context, uri)
+ )
+
+ context.notificationManager.notify(Notifications.ID_CRASH_LOGS, build())
+ }
+ }
+}
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index 85bf2a221..5048277ee 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -271,6 +271,11 @@
Volume keys
Invert volume keys
Tapping
+ Invert tapping
+ None
+ Horizontal
+ Vertical
+ Both
Long tap dialog
Background color
White
@@ -410,6 +415,9 @@
Refresh library manga covers
Refresh tracking
Updates status, score and last chapter read from the tracking services
+ Dump crash logs
+ Saves error logs to a file for sharing with the developers
+ Crash logs saved
Disable battery optimization
Helps with background library updates and backups
Battery optimization is already disabled
@@ -729,11 +737,7 @@
Backup and restore
Chapter updates
Extension updates
- Invert tapping
- None
- Horizontal
- Vertical
- Both
+ Crash logs
Previous page