Skip to content
This repository has been archived by the owner on Jun 17, 2024. It is now read-only.

Commit

Permalink
Revert "Bug 1875294 - Record breadbcrumbs before crashing with Unsats…
Browse files Browse the repository at this point in the history
…isfiedLinkError"

This reverts commit 6fb061c.

These didn't work out in practice.  The file lists were always empty, I
think it might be a difference in permissions for release builds vs the
debug builds that I was testing with.

The package installer name was useful, but I realized there's Sentry tag for that which is even more useful.
  • Loading branch information
bendk authored and mergify[bot] committed Feb 12, 2024
1 parent a26e21e commit 5c0e0ca
Showing 1 changed file with 5 additions and 71 deletions.
76 changes: 5 additions & 71 deletions fenix/app/src/main/java/org/mozilla/fenix/FenixApplication.kt
Original file line number Diff line number Diff line change
Expand Up @@ -112,11 +112,8 @@ import org.mozilla.fenix.session.VisibilityLifecycleCallback
import org.mozilla.fenix.utils.Settings
import org.mozilla.fenix.utils.Settings.Companion.TOP_SITES_PROVIDER_MAX_THRESHOLD
import org.mozilla.fenix.wallpapers.Wallpaper
import java.io.File
import java.io.FileInputStream
import java.util.UUID
import java.util.concurrent.TimeUnit
import java.util.zip.ZipInputStream
import kotlin.math.roundToLong

private const val RAM_THRESHOLD_MEGABYTES = 1024
Expand Down Expand Up @@ -525,76 +522,13 @@ open class FenixApplication : LocaleAwareApplication(), Provider {
* thread, early in the app startup sequence.
*/
private fun beginSetupMegazord() {
try {
// Note: Megazord.init() must be called as soon as possible ...
Megazord.init()

initializeRustErrors(components.analytics.crashReporter)
// ... but RustHttpConfig.setClient() and RustLog.enable() can be called later.
// Note: Megazord.init() must be called as soon as possible ...
Megazord.init()

RustLog.enable()
} catch (e: UnsatisfiedLinkError) {
@Suppress("TooGenericExceptionCaught")
try {
reportUnsatisfiedLinkErrorBreadcrumbs()
} catch (e: Throwable) {
// This shouldn't happen, but if it does it's better to ignore the exception from
// the breadcrumb code and rethrow the initial exception.
}
throw e
}
}
initializeRustErrors(components.analytics.crashReporter)
// ... but RustHttpConfig.setClient() and RustLog.enable() can be called later.

private fun reportUnsatisfiedLinkErrorBreadcrumbs() {
val breadcrumbStrings = mutableListOf<String>()
val apkPath = applicationContext.getApplicationInfo().sourceDir
breadcrumbStrings.add("APK: $apkPath")
val apkDir = File(apkPath).getParentFile()
val installSourcePackage = if (SDK_INT >= Build.VERSION_CODES.R) {
packageManager.getInstallSourceInfo(packageName).installingPackageName
} else {
@Suppress("DEPRECATION")
packageManager.getInstallerPackageName(packageName)
}
breadcrumbStrings.add("Installer package name: $installSourcePackage")

val installDirFileSet = if (apkDir != null) {
apkDir.walk()
.filter { it != apkDir && !it.isDirectory() }
.map { it.relativeTo(apkDir).toString() }
.filter { it.startsWith("lib/") }
.toHashSet()
} else {
HashSet()
}
val apkFileSet = ZipInputStream(FileInputStream(apkPath)).use {
generateSequence { it.nextEntry }
.map { it.name }
.filter { it.startsWith("lib/") }
.toHashSet()
}
fun formatFileSet(filenames: Set<String>) = if (filenames.size > 0) {
filenames.joinToString(", ")
} else {
"<none>"
}
val installDirOnly = formatFileSet(installDirFileSet - apkFileSet)
val apkFileOnly = formatFileSet(apkFileSet - installDirFileSet)
val both = formatFileSet(installDirFileSet union apkFileSet)

breadcrumbStrings.add("Files only inside lib/ dir: $installDirOnly")
breadcrumbStrings.add("Files only inside APK lib/ dir: $apkFileOnly")
breadcrumbStrings.add("Files inside both lib/ dirs: $both")

for (breadcrumbString in breadcrumbStrings) {
components.analytics.crashReporter.recordCrashBreadcrumb(
Breadcrumb(
category = "Startup",
message = breadcrumbString,
level = Breadcrumb.Level.INFO,
),
)
}
RustLog.enable()
}

@OptIn(DelicateCoroutinesApi::class) // GlobalScope usage
Expand Down

0 comments on commit 5c0e0ca

Please sign in to comment.