Android ANR-Keydispatch timeout

Code flow of ANR


  • Code flow of InputSystem

这里写图片描述

  • Code flow of dispatch input event
    这里写图片描述
    这里写图片描述

flow of Scenario


normal flow
这里写图片描述

// notifyKey() / notifyMotion()
01-15 11:55:56.713   937  1127 D InputDispatcher: notifyM-evT=1156348,dev=1,src=0x1002, ac=0x0, downT=1156348
01-15 11:55:56.713   937  1127 D InputDispatcher: id[0]=0,tool=1,x=670,y=1246

// dispatchKeyLocked() / dispatchMotionLocked() -> dispatchEventLocked()
// dispatchEventLocked to every inputTarget
01-15 11:55:56.713   937  1126 D InputDispatcher: DispatchM[0]42644ed8 NavigationBar (s),evT=1156348,curT=1156351
01-15 11:55:56.713   937  1126 D InputDispatcher: DispatchM[0]425a5d78 StatusBar (s),evT=1156348,curT=1156351
01-15 11:55:56.713   937  1126 D InputDispatcher: DispatchM[0]4354eee0 com.android.settings.Settings (s),evT=1156348,curT=1156351
01-15 11:55:56.713   937  1126 D InputDispatcher: DispatchM[0]WindowManager (s),evT=1156348,curT=1156351

// finishDispatchCycleLocked() -> ... -> doDispatchCycleFinishedLockedInterruptible()
01-15 11:55:56.713   937  1126 D InputDispatcher: FinishedM-evT=1156348
01-15 11:55:56.713   937  1126 D InputDispatcher: FinishedM-evT=1156348
01-15 11:55:56.713   937  1126 D InputDispatcher: FinishedM-evT=1156348
01-15 11:55:56.713   937  1126 D InputDispatcher: FinishedM-evT=1156348

No focused window
这里写图片描述

@ bugreport
Input Dispatcher State at time of last ANR:
  ANR:
    Time: 2014-02-20 12:13:15
    Window: AppWindowToken{4282ed50 token=Token{42755b28 ActivityRecord{42485160 u0 com.htc.camera/.CameraEntry t23}}}
    DispatchLatency: 5022.9ms
    WaitDuration: 5005.4ms
    Reason: Waiting because no window has focus but there is a focused application that may eventually add a window when it finishes starting up.
  DispatchEnabled: 1
  DispatchFrozen: 0
  FocusedApplication: name='AppWindowToken{4282ed50 token=Token{42755b28 ActivityRecord{42485160 u0 com.htc.camera/.CameraEntry t23}}}', dispatchingTimeout=5000.000ms
  FocusedWindow: name='<null>'
...
Windows:
...
PendingEvent:
    KeyEvent(deviceId=-1, source=0x00000101, action=0, flags=0x00000048, keyCode=4, scanCode=0, metaState=0x00000000, repeatCount=0), policyFlags=0x4b000100, age=5025.8ms

InboundQueue: length=5
    MotionEvent(deviceId=2, source=0x00001002, action=2, flags=0x00000000, metaState=0x00000000, buttonState=0x00000000, edgeFlags=0x00000000, xPrecision=1.5, yPrecision=1.5, displayId=0, pointers=[0: (1266.0, 569.5)]), policyFlags=0x42000000, age=5015.0ms
...
    KeyEvent(deviceId=-1, source=0x00000101, action=0, flags=0x000000c8, keyCode=4, scanCode=0, metaState=0x00000000, repeatCount=1), policyFlags=0x4b000100, age=4520.8ms

event not finished
这里写图片描述

// 1st touch: dispatch not finished (waitQueue can’t consume: 2*DispatchM but 1*FinishedM)
02-14 17:29:59.664   969  1058 D InputDispatcher: notifyM-evT=67123340,dev=3,src=0x1002, ac=0x1, downT=67123102
02-14 17:29:59.664   969  1058 D InputDispatcher: id[0]=0,tool=1,x=459,y=1023
02-14 17:29:59.664   969  1057 D InputDispatcher: DispatchM[1]4263bbf0 com.android.development.BadBehaviorActivity (s),evT=67123340,curT=67123341
02-14 17:29:59.664   969  1057 D InputDispatcher: DispatchM[1]WindowManager (s),evT=67123340,curT=67123341
02-14 17:29:59.664   969  1057 D InputDispatcher: FinishedM-evT=67123341
//     - mPendingEvent = NULL


// 2nd touch: 
02-14 17:30:01.576   969  1058 D InputDispatcher: notifyM-evT=67125255,dev=3,src=0x1002, ac=0x0, downT=67125255
02-14 17:30:01.576   969  1058 D InputDispatcher: id[0]=0,tool=1,x=433,y=1042
02-14 17:30:01.576   969  1057 D InputDispatcher: Waiting for application to become ready for input: Window{4263bbf0 u0 com.android.development/com.android.development.BadBehaviorActivity}.  Reason: Waiting because the touched window has not finished processing the input events that were previously delivered to it.
// findFocusedWindowTargetsLocked() -> handleTargetsNotReadyLocked()
//     - waitCause = INPUT_TARGET_WAIT_CAUSE_APPLICATION_NOT_READY;
//     - waitTimeoutTime = 17:30:01.576 + {5sec}
//     - Looper’s nextWakeupTime = 17:30:01.576 + {5sec}
//     - mPendingEvent = 2nd touch


// after 5sec, Looper wakeup
// dispatchOnceInnerLocked() -> handleTargetsNotReadyLocked() -> onANRLocked()
02-14 17:30:06.581   969  1057 I InputDispatcher: Application is not responding: Window{4263bbf0 u0 com.android.development/com.android.development.BadBehaviorActivity}.  It has been 5005.5ms since event, 5005.1ms since wait started.  Reason: Waiting because the touched window has not finished processing the input events that were previously delivered to it.
  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值