-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature: replace
ACRA
crash report with own implementation
- Loading branch information
Showing
16 changed files
with
297 additions
and
92 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,43 +4,13 @@ import android.app.Application | |
import android.content.Context | ||
import androidx.hilt.work.HiltWorkerFactory | ||
import androidx.work.Configuration | ||
import com.kaajjo.libresudoku.di.ACRA_SHARED_PREFS_NAME | ||
import dagger.hilt.android.HiltAndroidApp | ||
import org.acra.config.dialog | ||
import org.acra.config.mailSender | ||
import org.acra.data.StringFormat | ||
import org.acra.ktx.initAcra | ||
import java.time.LocalDate | ||
import javax.inject.Inject | ||
|
||
@HiltAndroidApp | ||
class LibreSudokuApp : Application(), Configuration.Provider { | ||
override fun attachBaseContext(base: Context?) { | ||
super.attachBaseContext(base) | ||
|
||
if (!BuildConfig.DEBUG) { | ||
// Only user can send a crash report | ||
initAcra { | ||
buildConfigClass = BuildConfig::class.java | ||
reportFormat = StringFormat.KEY_VALUE_LIST | ||
|
||
dialog { | ||
title = getString(R.string.app_name) | ||
text = getString(R.string.dialog_crash_report_text) | ||
negativeButtonText = getString(R.string.dialog_no) | ||
positiveButtonText = getString(R.string.dialog_yes) | ||
resTheme = android.R.style.Theme_DeviceDefault_Dialog | ||
} | ||
|
||
mailSender { | ||
mailTo = "[email protected]" | ||
reportFileName = "Report_${LocalDate.now()}_v${BuildConfig.VERSION_NAME}.txt" | ||
subject = "LibreSudoku crash report" | ||
reportAsFile = true | ||
} | ||
sharedPreferencesName = ACRA_SHARED_PREFS_NAME | ||
} | ||
} | ||
} | ||
|
||
@Inject | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
app/src/main/java/com/kaajjo/libresudoku/core/utils/GlobalExceptionHandler.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package com.kaajjo.libresudoku.core.utils | ||
|
||
import android.app.Activity | ||
import android.content.Context | ||
import android.content.Intent | ||
import android.util.Log | ||
import kotlin.system.exitProcess | ||
|
||
class GlobalExceptionHandler<T : Activity> private constructor( | ||
private val applicationContext: Context, | ||
private val defaultHandler: Thread.UncaughtExceptionHandler, | ||
private val activityToBeLaunched: Class<T> | ||
) : Thread.UncaughtExceptionHandler { | ||
|
||
override fun uncaughtException(p0: Thread, p1: Throwable) { | ||
kotlin.runCatching { | ||
Log.e(this.toString(), p1.stackTraceToString()) | ||
applicationContext.launchActivity(activityToBeLaunched, p1) | ||
exitProcess(0) | ||
}.getOrElse { | ||
defaultHandler.uncaughtException(p0, p1) | ||
} | ||
} | ||
|
||
private fun <T : Activity> Context.launchActivity( | ||
activity: Class<T>, | ||
exception: Throwable | ||
) { | ||
val crashedIntent = Intent(applicationContext, activity).apply { | ||
putExtra(INTENT_DATA_NAME, "$exception\n${Log.getStackTraceString(exception)}") | ||
addFlags(defFlags) | ||
} | ||
applicationContext.startActivity(crashedIntent) | ||
} | ||
|
||
companion object { | ||
private const val INTENT_DATA_NAME = "GlobalExceptionHandler" | ||
private const val defFlags = Intent.FLAG_ACTIVITY_CLEAR_TOP or | ||
Intent.FLAG_ACTIVITY_NEW_TASK or | ||
Intent.FLAG_ACTIVITY_CLEAR_TASK | ||
|
||
fun <T : Activity> initialize( | ||
applicationContext: Context, | ||
activityToBeLaunched: Class<T> | ||
) = Thread.setDefaultUncaughtExceptionHandler( | ||
GlobalExceptionHandler( | ||
applicationContext, | ||
Thread.getDefaultUncaughtExceptionHandler() as Thread.UncaughtExceptionHandler, | ||
activityToBeLaunched | ||
) | ||
) | ||
|
||
fun Activity.getExceptionString(): String = intent.getStringExtra(INTENT_DATA_NAME) ?: "" | ||
} | ||
} |
26 changes: 0 additions & 26 deletions
26
app/src/main/java/com/kaajjo/libresudoku/data/datastore/AcraSharedPrefs.kt
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.