Skip to content

Commit

Permalink
Issue mozilla-mobile#1705: Assign UUID to every crash object.
Browse files Browse the repository at this point in the history
  • Loading branch information
pocmo committed Apr 22, 2020
1 parent de719f4 commit 00920e7
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ package mozilla.components.lib.crash
import android.content.Intent
import android.os.Bundle
import java.io.Serializable
import java.util.UUID

// Intent extra used to store crash data under when passing crashes in Intent objects
private const val INTENT_CRASH = "mozilla.components.lib.crash.CRASH"
Expand All @@ -18,6 +19,7 @@ private const val INTENT_EXCEPTION = "exception"
private const val INTENT_BREADCRUMBS = "breadcrumbs"

// Native code crash intent extras (Mirroring GeckoView values)
private const val INTENT_UUID = "uuid"
private const val INTENT_MINIDUMP_PATH = "minidumpPath"
private const val INTENT_EXTRAS_PATH = "extrasPath"
private const val INTENT_MINIDUMP_SUCCESS = "minidumpSuccess"
Expand All @@ -27,6 +29,11 @@ private const val INTENT_FATAL = "fatal"
* Crash types that are handled by this library.
*/
sealed class Crash {
/**
* Unique ID identifying this crash.
*/
abstract val uuid: String

/**
* A crash caused by an uncaught exception.
*
Expand All @@ -35,17 +42,20 @@ sealed class Crash {
*/
data class UncaughtExceptionCrash(
val throwable: Throwable,
val breadcrumbs: ArrayList<Breadcrumb>
val breadcrumbs: ArrayList<Breadcrumb>,
override val uuid: String = UUID.randomUUID().toString()
) : Crash() {
override fun toBundle() = Bundle().apply {
putString(INTENT_UUID, uuid)
putSerializable(INTENT_EXCEPTION, throwable as Serializable)
putParcelableArrayList(INTENT_BREADCRUMBS, breadcrumbs)
}

companion object {
internal fun fromBundle(bundle: Bundle) = UncaughtExceptionCrash(
bundle.getSerializable(INTENT_EXCEPTION) as Throwable,
bundle.getParcelableArrayList(INTENT_BREADCRUMBS) ?: arrayListOf()
uuid = bundle.getString(INTENT_UUID) as String,
throwable = bundle.getSerializable(INTENT_EXCEPTION) as Throwable,
breadcrumbs = bundle.getParcelableArrayList(INTENT_BREADCRUMBS) ?: arrayListOf()
)
}
}
Expand All @@ -69,9 +79,11 @@ sealed class Crash {
val minidumpSuccess: Boolean,
val extrasPath: String?,
val isFatal: Boolean,
val breadcrumbs: ArrayList<Breadcrumb>
val breadcrumbs: ArrayList<Breadcrumb>,
override val uuid: String = UUID.randomUUID().toString()
) : Crash() {
override fun toBundle() = Bundle().apply {
putString(INTENT_UUID, uuid)
putString(INTENT_MINIDUMP_PATH, minidumpPath)
putBoolean(INTENT_MINIDUMP_SUCCESS, minidumpSuccess)
putString(INTENT_EXTRAS_PATH, extrasPath)
Expand All @@ -81,11 +93,12 @@ sealed class Crash {

companion object {
internal fun fromBundle(bundle: Bundle) = NativeCodeCrash(
bundle.getString(INTENT_MINIDUMP_PATH, null),
bundle.getBoolean(INTENT_MINIDUMP_SUCCESS, false),
bundle.getString(INTENT_EXTRAS_PATH, null),
bundle.getBoolean(INTENT_FATAL, false),
bundle.getParcelableArrayList(INTENT_BREADCRUMBS) ?: arrayListOf()
uuid = bundle.getString(INTENT_UUID) as String,
minidumpPath = bundle.getString(INTENT_MINIDUMP_PATH, null),
minidumpSuccess = bundle.getBoolean(INTENT_MINIDUMP_SUCCESS, false),
extrasPath = bundle.getString(INTENT_EXTRAS_PATH, null),
isFatal = bundle.getBoolean(INTENT_FATAL, false),
breadcrumbs = bundle.getParcelableArrayList(INTENT_BREADCRUMBS) ?: arrayListOf()
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class NativeCodeCrashTest {
intent.component = ComponentName(
"org.mozilla.samples.browser",
"mozilla.components.lib.crash.handler.CrashHandlerService")
intent.putExtra("uuid", "afc91225-93d7-4328-b3eb-d26ad5af4d86")
intent.putExtra("minidumpPath",
"/data/data/org.mozilla.samples.browser/files/mozilla/Crash Reports/pending/3ba5f665-8422-dc8e-a88e-fc65c081d304.dmp")
intent.putExtra("fatal", false)
Expand All @@ -29,6 +30,10 @@ class NativeCodeCrashTest {

val crash = Crash.NativeCodeCrash.fromBundle(intent.extras!!)

assertEquals(
"afc91225-93d7-4328-b3eb-d26ad5af4d86",
crash.uuid
)
assertEquals(crash.minidumpSuccess, true)
assertEquals(crash.isFatal, false)
assertEquals(
Expand All @@ -40,4 +45,20 @@ class NativeCodeCrashTest {
crash.extrasPath
)
}

@Test
fun `to and from bundle`() {
val crash = Crash.NativeCodeCrash(
"minidumpPath",
true,
"extrasPath",
true,
arrayListOf()
)

val bundle = crash.toBundle()
val otherCrash = Crash.NativeCodeCrash.fromBundle(bundle)

assertEquals(crash, otherCrash)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,15 @@ class UncaughtExceptionCrashTest {

assertEquals(exception, crash.throwable)
}

@Test
fun `to and from bundle`() {
val exception = RuntimeException("Kaput")
val crash = Crash.UncaughtExceptionCrash(exception, arrayListOf())

val bundle = crash.toBundle()
val otherCrash = Crash.UncaughtExceptionCrash.fromBundle(bundle)

assertEquals(crash, otherCrash)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ class CrashHandlerServiceTest {
"org.mozilla.samples.browser",
"mozilla.components.lib.crash.handler.CrashHandlerService"
)
intent?.putExtra(
"uuid",
"94f66ed7-50c7-41d1-96a7-299139a8c2af"
)
intent?.putExtra(
"minidumpPath",
"/data/data/org.mozilla.samples.browser/files/mozilla/Crash Reports/pending/3ba5f665-8422-dc8e-a88e-fc65c081d304.dmp"
Expand Down

0 comments on commit 00920e7

Please sign in to comment.