-
Notifications
You must be signed in to change notification settings - Fork 204
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(ExitInfo)added DiscardEventCallback
- Loading branch information
1 parent
c82916e
commit 64ba4cb
Showing
7 changed files
with
89 additions
and
28 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
40 changes: 40 additions & 0 deletions
40
...g-plugin-android-exitinfo/src/main/java/com/bugsnag/android/ApplicationExitInfoMatcher.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,40 @@ | ||
package com.bugsnag.android | ||
|
||
import android.app.ActivityManager | ||
import android.app.ApplicationExitInfo | ||
import android.content.Context | ||
import android.os.Build | ||
import androidx.annotation.RequiresApi | ||
|
||
@RequiresApi(Build.VERSION_CODES.R) | ||
internal class ApplicationExitInfoMatcher( | ||
private val context: Context, | ||
private val pid: Int | ||
) { | ||
fun matchExitInfo(event: Event): ApplicationExitInfo? { | ||
val am: ActivityManager = | ||
context.getSystemService(Context.ACTIVITY_SERVICE) as ActivityManager | ||
val allExitInfo: List<ApplicationExitInfo> = | ||
am.getHistoricalProcessExitReasons(context.packageName, 0, MAX_EXIT_INFO) | ||
val sessionIdBytes: ByteArray = | ||
event.session?.id?.toByteArray() ?: return null | ||
val exitInfo: ApplicationExitInfo = | ||
findExitInfoBySessionId(allExitInfo, sessionIdBytes) | ||
?: findExitInfoByPid(allExitInfo) ?: return null | ||
return exitInfo | ||
} | ||
|
||
internal fun findExitInfoBySessionId( | ||
allExitInfo: List<ApplicationExitInfo>, | ||
sessionIdBytes: ByteArray | ||
) = allExitInfo.find { | ||
it.processStateSummary?.contentEquals(sessionIdBytes) == true | ||
} | ||
|
||
internal fun findExitInfoByPid(allExitInfo: List<ApplicationExitInfo>) = | ||
allExitInfo.find { it.pid == pid } | ||
|
||
internal companion object { | ||
private const val MAX_EXIT_INFO = 100 | ||
} | ||
} |
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
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