Remove crash log notification in favor of sharing directly

This commit is contained in:
arkon
2023-04-02 15:30:07 -04:00
parent c9bd3a5314
commit 75460e01c8
4 changed files with 6 additions and 71 deletions

View File

@ -119,14 +119,6 @@ class NotificationReceiver : BroadcastReceiver() {
downloadChapters(urls, mangaId)
}
}
// Share crash dump file
ACTION_SHARE_CRASH_LOG ->
shareFile(
context,
intent.getParcelableExtraCompat(EXTRA_URI)!!,
"text/plain",
intent.getIntExtra(EXTRA_NOTIFICATION_ID, -1),
)
}
}
@ -272,8 +264,6 @@ class NotificationReceiver : BroadcastReceiver() {
private const val ACTION_SHARE_BACKUP = "$ID.$NAME.SEND_BACKUP"
private const val ACTION_SHARE_CRASH_LOG = "$ID.$NAME.SEND_CRASH_LOG"
private const val ACTION_CANCEL_RESTORE = "$ID.$NAME.CANCEL_RESTORE"
private const val ACTION_CANCEL_LIBRARY_UPDATE = "$ID.$NAME.CANCEL_LIBRARY_UPDATE"
@ -566,23 +556,6 @@ class NotificationReceiver : BroadcastReceiver() {
return PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_IMMUTABLE)
}
/**
* Returns [PendingIntent] that starts a share activity for a crash log dump file.
*
* @param context context of application
* @param uri uri of file
* @param notificationId id of notification
* @return [PendingIntent]
*/
internal fun shareCrashLogPendingBroadcast(context: Context, uri: Uri, notificationId: Int): PendingIntent {
val intent = Intent(context, NotificationReceiver::class.java).apply {
action = ACTION_SHARE_CRASH_LOG
putExtra(EXTRA_URI, uri)
putExtra(EXTRA_NOTIFICATION_ID, notificationId)
}
return PendingIntent.getBroadcast(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE)
}
/**
* Returns [PendingIntent] that cancels a backup restore job.
*

View File

@ -59,12 +59,6 @@ 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
/**
* Notification channel used for Incognito Mode
*/
@ -90,6 +84,7 @@ object Notifications {
"library_progress_channel",
"updates_ext_channel",
"downloader_cache_renewal",
"crash_logs_channel",
)
/**
@ -165,9 +160,6 @@ object Notifications {
setShowBadge(false)
setSound(null, null)
},
buildNotificationChannel(CHANNEL_CRASH_LOGS, IMPORTANCE_HIGH) {
setName(context.getString(R.string.channel_crash_logs))
},
buildNotificationChannel(CHANNEL_INCOGNITO_MODE, IMPORTANCE_LOW) {
setName(context.getString(R.string.pref_incognito_mode))
},

View File

@ -1,16 +1,11 @@
package eu.kanade.tachiyomi.util
import android.content.Context
import android.net.Uri
import android.os.Build
import eu.kanade.tachiyomi.BuildConfig
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.cancelNotification
import eu.kanade.tachiyomi.util.system.createFileInCacheDir
import eu.kanade.tachiyomi.util.system.notify
import eu.kanade.tachiyomi.util.system.toShareIntent
import eu.kanade.tachiyomi.util.system.toast
import tachiyomi.core.util.lang.withNonCancellableContext
import tachiyomi.core.util.lang.withUIContext
@ -23,7 +18,8 @@ class CrashLogUtil(private val context: Context) {
Runtime.getRuntime().exec("logcat *:E -d -f ${file.absolutePath}").waitFor()
file.appendText(getDebugInfo())
showNotification(file.getUriCompat(context))
val uri = file.getUriCompat(context)
context.startActivity(uri.toShareIntent(context, "text/plain"))
} catch (e: Throwable) {
withUIContext { context.toast("Failed to get logs") }
}
@ -41,28 +37,4 @@ class CrashLogUtil(private val context: Context) {
Device product name: ${Build.PRODUCT}
""".trimIndent()
}
private fun showNotification(uri: Uri) {
context.cancelNotification(Notifications.ID_CRASH_LOGS)
context.notify(
Notifications.ID_CRASH_LOGS,
Notifications.CHANNEL_CRASH_LOGS,
) {
setContentTitle(context.getString(R.string.crash_log_saved))
setSmallIcon(R.drawable.ic_tachi)
clearActions()
addAction(
R.drawable.ic_folder_24dp,
context.getString(R.string.action_open_log),
NotificationReceiver.openErrorLogPendingActivity(context, uri),
)
addAction(
R.drawable.ic_share_24dp,
context.getString(R.string.action_share),
NotificationReceiver.shareCrashLogPendingBroadcast(context, uri, Notifications.ID_CRASH_LOGS),
)
}
}
}