commit 527f46120a76da4644512c0a5a0fdb34a840e4e7
parent 2cc27953b96f69d268fc31fab9a060feefd1d33b
Author: Atila Butkovits <abutkovits@mozilla.com>
Date: Tue, 9 Dec 2025 05:11:29 +0200
Revert "Bug 2003887, Bug 2003704 - silently fail when trying to start services while backgrounded r=android-reviewers,tcampbell" for causing bustages at CrashHandlerServiceTest.
This reverts commit e81a02b99aae84128329ba94f829efda821fa642.
Revert "Bug 2003704 - ensure throwables are serializable when starting crash services r=android-reviewers,tcampbell"
This reverts commit 04cd091917a368dbb9a722d9d1bbc5568f536c19.
Diffstat:
2 files changed, 6 insertions(+), 52 deletions(-)
diff --git a/mobile/android/android-components/components/lib/crash/src/main/java/mozilla/components/lib/crash/CrashReporter.kt b/mobile/android/android-components/components/lib/crash/src/main/java/mozilla/components/lib/crash/CrashReporter.kt
@@ -4,11 +4,9 @@
package mozilla.components.lib.crash
-import android.app.ForegroundServiceStartNotAllowedException
import android.app.PendingIntent
import android.content.Context
import android.content.Intent
-import android.os.BadParcelableException
import android.os.Build
import androidx.annotation.StyleRes
import androidx.annotation.VisibleForTesting
@@ -21,7 +19,6 @@ import kotlinx.coroutines.withContext
import mozilla.components.concept.base.crash.Breadcrumb
import mozilla.components.concept.base.crash.CrashReporting
import mozilla.components.lib.crash.db.CrashDatabase
-import mozilla.components.lib.crash.db.forceSerializable
import mozilla.components.lib.crash.db.insertCrashSafely
import mozilla.components.lib.crash.db.insertReportSafely
import mozilla.components.lib.crash.db.toCrash
@@ -385,51 +382,13 @@ class CrashReporter internal constructor(
}
@VisibleForTesting(otherwise = VisibleForTesting.PRIVATE)
- internal fun sendCrashReport(context: Context, crash: Crash) = try {
+ internal fun sendCrashReport(context: Context, crash: Crash) {
ContextCompat.startForegroundService(context, SendCrashReportService.createReportIntent(context, crash))
- } catch (e: BadParcelableException) {
- (crash as? Crash.UncaughtExceptionCrash)?.let {
- // We may end up with a throwable that isn't completely serializable, which will cause
- // a crash when the service tries to unbundle it.
- val updatedCrash = it.copy(throwable = it.throwable.forceSerializable())
- ContextCompat.startForegroundService(
- context,
- SendCrashReportService.createReportIntent(context, updatedCrash),
- )
- logger.warn("replaced throwable for crash that could not be serialized")
- }
- } catch (e: IllegalStateException) {
- if (Build.VERSION.SDK_INT > Build.VERSION_CODES.S &&
- e is ForegroundServiceStartNotAllowedException
- ) {
- logger.warn("ignored failed service start while backgrounded")
- } else {
- throw e
- }
}
@VisibleForTesting(otherwise = VisibleForTesting.PRIVATE)
- internal fun sendCrashTelemetry(context: Context, crash: Crash) = try {
+ internal fun sendCrashTelemetry(context: Context, crash: Crash) {
ContextCompat.startForegroundService(context, SendCrashTelemetryService.createReportIntent(context, crash))
- } catch (e: BadParcelableException) {
- (crash as? Crash.UncaughtExceptionCrash)?.let {
- // We may end up with a throwable that isn't completely serializable, which will cause
- // a crash when the service tries to unbundle it.
- val updatedCrash = it.copy(throwable = it.throwable.forceSerializable())
- ContextCompat.startForegroundService(
- context,
- SendCrashTelemetryService.createReportIntent(context, updatedCrash),
- )
- logger.warn("replaced throwable for crash that could not be serialized")
- }
- } catch (e: IllegalStateException) {
- if (Build.VERSION.SDK_INT > Build.VERSION_CODES.S &&
- e is ForegroundServiceStartNotAllowedException
- ) {
- logger.warn("ignored failed service start while backgrounded")
- } else {
- throw e
- }
}
@VisibleForTesting
diff --git a/mobile/android/android-components/components/lib/crash/src/main/java/mozilla/components/lib/crash/db/CrashEntity.kt b/mobile/android/android-components/components/lib/crash/src/main/java/mozilla/components/lib/crash/db/CrashEntity.kt
@@ -173,18 +173,13 @@ private fun Throwable.serialize(): ByteArray {
// If throwable isn't serializable, then use a placeholder Throwable with
// the same stack and include basic name / message data. This gives us
// at least some data to understand these crashes in the wild.
-
- this.forceSerializable().serialize()
+ val innerMessage = "${javaClass.name}: $message"
+ val altThrowable = CrashReporterUnableToRestoreException(innerMessage)
+ altThrowable.stackTrace = stackTrace.clone()
+ altThrowable.serialize()
}
}
-internal fun Throwable.forceSerializable(): Throwable {
- val innerMessage = "${javaClass.name}: $message"
- val altThrowable = CrashReporterUnableToRestoreException(innerMessage)
- altThrowable.stackTrace = stackTrace.clone()
- return altThrowable
-}
-
private fun ByteArray.deserializeThrowable(): Throwable {
val byteArrayInputStream = ByteArrayInputStream(this)
val throwable = ObjectInputStream(byteArrayInputStream).use { ois ->