@@ -302,6 +302,8 @@ std::list<NotifyArgs> TouchInputMapper::reconfigure(nsecs_t when,
302302 ConfigurationChanges changes) {
303303 std::list<NotifyArgs> out = InputMapper::reconfigure (when, config, changes);
304304
305+ std::optional<ui::LogicalDisplayId> previousDisplayId = getAssociatedDisplayId ();
306+
305307 mConfig = config;
306308
307309 // Full configuration should happen the first time configure is called and
@@ -350,6 +352,8 @@ std::list<NotifyArgs> TouchInputMapper::reconfigure(nsecs_t when,
350352 }
351353
352354 if (changes.any () && resetNeeded) {
355+ // Touches should be aborted using the previous display id, so that the stream is consistent
356+ out += abortTouches (when, when, /* policyFlags=*/ 0 , previousDisplayId);
353357 out += reset (when);
354358
355359 // Send reset, unless this is the first time the device has been configured,
@@ -1657,6 +1661,10 @@ bool TouchInputMapper::isTouchScreen() {
16571661 mParameters .hasAssociatedDisplay ;
16581662}
16591663
1664+ ui::LogicalDisplayId TouchInputMapper::resolveDisplayId () const {
1665+ return getAssociatedDisplayId ().value_or (ui::LogicalDisplayId::INVALID);
1666+ };
1667+
16601668void TouchInputMapper::applyExternalStylusButtonState (nsecs_t when) {
16611669 if (mDeviceMode == DeviceMode::DIRECT && hasExternalStylus ()) {
16621670 // If any of the external buttons are already pressed by the touch device, ignore them.
@@ -1928,8 +1936,9 @@ NotifyKeyArgs TouchInputMapper::dispatchVirtualKey(nsecs_t when, nsecs_t readTim
19281936 keyEventFlags, keyCode, scanCode, metaState, downTime);
19291937}
19301938
1931- std::list<NotifyArgs> TouchInputMapper::abortTouches (nsecs_t when, nsecs_t readTime,
1932- uint32_t policyFlags) {
1939+ std::list<NotifyArgs> TouchInputMapper::abortTouches (
1940+ nsecs_t when, nsecs_t readTime, uint32_t policyFlags,
1941+ std::optional<ui::LogicalDisplayId> currentGestureDisplayId) {
19331942 std::list<NotifyArgs> out;
19341943 if (mCurrentMotionAborted ) {
19351944 // Current motion event was already aborted.
@@ -1940,6 +1949,7 @@ std::list<NotifyArgs> TouchInputMapper::abortTouches(nsecs_t when, nsecs_t readT
19401949 int32_t metaState = getContext ()->getGlobalMetaState ();
19411950 int32_t buttonState = mCurrentCookedState .buttonState ;
19421951 out.push_back (dispatchMotion (when, readTime, policyFlags, mSource ,
1952+ currentGestureDisplayId.value_or (resolveDisplayId ()),
19431953 AMOTION_EVENT_ACTION_CANCEL, 0 , AMOTION_EVENT_FLAG_CANCELED,
19441954 metaState, buttonState, AMOTION_EVENT_EDGE_FLAG_NONE,
19451955 mCurrentCookedState .cookedPointerData .pointerProperties ,
@@ -1994,14 +2004,15 @@ std::list<NotifyArgs> TouchInputMapper::dispatchTouches(nsecs_t when, nsecs_t re
19942004 if (!currentIdBits.isEmpty ()) {
19952005 // No pointer id changes so this is a move event.
19962006 // The listener takes care of batching moves so we don't have to deal with that here.
1997- out.push_back (
1998- dispatchMotion (when, readTime, policyFlags, mSource , AMOTION_EVENT_ACTION_MOVE,
1999- 0 , 0 , metaState, buttonState, AMOTION_EVENT_EDGE_FLAG_NONE,
2000- mCurrentCookedState .cookedPointerData .pointerProperties ,
2001- mCurrentCookedState .cookedPointerData .pointerCoords ,
2002- mCurrentCookedState .cookedPointerData .idToIndex , currentIdBits,
2003- -1 , mOrientedXPrecision , mOrientedYPrecision , mDownTime ,
2004- MotionClassification::NONE));
2007+ out.push_back (dispatchMotion (when, readTime, policyFlags, mSource , resolveDisplayId (),
2008+ AMOTION_EVENT_ACTION_MOVE, 0 , 0 , metaState, buttonState,
2009+ AMOTION_EVENT_EDGE_FLAG_NONE,
2010+ mCurrentCookedState .cookedPointerData .pointerProperties ,
2011+ mCurrentCookedState .cookedPointerData .pointerCoords ,
2012+ mCurrentCookedState .cookedPointerData .idToIndex ,
2013+ currentIdBits, -1 , mOrientedXPrecision ,
2014+ mOrientedYPrecision , mDownTime ,
2015+ MotionClassification::NONE));
20052016 }
20062017 } else {
20072018 // There may be pointers going up and pointers going down and pointers moving
@@ -2031,7 +2042,7 @@ std::list<NotifyArgs> TouchInputMapper::dispatchTouches(nsecs_t when, nsecs_t re
20312042 if (isCanceled) {
20322043 ALOGI (" Canceling pointer %d for the palm event was detected." , upId);
20332044 }
2034- out.push_back (dispatchMotion (when, readTime, policyFlags, mSource ,
2045+ out.push_back (dispatchMotion (when, readTime, policyFlags, mSource , resolveDisplayId (),
20352046 AMOTION_EVENT_ACTION_POINTER_UP, 0 ,
20362047 isCanceled ? AMOTION_EVENT_FLAG_CANCELED : 0 , metaState,
20372048 buttonState, 0 ,
@@ -2050,7 +2061,7 @@ std::list<NotifyArgs> TouchInputMapper::dispatchTouches(nsecs_t when, nsecs_t re
20502061 // events, they do not generally handle them except when presented in a move event.
20512062 if (moveNeeded && !moveIdBits.isEmpty ()) {
20522063 ALOG_ASSERT (moveIdBits.value == dispatchedIdBits.value );
2053- out.push_back (dispatchMotion (when, readTime, policyFlags, mSource ,
2064+ out.push_back (dispatchMotion (when, readTime, policyFlags, mSource , resolveDisplayId (),
20542065 AMOTION_EVENT_ACTION_MOVE, 0 , 0 , metaState, buttonState, 0 ,
20552066 mCurrentCookedState .cookedPointerData .pointerProperties ,
20562067 mCurrentCookedState .cookedPointerData .pointerCoords ,
@@ -2071,7 +2082,7 @@ std::list<NotifyArgs> TouchInputMapper::dispatchTouches(nsecs_t when, nsecs_t re
20712082 }
20722083
20732084 out.push_back (
2074- dispatchMotion (when, readTime, policyFlags, mSource ,
2085+ dispatchMotion (when, readTime, policyFlags, mSource , resolveDisplayId (),
20752086 AMOTION_EVENT_ACTION_POINTER_DOWN, 0 , 0 , metaState, buttonState,
20762087 0 , mCurrentCookedState .cookedPointerData .pointerProperties ,
20772088 mCurrentCookedState .cookedPointerData .pointerCoords ,
@@ -2090,7 +2101,7 @@ std::list<NotifyArgs> TouchInputMapper::dispatchHoverExit(nsecs_t when, nsecs_t
20902101 (mCurrentCookedState .cookedPointerData .hoveringIdBits .isEmpty () ||
20912102 !mCurrentCookedState .cookedPointerData .touchingIdBits .isEmpty ())) {
20922103 int32_t metaState = getContext ()->getGlobalMetaState ();
2093- out.push_back (dispatchMotion (when, readTime, policyFlags, mSource ,
2104+ out.push_back (dispatchMotion (when, readTime, policyFlags, mSource , resolveDisplayId (),
20942105 AMOTION_EVENT_ACTION_HOVER_EXIT, 0 , 0 , metaState,
20952106 mLastCookedState .buttonState , 0 ,
20962107 mLastCookedState .cookedPointerData .pointerProperties ,
@@ -2111,7 +2122,7 @@ std::list<NotifyArgs> TouchInputMapper::dispatchHoverEnterAndMove(nsecs_t when,
21112122 !mCurrentCookedState .cookedPointerData .hoveringIdBits .isEmpty ()) {
21122123 int32_t metaState = getContext ()->getGlobalMetaState ();
21132124 if (!mSentHoverEnter ) {
2114- out.push_back (dispatchMotion (when, readTime, policyFlags, mSource ,
2125+ out.push_back (dispatchMotion (when, readTime, policyFlags, mSource , resolveDisplayId (),
21152126 AMOTION_EVENT_ACTION_HOVER_ENTER, 0 , 0 , metaState,
21162127 mCurrentRawState .buttonState , 0 ,
21172128 mCurrentCookedState .cookedPointerData .pointerProperties ,
@@ -2123,7 +2134,7 @@ std::list<NotifyArgs> TouchInputMapper::dispatchHoverEnterAndMove(nsecs_t when,
21232134 mSentHoverEnter = true ;
21242135 }
21252136
2126- out.push_back (dispatchMotion (when, readTime, policyFlags, mSource ,
2137+ out.push_back (dispatchMotion (when, readTime, policyFlags, mSource , resolveDisplayId (),
21272138 AMOTION_EVENT_ACTION_HOVER_MOVE, 0 , 0 , metaState,
21282139 mCurrentRawState .buttonState , 0 ,
21292140 mCurrentCookedState .cookedPointerData .pointerProperties ,
@@ -2146,7 +2157,7 @@ std::list<NotifyArgs> TouchInputMapper::dispatchButtonRelease(nsecs_t when, nsec
21462157 while (!releasedButtons.isEmpty ()) {
21472158 int32_t actionButton = BitSet32::valueForBit (releasedButtons.clearFirstMarkedBit ());
21482159 buttonState &= ~actionButton;
2149- out.push_back (dispatchMotion (when, readTime, policyFlags, mSource ,
2160+ out.push_back (dispatchMotion (when, readTime, policyFlags, mSource , resolveDisplayId (),
21502161 AMOTION_EVENT_ACTION_BUTTON_RELEASE, actionButton, 0 ,
21512162 metaState, buttonState, 0 ,
21522163 mLastCookedState .cookedPointerData .pointerProperties ,
@@ -2168,7 +2179,7 @@ std::list<NotifyArgs> TouchInputMapper::dispatchButtonPress(nsecs_t when, nsecs_
21682179 while (!pressedButtons.isEmpty ()) {
21692180 int32_t actionButton = BitSet32::valueForBit (pressedButtons.clearFirstMarkedBit ());
21702181 buttonState |= actionButton;
2171- out.push_back (dispatchMotion (when, readTime, policyFlags, mSource ,
2182+ out.push_back (dispatchMotion (when, readTime, policyFlags, mSource , resolveDisplayId (),
21722183 AMOTION_EVENT_ACTION_BUTTON_PRESS, actionButton, 0 , metaState,
21732184 buttonState, 0 ,
21742185 mCurrentCookedState .cookedPointerData .pointerProperties ,
@@ -2192,7 +2203,7 @@ std::list<NotifyArgs> TouchInputMapper::dispatchGestureButtonRelease(nsecs_t whe
21922203 while (!releasedButtons.isEmpty ()) {
21932204 int32_t actionButton = BitSet32::valueForBit (releasedButtons.clearFirstMarkedBit ());
21942205 buttonState &= ~actionButton;
2195- out.push_back (dispatchMotion (when, readTime, policyFlags, mSource ,
2206+ out.push_back (dispatchMotion (when, readTime, policyFlags, mSource , resolveDisplayId (),
21962207 AMOTION_EVENT_ACTION_BUTTON_RELEASE, actionButton, 0 ,
21972208 metaState, buttonState, 0 ,
21982209 mPointerGesture .lastGestureProperties ,
@@ -2216,7 +2227,7 @@ std::list<NotifyArgs> TouchInputMapper::dispatchGestureButtonPress(nsecs_t when,
22162227 while (!pressedButtons.isEmpty ()) {
22172228 int32_t actionButton = BitSet32::valueForBit (pressedButtons.clearFirstMarkedBit ());
22182229 buttonState |= actionButton;
2219- out.push_back (dispatchMotion (when, readTime, policyFlags, mSource ,
2230+ out.push_back (dispatchMotion (when, readTime, policyFlags, mSource , resolveDisplayId (),
22202231 AMOTION_EVENT_ACTION_BUTTON_PRESS, actionButton, 0 , metaState,
22212232 buttonState, 0 , mPointerGesture .currentGestureProperties ,
22222233 mPointerGesture .currentGestureCoords ,
@@ -2564,7 +2575,7 @@ std::list<NotifyArgs> TouchInputMapper::dispatchPointerGestures(nsecs_t when, ns
25642575 if (!dispatchedGestureIdBits.isEmpty ()) {
25652576 if (cancelPreviousGesture) {
25662577 const uint32_t cancelFlags = flags | AMOTION_EVENT_FLAG_CANCELED;
2567- out.push_back (dispatchMotion (when, readTime, policyFlags, mSource ,
2578+ out.push_back (dispatchMotion (when, readTime, policyFlags, mSource , resolveDisplayId (),
25682579 AMOTION_EVENT_ACTION_CANCEL, 0 , cancelFlags, metaState,
25692580 buttonState, AMOTION_EVENT_EDGE_FLAG_NONE,
25702581 mPointerGesture .lastGestureProperties ,
@@ -2591,8 +2602,9 @@ std::list<NotifyArgs> TouchInputMapper::dispatchPointerGestures(nsecs_t when, ns
25912602 }
25922603 const uint32_t id = upGestureIdBits.clearFirstMarkedBit ();
25932604 out.push_back (dispatchMotion (when, readTime, policyFlags, mSource ,
2594- AMOTION_EVENT_ACTION_POINTER_UP, 0 , flags, metaState,
2595- buttonState, AMOTION_EVENT_EDGE_FLAG_NONE,
2605+ resolveDisplayId (), AMOTION_EVENT_ACTION_POINTER_UP, 0 ,
2606+ flags, metaState, buttonState,
2607+ AMOTION_EVENT_EDGE_FLAG_NONE,
25962608 mPointerGesture .lastGestureProperties ,
25972609 mPointerGesture .lastGestureCoords ,
25982610 mPointerGesture .lastGestureIdToIndex ,
@@ -2606,13 +2618,14 @@ std::list<NotifyArgs> TouchInputMapper::dispatchPointerGestures(nsecs_t when, ns
26062618
26072619 // Send motion events for all pointers that moved.
26082620 if (moveNeeded) {
2609- out.push_back (
2610- dispatchMotion (when, readTime, policyFlags, mSource , AMOTION_EVENT_ACTION_MOVE, 0 ,
2611- flags, metaState, buttonState, AMOTION_EVENT_EDGE_FLAG_NONE,
2612- mPointerGesture .currentGestureProperties ,
2613- mPointerGesture .currentGestureCoords ,
2614- mPointerGesture .currentGestureIdToIndex , dispatchedGestureIdBits, -1 ,
2615- 0 , 0 , mPointerGesture .downTime , classification));
2621+ out.push_back (dispatchMotion (when, readTime, policyFlags, mSource , resolveDisplayId (),
2622+ AMOTION_EVENT_ACTION_MOVE, 0 , flags, metaState, buttonState,
2623+ AMOTION_EVENT_EDGE_FLAG_NONE,
2624+ mPointerGesture .currentGestureProperties ,
2625+ mPointerGesture .currentGestureCoords ,
2626+ mPointerGesture .currentGestureIdToIndex ,
2627+ dispatchedGestureIdBits, -1 , 0 , 0 , mPointerGesture .downTime ,
2628+ classification));
26162629 }
26172630
26182631 // Send motion events for all pointers that went down.
@@ -2627,7 +2640,7 @@ std::list<NotifyArgs> TouchInputMapper::dispatchPointerGestures(nsecs_t when, ns
26272640 mPointerGesture .downTime = when;
26282641 }
26292642
2630- out.push_back (dispatchMotion (when, readTime, policyFlags, mSource ,
2643+ out.push_back (dispatchMotion (when, readTime, policyFlags, mSource , resolveDisplayId (),
26312644 AMOTION_EVENT_ACTION_POINTER_DOWN, 0 , flags, metaState,
26322645 buttonState, 0 , mPointerGesture .currentGestureProperties ,
26332646 mPointerGesture .currentGestureCoords ,
@@ -2645,7 +2658,7 @@ std::list<NotifyArgs> TouchInputMapper::dispatchPointerGestures(nsecs_t when, ns
26452658
26462659 // Send motion events for hover.
26472660 if (mPointerGesture .currentGestureMode == PointerGesture::Mode::HOVER) {
2648- out.push_back (dispatchMotion (when, readTime, policyFlags, mSource ,
2661+ out.push_back (dispatchMotion (when, readTime, policyFlags, mSource , resolveDisplayId (),
26492662 AMOTION_EVENT_ACTION_HOVER_MOVE, 0 , flags, metaState,
26502663 buttonState, AMOTION_EVENT_EDGE_FLAG_NONE,
26512664 mPointerGesture .currentGestureProperties ,
@@ -2704,7 +2717,7 @@ std::list<NotifyArgs> TouchInputMapper::abortPointerGestures(nsecs_t when, nsecs
27042717 if (!mPointerGesture .lastGestureIdBits .isEmpty ()) {
27052718 int32_t metaState = getContext ()->getGlobalMetaState ();
27062719 int32_t buttonState = mCurrentRawState .buttonState ;
2707- out.push_back (dispatchMotion (when, readTime, policyFlags, mSource ,
2720+ out.push_back (dispatchMotion (when, readTime, policyFlags, mSource , resolveDisplayId (),
27082721 AMOTION_EVENT_ACTION_CANCEL, 0 , AMOTION_EVENT_FLAG_CANCELED,
27092722 metaState, buttonState, AMOTION_EVENT_EDGE_FLAG_NONE,
27102723 mPointerGesture .lastGestureProperties ,
@@ -3498,8 +3511,7 @@ std::list<NotifyArgs> TouchInputMapper::dispatchPointerMouse(nsecs_t when, nsecs
34983511 hovering = false ;
34993512 }
35003513
3501- return dispatchPointerSimple (when, readTime, policyFlags, down, hovering,
3502- getAssociatedDisplayId ().value_or (ui::LogicalDisplayId::INVALID));
3514+ return dispatchPointerSimple (when, readTime, policyFlags, down, hovering, resolveDisplayId ());
35033515}
35043516
35053517std::list<NotifyArgs> TouchInputMapper::abortPointerMouse (nsecs_t when, nsecs_t readTime,
@@ -3662,9 +3674,10 @@ std::list<NotifyArgs> TouchInputMapper::abortPointerSimple(nsecs_t when, nsecs_t
36623674}
36633675
36643676NotifyMotionArgs TouchInputMapper::dispatchMotion (
3665- nsecs_t when, nsecs_t readTime, uint32_t policyFlags, uint32_t source, int32_t action,
3666- int32_t actionButton, int32_t flags, int32_t metaState, int32_t buttonState,
3667- int32_t edgeFlags, const PropertiesArray& properties, const CoordsArray& coords,
3677+ nsecs_t when, nsecs_t readTime, uint32_t policyFlags, uint32_t source,
3678+ ui::LogicalDisplayId displayId, int32_t action, int32_t actionButton, int32_t flags,
3679+ int32_t metaState, int32_t buttonState, int32_t edgeFlags,
3680+ const PropertiesArray& properties, const CoordsArray& coords,
36683681 const IdToIndexArray& idToIndex, BitSet32 idBits, int32_t changedId, float xPrecision,
36693682 float yPrecision, nsecs_t downTime, MotionClassification classification) const {
36703683 std::vector<PointerCoords> pointerCoords;
@@ -3714,9 +3727,6 @@ NotifyMotionArgs TouchInputMapper::dispatchMotion(
37143727 }
37153728 }
37163729
3717- const ui::LogicalDisplayId displayId =
3718- getAssociatedDisplayId ().value_or (ui::LogicalDisplayId::INVALID);
3719-
37203730 float xCursorPosition = AMOTION_EVENT_INVALID_CURSOR_POSITION;
37213731 float yCursorPosition = AMOTION_EVENT_INVALID_CURSOR_POSITION;
37223732 if (mDeviceMode == DeviceMode::POINTER) {
@@ -3739,7 +3749,7 @@ NotifyMotionArgs TouchInputMapper::dispatchMotion(
37393749std::list<NotifyArgs> TouchInputMapper::cancelTouch (nsecs_t when, nsecs_t readTime) {
37403750 std::list<NotifyArgs> out;
37413751 out += abortPointerUsage (when, readTime, /* policyFlags=*/ 0 );
3742- out += abortTouches (when, readTime, /* policyFlags=*/ 0 );
3752+ out += abortTouches (when, readTime, /* policyFlags=*/ 0 , std:: nullopt );
37433753 return out;
37443754}
37453755
0 commit comments