@@ -1390,28 +1390,35 @@ int32_t InputDispatcher::findTouchedWindowTargetsLocked(nsecs_t currentTime,
13901390 // New window supports splitting.
13911391 isSplit = true ;
13921392 } else if (isSplit) {
1393- // New window does not support splitting but we have already split events.
1394- // Assign the pointer to the first foreground window we find.
1395- // (May be NULL which is why we put this code block before the next check.)
1396- newTouchedWindowHandle = mTempTouchState .getFirstForegroundWindowHandle ();
1393+ // Ignore the new window.
1394+ newTouchedWindowHandle = NULL ;
13971395 }
13981396
1399- // If we did not find a touched window then fail .
1397+ // Handle the case where we did not find a window.
14001398 if (newTouchedWindowHandle == NULL ) {
1401- if (mFocusedApplicationHandle != NULL ) {
1399+ // Try to assign the pointer to the first foreground window we find, if there is one.
1400+ newTouchedWindowHandle = mTempTouchState .getFirstForegroundWindowHandle ();
1401+ if (newTouchedWindowHandle == NULL ) {
1402+ // There is no touched window. If this is an initial down event
1403+ // then wait for a window to appear that will handle the touch. This is
1404+ // to ensure that we report an ANR in the case where an application has started
1405+ // but not yet put up a window and the user is starting to get impatient.
1406+ if (maskedAction == AMOTION_EVENT_ACTION_DOWN
1407+ && mFocusedApplicationHandle != NULL ) {
14021408#if DEBUG_FOCUS
1403- ALOGD (" Waiting because there is no touched window but there is a "
1404- " focused application that may eventually add a new window: %s." ,
1405- getApplicationWindowLabelLocked (mFocusedApplicationHandle , NULL ).string ());
1409+ ALOGD (" Waiting because there is no touched window but there is a "
1410+ " focused application that may eventually add a new window: %s." ,
1411+ getApplicationWindowLabelLocked (
1412+ mFocusedApplicationHandle , NULL ).string ());
14061413#endif
1407- injectionResult = handleTargetsNotReadyLocked (currentTime, entry,
1408- mFocusedApplicationHandle , NULL , nextWakeupTime);
1409- goto Unresponsive;
1414+ injectionResult = handleTargetsNotReadyLocked (currentTime, entry,
1415+ mFocusedApplicationHandle , NULL , nextWakeupTime);
1416+ goto Unresponsive;
1417+ }
1418+ ALOGI (" Dropping event because there is no touched window." );
1419+ injectionResult = INPUT_EVENT_INJECTION_FAILED;
1420+ goto Failed;
14101421 }
1411-
1412- ALOGI (" Dropping event because there is no touched window or focused application." );
1413- injectionResult = INPUT_EVENT_INJECTION_FAILED;
1414- goto Failed;
14151422 }
14161423
14171424 // Set target flags.
0 commit comments