Android ANR-Keydispatch timeout

Code flow of ANR


  • Code flow of InputSystem

Android ANR-Keydispatch timeout_第1张图片

  • Code flow of dispatch input event
    Android ANR-Keydispatch timeout_第2张图片
    Android ANR-Keydispatch timeout_第3张图片

flow of Scenario


normal flow
Android ANR-Keydispatch timeout_第4张图片

// 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
Android ANR-Keydispatch timeout_第5张图片

@ 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=''
...
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
Android ANR-Keydispatch timeout_第6张图片

// 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.

你可能感兴趣的:(Android)