Fixed errors after updated ag/29186008

After ag/29186008 the last event in the PointerInput API can contain
multiple pointers, but always and only one pointer with id
== velocityPointerId.
Completed the swipe gesture in
multiPointerWaitAConsumableEventInMainPass to avoid possible errors.

Test: atest ElementTest
Test: atest MultiPointerDraggableTest
Bug: 365564010
Flag: com.android.systemui.scene_container
Change-Id: I69beecd0ae7c0b993da4812a663ae95077dff749
diff --git a/packages/SystemUI/compose/scene/src/com/android/compose/animation/scene/MultiPointerDraggable.kt b/packages/SystemUI/compose/scene/src/com/android/compose/animation/scene/MultiPointerDraggable.kt
index b99b7f9..fb9dde3 100644
--- a/packages/SystemUI/compose/scene/src/com/android/compose/animation/scene/MultiPointerDraggable.kt
+++ b/packages/SystemUI/compose/scene/src/com/android/compose/animation/scene/MultiPointerDraggable.kt
@@ -234,8 +234,8 @@
                     pointersDown == 0 -> {
                         startedPosition = null
 
-                        // This is the last pointer up
-                        velocityTracker.addPointerInputChange(changes.single())
+                        val lastPointerUp = changes.single { it.id == velocityPointerId }
+                        velocityTracker.addPointerInputChange(lastPointerUp)
                     }
 
                     // The first pointer down, startedPosition was not set.
@@ -271,7 +271,12 @@
 
                         // If the previous pointer has been removed, we use the first available
                         // change to keep tracking the velocity.
-                        velocityPointerId = pointerChange.id
+                        velocityPointerId =
+                            if (pointerChange.pressed) {
+                                pointerChange.id
+                            } else {
+                                changes.first { it.pressed }.id
+                            }
 
                         velocityTracker.addPointerInputChange(pointerChange)
                     }
diff --git a/packages/SystemUI/compose/scene/tests/src/com/android/compose/animation/scene/MultiPointerDraggableTest.kt b/packages/SystemUI/compose/scene/tests/src/com/android/compose/animation/scene/MultiPointerDraggableTest.kt
index 942cb23..af717ac 100644
--- a/packages/SystemUI/compose/scene/tests/src/com/android/compose/animation/scene/MultiPointerDraggableTest.kt
+++ b/packages/SystemUI/compose/scene/tests/src/com/android/compose/animation/scene/MultiPointerDraggableTest.kt
@@ -438,6 +438,9 @@
 
         continueDraggingDown()
         assertThat(stopped).isTrue()
+
+        // Complete the gesture
+        rule.onRoot().performTouchInput { up() }
     }
 
     @Test