Add method for users to save error logs to a file

(cherry picked from commit db2dd4b6c647dc01650b98472664a4e043f8f572)

# Conflicts:
#	app/src/main/java/eu/kanade/tachiyomi/data/notification/Notifications.kt
#	app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsAdvancedController.kt
This commit is contained in:
arkon 2021-01-21 18:21:03 -05:00 committed by Jobobby04
parent 48b713aad5
commit 4d6bd382e8
4 changed files with 87 additions and 7 deletions

View File

@ -62,13 +62,19 @@ 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
// SY -->
/**
* Notification channel and ids used for backup and restore.
*/
const val CHANNEL_SIMILAR = "similar_channel"
const val ID_SIMILAR_PROGRESS = -601
const val ID_SIMILAR_COMPLETE = -602
const val ID_SIMILAR_PROGRESS = -901
const val ID_SIMILAR_COMPLETE = -902
// SY <--
private val deprecatedChannels = listOf(
@ -153,6 +159,11 @@ object Notifications {
setShowBadge(false)
setSound(null, null)
},
NotificationChannel(
CHANNEL_CRASH_LOGS,
context.getString(R.string.channel_crash_logs),
NotificationManager.IMPORTANCE_HIGH
),
NotificationChannel(
CHANNEL_SIMILAR,
context.getString(R.string.similar),

View File

@ -25,6 +25,7 @@ import eu.kanade.tachiyomi.source.SourceManager
import eu.kanade.tachiyomi.source.SourceManager.Companion.DELEGATED_SOURCES
import eu.kanade.tachiyomi.ui.base.controller.DialogController
import eu.kanade.tachiyomi.ui.base.controller.withFadeTransaction
import eu.kanade.tachiyomi.util.CrashLogUtil
import eu.kanade.tachiyomi.util.lang.launchUI
import eu.kanade.tachiyomi.util.preference.defaultValue
import eu.kanade.tachiyomi.util.preference.editTextPreference
@ -68,6 +69,16 @@ class SettingsAdvancedController : SettingsController() {
override fun setupPreferenceScreen(screen: PreferenceScreen) = screen.apply {
titleRes = R.string.pref_category_advanced
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"

View File

@ -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())
}
}
}

View File

@ -273,6 +273,11 @@
<string name="pref_read_with_volume_keys">Volume keys</string>
<string name="pref_read_with_volume_keys_inverted">Invert volume keys</string>
<string name="pref_read_with_tapping">Tapping</string>
<string name="pref_read_with_tapping_inverted">Invert tapping</string>
<string name="tapping_inverted_none">None</string>
<string name="tapping_inverted_horizontal">Horizontal</string>
<string name="tapping_inverted_vertical">Vertical</string>
<string name="tapping_inverted_both">Both</string>
<string name="pref_read_with_long_tap">Long tap dialog</string>
<string name="pref_reader_theme">Background color</string>
<string name="white_background">White</string>
@ -412,6 +417,9 @@
<string name="pref_refresh_library_covers">Refresh library manga covers</string>
<string name="pref_refresh_library_tracking">Refresh tracking</string>
<string name="pref_refresh_library_tracking_summary">Updates status, score and last chapter read from the tracking services</string>
<string name="pref_dump_crash_logs">Dump crash logs</string>
<string name="pref_dump_crash_logs_summary">Saves error logs to a file for sharing with the developers</string>
<string name="crash_log_saved">Crash logs saved</string>
<string name="pref_disable_battery_optimization">Disable battery optimization</string>
<string name="pref_disable_battery_optimization_summary">Helps with background library updates and backups</string>
<string name="battery_optimization_disabled">Battery optimization is already disabled</string>
@ -731,11 +739,7 @@
<string name="group_backup_restore">Backup and restore</string>
<string name="channel_new_chapters">Chapter updates</string>
<string name="channel_ext_updates">Extension updates</string>
<string name="pref_read_with_tapping_inverted">Invert tapping</string>
<string name="tapping_inverted_none">None</string>
<string name="tapping_inverted_horizontal">Horizontal</string>
<string name="tapping_inverted_vertical">Vertical</string>
<string name="tapping_inverted_both">Both</string>
<string name="channel_crash_logs">Crash logs</string>
<!-- S Pen actions -->
<string name="spen_previous_page">Previous page</string>