Remove awaisomereport/

This commit is contained in:
Suhan Paradkar 2022-02-10 08:30:53 +05:30 committed by Wisest_wizard
parent cb40591564
commit 3c283625ac
4 changed files with 0 additions and 293 deletions

View File

@ -1,40 +0,0 @@
package awaisomereport
import android.app.Application
class CrashReporter private constructor(application: Application) : Thread.UncaughtExceptionHandler {
private val crashHandler: CrashHandler?
private var startAttempted = false
private var defaultExceptionHandler: Thread.UncaughtExceptionHandler? = null
init {
crashHandler = CrashHandler(application)
}
fun start() {
if (startAttempted) return
startAttempted = true
defaultExceptionHandler = Thread.getDefaultUncaughtExceptionHandler()
Thread.setDefaultUncaughtExceptionHandler(this)
}
override fun uncaughtException(t: Thread, exception: Throwable) {
if (crashHandler == null) {
defaultExceptionHandler?.uncaughtException(t, exception)
return
}
crashHandler.uncaughtException(t, exception, defaultExceptionHandler ?: return)
}
companion object {
@Volatile
private var INSTANCE: CrashReporter? = null
fun getInstance(application: Application): CrashReporter {
return INSTANCE ?: synchronized(this) {
CrashReporter(application).also { INSTANCE = it }
}
}
}
}

View File

@ -1,148 +0,0 @@
package awaisomereport
import android.app.Application
import android.content.Context
import android.content.Intent
import android.os.Build
import android.util.Log
import awais.instagrabber.BuildConfig
import awais.instagrabber.R
import awais.instagrabber.utils.Constants
import awais.instagrabber.utils.extensions.TAG
import java.io.*
import java.time.LocalDateTime
object CrashReporterHelper {
private val shortBorder = "=".repeat(14)
private val longBorder = "=".repeat(21)
private const val prefix = "stack-"
private const val suffix = ".stacktrace"
fun startErrorReporterActivity(
application: Application,
exception: Throwable
) {
try {
application.openFileOutput(
"$prefix${System.currentTimeMillis()}$suffix",
Context.MODE_PRIVATE
).use { it.write(getReportContent(exception).toByteArray()) }
} catch (ex: Exception) {
if (BuildConfig.DEBUG) Log.e(TAG, "", ex)
}
application.startActivity(Intent(application, ErrorReporterActivity::class.java).setFlags(Intent.FLAG_ACTIVITY_NEW_TASK))
}
fun getReportContent(exception: Throwable): String {
var reportContent =
"""
IMPORTANT: If sending by email, your email address and the entire content will be made public at https://github.com/austinhuang0131/barinsta/issues.
When possible, please describe the steps leading to this crash. Thank you for your cooperation.
Error report collected on: ${LocalDateTime.now()}
Information:
$shortBorder
VERSION : ${BuildConfig.VERSION_NAME}
VERSION_CODE : ${BuildConfig.VERSION_CODE}
PHONE-MODEL : ${Build.MODEL}
ANDROID_VERS : ${Build.VERSION.RELEASE}
ANDROID_REL : ${Build.VERSION.SDK_INT}
BRAND : ${Build.BRAND}
MANUFACTURER : ${Build.MANUFACTURER}
BOARD : ${Build.BOARD}
DEVICE : ${Build.DEVICE}
PRODUCT : ${Build.PRODUCT}
HOST : ${Build.HOST}
TAGS : ${Build.TAGS}
Stack:
$shortBorder
""".trimIndent()
reportContent = "$reportContent${getStackStrace(exception)}\n\n*** End of current Report ***"
return reportContent.replace("\n", "\r\n")
}
private fun getStackStrace(exception: Throwable): String {
val writer = StringWriter()
return PrintWriter(writer).use {
val reportBuilder = StringBuilder("\n")
exception.printStackTrace(it)
reportBuilder.append(writer.toString())
var cause = exception.cause
if (cause != null) reportBuilder.append("\nCause:\n$shortBorder\n")
while (cause != null) {
cause.printStackTrace(it)
reportBuilder.append(writer.toString())
cause = cause.cause
}
return@use reportBuilder.toString()
}
}
@JvmStatic
fun startCrashEmailIntent(context: Context) {
try {
val filePath = context.filesDir.absolutePath
val errorFileList: Array<String>? = try {
val dir = File(filePath)
if (dir.exists() && !dir.isDirectory) {
dir.delete()
}
dir.mkdirs()
dir.list { _: File?, name: String -> name.endsWith(suffix) }
} catch (e: Exception) {
null
}
if (errorFileList == null || errorFileList.isEmpty()) {
return
}
val errorStringBuilder: StringBuilder = StringBuilder("\n\n")
val maxSendMail = 5
for ((curIndex, curString) in errorFileList.withIndex()) {
val file = File("$filePath/$curString")
if (curIndex <= maxSendMail) {
errorStringBuilder.append("New Trace collected:\n$longBorder\n")
BufferedReader(FileReader(file)).use { input ->
var line: String?
while (input.readLine().also { line = it } != null) errorStringBuilder.append(line).append("\n")
}
}
file.delete()
}
errorStringBuilder.append("\n\n")
val resources = context.resources
context.startActivity(
Intent.createChooser(
Intent(Intent.ACTION_SEND).apply {
type = "message/rfc822"
flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_GRANT_READ_URI_PERMISSION or Intent.FLAG_GRANT_WRITE_URI_PERMISSION
putExtra(Intent.EXTRA_EMAIL, arrayOf(Constants.CRASH_REPORT_EMAIL))
putExtra(Intent.EXTRA_SUBJECT, resources.getString(R.string.crash_report_subject))
putExtra(Intent.EXTRA_TEXT, errorStringBuilder.toString().replace("\n", "\r\n"))
},
context.resources.getString(R.string.crash_report_title)
)
)
} catch (e: Exception) {
Log.e(TAG, "", e)
}
}
@JvmStatic
fun deleteAllStacktraceFiles(context: Context) {
val filePath = context.filesDir.absolutePath
val errorFileList: Array<File>? = try {
val dir = File(filePath)
if (dir.exists() && !dir.isDirectory) {
dir.delete()
}
dir.mkdirs()
dir.listFiles { _: File?, name: String -> name.endsWith(suffix) }
} catch (e: Exception) {
null
}
errorFileList?.forEach { it.delete() }
}
}

View File

@ -1,96 +0,0 @@
package awaisomereport
import android.app.Activity
import android.content.Context
import android.graphics.Canvas
import android.graphics.Paint
import android.graphics.Paint.FontMetricsInt
import android.graphics.drawable.Drawable
import android.os.Bundle
import android.text.Spannable
import android.text.SpannableString
import android.text.style.ImageSpan
import android.view.View
import android.view.ViewGroup
import androidx.annotation.DrawableRes
import awais.instagrabber.R
import awais.instagrabber.databinding.ActivityCrashErrorBinding
import awaisomereport.CrashReporterHelper.startCrashEmailIntent
import java.lang.ref.WeakReference
import kotlin.system.exitProcess
class ErrorReporterActivity : Activity(), View.OnClickListener {
private lateinit var binding: ActivityCrashErrorBinding
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
binding = ActivityCrashErrorBinding.inflate(layoutInflater)
setContentView(binding.root)
setFinishOnTouchOutside(false)
window.setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT)
val crashTitle = SpannableString(" " + getString(R.string.crash_title))
crashTitle.setSpan(
CenteredImageSpan(this, android.R.drawable.stat_notify_error),
0,
1,
Spannable.SPAN_INCLUSIVE_EXCLUSIVE
)
title = crashTitle
binding.btnReport.setOnClickListener(this)
binding.btnCancel.setOnClickListener(this)
}
override fun onClick(v: View) {
if (v === binding.btnReport) {
startCrashEmailIntent(this)
}
finish()
exitProcess(10)
}
private class CenteredImageSpan(context: Context, @DrawableRes drawableRes: Int) : ImageSpan(context, drawableRes) {
private var drawable: WeakReference<Drawable>? = null
override fun getSize(
paint: Paint,
text: CharSequence,
start: Int,
end: Int,
fm: FontMetricsInt?
): Int {
fm?.apply {
val pfm = paint.fontMetricsInt
ascent = pfm.ascent
descent = pfm.descent
top = pfm.top
bottom = pfm.bottom
}
return cachedDrawable.bounds.right
}
override fun draw(
canvas: Canvas,
text: CharSequence,
start: Int,
end: Int,
x: Float,
top: Int,
y: Int,
bottom: Int,
paint: Paint
) {
canvas.save()
val drawableHeight = cachedDrawable.intrinsicHeight
val fontMetricsInt = paint.fontMetricsInt
val transY = bottom - cachedDrawable.bounds.bottom + (drawableHeight - fontMetricsInt.descent + fontMetricsInt.ascent) / 2
canvas.translate(x, transY.toFloat())
cachedDrawable.draw(canvas)
canvas.restore()
}
private val cachedDrawable: Drawable
get() = drawable?.get() ?: getDrawable().also { drawable = WeakReference(it) }
}
}

View File

@ -1,9 +0,0 @@
package awaisomereport
interface ICrashHandler {
fun uncaughtException(
t: Thread,
exception: Throwable,
defaultExceptionHandler: Thread.UncaughtExceptionHandler
)
}