关于 Android 13,而不是 12 上的早期问题,存在 Google 跟踪器问题here https://issuetracker.google.com/issues/245258072,在撰写本文时已分配但正在等待有意义的响应。
该问题的摘要是,它仅发生在 13 上,并且仅发生在 Pixel 设备上。
CommonsWare 有一篇关于此的博客文章here https://commonsware.com/blog/2022/10/16/issue-trackers-cant-deliver-broadcast-bug.html,我在任何地方找到的唯一其他线索是在 GrapheneOS 的变更日志中,here https://grapheneos.org/releases#2022092800,其中有此行条目:
沙盒化 Google Play 兼容层:不向用户报告 CannotDeliverBroadcastException
我们使用这个 Play 库并遇到了这个错误,因此 Graphene 可能遇到了这个问题,并且不得不进行操作系统修复。
Update:
我暂时相信我们作为一个应用程序已经抑制了这个问题,并阻止它污染我们的统计数据。
我们设置了一个异常处理程序来吸收它,这就是 GrapheneOS 正在做的事情——归功于他们。
class CustomUncaughtExceptionHandler(
private val uncaughtExceptionHandler: Thread.UncaughtExceptionHandler) : Thread.UncaughtExceptionHandler {
override fun uncaughtException(thread: Thread, exception: Throwable) {
if (shouldAbsorb(exception)) {
return
}
uncaughtExceptionHandler.uncaughtException(thread, exception)
}
/**
* Evaluate whether to silently absorb uncaught crashes such that they
* don't crash the app. We generally want to avoid this practice - we would
* rather know about them. However in some cases there's nothing we can do
* about the crash (e.g. it is an OS fault) and we would rather not have them
* pollute our reliability stats.
*/
private fun shouldAbsorb(exception: Throwable): Boolean {
return when (exception::class.simpleName) {
"CannotDeliverBroadcastException" -> true
else -> false
}
}
}
我们必须对类名字符串进行操作,因为 CannotDeliverBroadcastException 类是隐藏的,我们无法使用。
我们在 Application.onCreate() 方法的早期安装这个处理程序,如下所示:
val defaultUncaughtExceptionHandler = Thread.getDefaultUncaughtExceptionHandler()
Thread.setDefaultUncaughtExceptionHandler(
CustomUncaughtExceptionHandler(defaultUncaughtExceptionHandler)
)
我对此可能有点不成熟,但到目前为止,这还没有导致 Play 管理中心中出现任何崩溃。有一些确实出现在我们的其他报告平台中,其中报告的内容/未报告的内容始终各不相同。
需要明确的是,我并不是说这是一种好方法,或者您必须采取的方法。它需要客户端版本,并且有掩盖与此根本原因无关的异常的风险。 Google 有责任在收集数据时解决或忽略此问题。然而,它似乎已经停止了对我们标题可靠性统计数据的影响,所以我想我会分享它作为一种可能性。