当前位置: 首页 > news >正文

应用crash时发送广播及信息

一、环境

高通865 Android 10

二、情景

应用崩溃时,将奔溃信息以广播的形式发送

二、代码位置

frameworks/base/core/java/com/android/internal/os/RuntimeInit.java

    private static class KillApplicationHandler implements Thread.UncaughtExceptionHandler {private final LoggingHandler mLoggingHandler;/*** Create a new KillApplicationHandler that follows the given LoggingHandler.* If {@link #uncaughtException(Thread, Throwable) uncaughtException} is called* on the created instance without {@code loggingHandler} having been triggered,* {@link LoggingHandler#uncaughtException(Thread, Throwable)* loggingHandler.uncaughtException} will be called first.** @param loggingHandler the {@link LoggingHandler} expected to have run before*     this instance's {@link #uncaughtException(Thread, Throwable) uncaughtException}*     is being called.*/public KillApplicationHandler(LoggingHandler loggingHandler) {this.mLoggingHandler = Objects.requireNonNull(loggingHandler);}@Overridepublic void uncaughtException(Thread t, Throwable e) {try {ensureLogging(t, e);// Don't re-enter -- avoid infinite loops if crash-reporting crashes.if (mCrashing) return;mCrashing = true;//应用奔溃时发送广播Log.d(TAG," uncaughtException com.sc.app.crash.info ");Intent mIntent = new Intent();mIntent.setAction("com.sc.app.crash.info");mIntent.putExtra("crashInfo", Log.getStackTraceString(e));ActivityThread.currentApplication().sendBroadcast(mIntent);// Try to end profiling. If a profiler is running at this point, and we kill the// process (below), the in-memory buffer will be lost. So try to stop, which will// flush the buffer. (This makes method trace profiling useful to debug crashes.)if (ActivityThread.currentActivityThread() != null) {ActivityThread.currentActivityThread().stopProfiling();}// Bring up crash dialog, wait for it to be dismissedActivityManager.getService().handleApplicationCrash(mApplicationObject, new ApplicationErrorReport.ParcelableCrashInfo(e));} catch (Throwable t2) {if (t2 instanceof DeadObjectException) {// System process is dead; ignore} else {try {Clog_e(TAG, "Error reporting crash", t2);} catch (Throwable t3) {// Even Clog_e() fails!  Oh well.}}} finally {// Try everything to make sure this process goes away.Process.killProcess(Process.myPid());System.exit(10);}}/*** Ensures that the logging handler has been triggered.** See b/73380984. This reinstates the pre-O behavior of**   {@code thread.getUncaughtExceptionHandler().uncaughtException(thread, e);}** logging the exception (in addition to killing the app). This behavior* was never documented / guaranteed but helps in diagnostics of apps* using the pattern.** If this KillApplicationHandler is invoked the "regular" way (by* {@link Thread#dispatchUncaughtException(Throwable)* Thread.dispatchUncaughtException} in case of an uncaught exception)* then the pre-handler (expected to be {@link #mLoggingHandler}) will already* have run. Otherwise, we manually invoke it here.*/private void ensureLogging(Thread t, Throwable e) {if (!mLoggingHandler.mTriggered) {try {mLoggingHandler.uncaughtException(t, e);} catch (Throwable loggingThrowable) {// Ignored.}}}}

http://www.lryc.cn/news/197853.html

相关文章:

  • 【亲测可用】图像目标识别入门-利用笔记本电脑摄像头识别人脸标记出来采用深度学习模型实现
  • 数字孪生技术:煤矿运输的未来革命
  • 一些bug总结
  • 第三章 内存管理 九、基本分段存储管理方式
  • 轻重链剖分+启发式合并专题
  • IRC/ML:金融智能风控—信贷风控场景简介、两大场景(贷款场景+信用卡场景)、信用卡评分模型设计、反欺诈检测技术的简介、案例应用之详细攻略
  • 【学习笔记】RabbitMQ01:基础概念认识以及快速部署
  • Java数据结构之第二十章、手撕平衡AVL树
  • SQL 在PostgreSQL中使用SQL将多行连接成数组
  • Ajax技术实现前端开发
  • WebMail:网页注册成功发送邮件
  • Electron之集成vue+vite开发桌面程序
  • pycharm社区版创建Django项目的一种方式
  • Python configparser模块使用教程
  • Kotlin + 协程 + Room 结合使用
  • 网工记背命令(6)----链路聚合配置
  • 使用 Service 把前端连接到后端
  • vue 如何优化首页的加载速度?vue 首页白屏是什么问题引起的?如何解决呢?
  • Android平台GB28181设备接入模块之SmartGBD
  • JVM第十三讲:调试排错 - JVM 调优参数
  • Android Gradle权威指南读书笔记
  • 顺子日期(蓝桥杯)
  • 攻防世界web篇-unserialize3
  • 微信小程序 onLoad和onShow的区别
  • elementui select组件下拉框底部增加自定义按钮
  • 深入理解闭包:原理、应用与最佳实践
  • [NSSCTF 2nd]Math
  • uml知识点学习
  • JAVA学习日记1——JAVA简介及第一个java程序
  • Linux命令(102)之less