Android Camera close异常导致app的input ANR案例分析

1. 背景
在日常的项目开发过程中,经常会收到用户或者测试同仁报过来的ANR(Application Not Response)的问题,本文结合作者的日常工作中遇到的典型案例,分享ANR的分析过程。

 ANR(‌Application Not Responding)‌主要分为以下几种类型:‌

Input dispatching timed out:‌当输入事件(‌包括按键和触屏事件)‌在5秒内没有处理完成时,‌会发生ANR。‌这种情况下的日志关键字是“Input event dispatching timed out”。‌

BroadcastTimeout:‌包括前台广播和后台广播。‌前台广播需要在10秒内完成,‌而后台广播则需要在60秒内完成。‌如果超时不处理,‌就会发生ANR。‌相关的日志关键字是“Timeout of broadcast BroadcastRecord”。‌

ServiceTimeout:‌对于前台服务,‌其生命周期方法(‌如onCreate, onStart, onBind等)‌需要在20秒内完成;‌而对于后台服务,‌这些方法需要在200秒内完成。‌超时未处理会导致ANR,‌日志关键字为“Timeout executing service”。‌

ContentProviderTimeout:‌ContentProvider在10秒内没有处理完成时也会发生ANR。‌相关的日志关键字是“timeout publishing content providers”。‌

2. ANR分析流程

1. 首先找到log中的anr trace,根据trace寻找anr 到底是卡在哪里?
log\anr\anr_2024-07-31-14-02-16-207
----- pid 8838 at 2024-07-31 14:02:16 -----
Cmd line: com.xxx.xxx

从anr trace首先可以确定anr 发现的pid和process name,并能够找到anr dump的时间点,一般来说anr dump的时间点就是anr发生之后的时间点,与anr发生的时间点比较接近。

pid 8838 ---------pid
Cmd line: com.xxx.xxx ------process name
2024-07-31 14:02:16 ------anr dump time ~ anr time

2. 通过android main log,根据"am_anr" 这个关键字,找到anr的pid,更精确的时间点以及anr的类型。

07-31 14:02:15.404 985 5018 I am_anr : [0,8838,com.xxx.xxx,549994055,Input dispatching timed out (e4d2f67 com.xxx.xxx/com.xxx.xxx.subject.ScreenDisplayTestActivity (server) is not responding. Waited 5001ms for FocusEvent(hasFocus=false))]

pid 和 anr trace的相同:8838
anr 类型:dispatching timed out
根据anr类型,我们可以知道,这个input event在anr发生的前5s触发,但是app一直没有响应,也就是app卡了5s,那么我们接下来要看anr发生时间点的前5s app在忙什么事情,我们可以通过pid=8838搜log,找到相关信息。

行  8051: 07-31 14:02:09.418  8838  8838 I wm_on_stop_called: [144380212,com.xxx.xxxb.subject.CameraTestActivity,LIFECYCLER_STOP_ACTIVITY]
	行  8052: 07-31 14:02:09.418  8838  8838 D FragmentManager: onCleared 
  • 21
    点赞
  • 15
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值