Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 477ee085 authored by Ricki Hirner's avatar Ricki Hirner
Browse files

Show unhandled exceptions with DebugInfoActivity

parent 8f62c185
Loading
Loading
Loading
Loading
+17 −1
Original line number Diff line number Diff line
@@ -20,11 +20,13 @@ import androidx.appcompat.app.AppCompatDelegate
import androidx.appcompat.content.res.AppCompatResources
import androidx.multidex.MultiDexApplication
import at.bitfire.davdroid.log.Logger
import at.bitfire.davdroid.ui.DebugInfoActivity
import at.bitfire.davdroid.ui.NotificationUtils
import java.util.logging.Level
import kotlin.concurrent.thread

@Suppress("unused")
class App: MultiDexApplication() {
class App: MultiDexApplication(), Thread.UncaughtExceptionHandler {

    companion object {

@@ -50,6 +52,9 @@ class App: MultiDexApplication() {
        super.onCreate()
        Logger.initialize(this)

        //if (BuildConfig.FLAVOR == FLAVOR_STANDARD)
            Thread.setDefaultUncaughtExceptionHandler(this)

        if (BuildConfig.DEBUG)
            StrictMode.setVmPolicy(StrictMode.VmPolicy.Builder()
                    .detectActivityLeaks()
@@ -79,4 +84,15 @@ class App: MultiDexApplication() {
        }
    }

    override fun uncaughtException(t: Thread, e: Throwable) {
        Logger.log.log(Level.SEVERE, "Unhandled exception!", e)

        val intent = Intent(this, DebugInfoActivity::class.java)
        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
        intent.putExtra(DebugInfoActivity.KEY_THROWABLE, e)
        startActivity(intent)

        System.exit(1)
    }

}
+1 −5
Original line number Diff line number Diff line
@@ -60,7 +60,6 @@ class DebugInfoActivity: AppCompatActivity() {
        const val KEY_LOGS = "logs"
        const val KEY_ACCOUNT = "account"
        const val KEY_AUTHORITY = "authority"
        const val KEY_PHASE = "phase"
        const val KEY_LOCAL_RESOURCE = "localResource"
        const val KEY_REMOTE_RESOURCE = "remoteResource"
    }
@@ -132,11 +131,8 @@ class DebugInfoActivity: AppCompatActivity() {
                val text = StringBuilder("--- BEGIN DEBUG INFO ---\n")

                // begin with most specific information
                extras?.getInt(KEY_PHASE, -1).takeIf { it != -1 }?.let {
                    text.append("SYNCHRONIZATION INFO\nSynchronization phase: $it\n")
                }
                extras?.getParcelable<Account>(KEY_ACCOUNT)?.let {
                    text.append("Account name: ${it.name}\n")
                    text.append("SYNCHRONIZATION INFO\nAccount name: ${it.name}\n")
                }
                extras?.getString(KEY_AUTHORITY)?.let {
                    text.append("Authority: $it\n")