Skip to content

Commit

Permalink
feature(exitInfo) add pid check into exitinfo callback
Browse files Browse the repository at this point in the history
  • Loading branch information
YYChen01988 committed Sep 25, 2023
1 parent 23c5062 commit 217fc45
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,13 @@ class BugsnagExitInfoPlugin @JvmOverloads constructor(
)
}

val exitInfoPluginStore = ExitInfoPluginStore(client.immutableConfig)
val oldPid = exitInfoPluginStore.load()
exitInfoPluginStore.persist(android.os.Process.myPid())

exitInfoCallback = ExitInfoCallback(
client.appContext,
oldPid,
TombstoneEventEnhancer(client.logger, listOpenFds, includeLogcat),
TraceEventEnhancer(client.logger, client.immutableConfig.projectPackages)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import androidx.annotation.RequiresApi

internal class ExitInfoCallback(
private val context: Context,
private val pid: Int?,
private val nativeEnhancer: (Event, ApplicationExitInfo) -> Unit,
private val anrEventEnhancer: (Event, ApplicationExitInfo) -> Unit
) : OnSendCallback {
Expand All @@ -18,8 +19,10 @@ internal class ExitInfoCallback(
val allExitInfo = am.getHistoricalProcessExitReasons(context.packageName, 0, MAX_EXIT_INFO)
val sessionIdBytes = event.session?.id?.toByteArray() ?: return true
val exitInfo =
allExitInfo.find { it.processStateSummary?.contentEquals(sessionIdBytes) == true }
?: return true
allExitInfo.find {
it.processStateSummary?.contentEquals(sessionIdBytes) == true
}
?: allExitInfo.find { it.pid == pid } ?: return true

try {
if (exitInfo.reason == ApplicationExitInfo.REASON_CRASH_NATIVE ||
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,10 @@ internal class TombstoneParser(
values.forEach { thread ->
val stacktrace = thread.currentBacktraceList.map { tombstoneTraceFrame ->
val stackFrame = Stackframe(
tombstoneTraceFrame.functionName,
tombstoneTraceFrame.fileName,
tombstoneTraceFrame.relPc,
null
method = tombstoneTraceFrame.functionName,
file = tombstoneTraceFrame.fileName,
lineNumber = tombstoneTraceFrame.relPc,
inProject = null
)
stackFrame.symbolAddress = tombstoneTraceFrame.functionOffset
stackFrame.loadAddress = tombstoneTraceFrame.fileMapOffset
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ internal class ExitInfoCallbackTest {

@Before
fun setUp() {
exitInfoCallback = ExitInfoCallback(context, nativeEnhancer, anrEventEnhancer)
exitInfoCallback = ExitInfoCallback(context, 100, nativeEnhancer, anrEventEnhancer)
exitInfos = listOf(exitInfo1)
`when`(context.getSystemService(any())).thenReturn(am)
`when`(am.getHistoricalProcessExitReasons(any(), anyInt(), anyInt()))
Expand Down

0 comments on commit 217fc45

Please sign in to comment.