InputAtomsTest: Return touchpad swipes to the starting location

When interacting with the emulated touchpad, multi-finger swipes can
have unintended side effects, like expanding the notification shade,
which can alter the state of the system.

To combat this, return the swiping fingers to the starting location when
performing a multi-finger swipe, which should mitigate these side
effects.

Bug: 355035531
Test: atest CtsInputHostTestCases
Flag: TEST_ONLY
Change-Id: I1e80e73d666142dbce49cbdf1b3a3d0fd3fe6d9e
diff --git a/hostsidetests/input/app/src/android/input/cts/hostside/app/EmulateInputDevice.kt b/hostsidetests/input/app/src/android/input/cts/hostside/app/EmulateInputDevice.kt
index 89e45d7..4bcfffe 100644
--- a/hostsidetests/input/app/src/android/input/cts/hostside/app/EmulateInputDevice.kt
+++ b/hostsidetests/input/app/src/android/input/cts/hostside/app/EmulateInputDevice.kt
@@ -31,6 +31,7 @@
 import com.android.cts.input.UinputTouchScreen
 import com.android.cts.input.inputeventmatchers.withMotionAction
 import org.junit.After
+import org.junit.Assert.assertTrue
 import org.junit.Before
 import org.junit.Rule
 import org.junit.Test
@@ -57,7 +58,10 @@
         val dm = DisplayMetrics().also { activity.display.getRealMetrics(it) }
         screenSize = Size(dm.widthPixels, dm.heightPixels)
         verifier = EventVerifier(activity::getInputEvent)
-        waitForWindowOnTop(activity.window)
+        assertTrue(
+            "Failed to wait for activity window to be on top",
+            waitForWindowOnTop(activity.window)
+        )
     }
 
     @After
@@ -188,6 +192,8 @@
         multiFingerSwipe(4)
     }
 
+    // Perform a multi-finger swipe in one direction and return to the starting location to
+    // minimize the size effects of the gesture to the rest of the system.
     private fun multiFingerSwipe(numFingers: Int) {
         UinputTouchPad(instrumentation, activity.display).use { touchpad ->
             val pointers = Array(numFingers) { i -> Point(500 + i * 200, 500) }
@@ -199,9 +205,10 @@
             touchpad.sync()
             Thread.sleep(TOUCHPAD_SCAN_DELAY_MILLIS)
 
-            for (rep in 0 until 10) {
+            for (rep in 0 until 20) {
+                val direction = if (rep < 10) 1 else -1
                 for (i in pointers.indices) {
-                    pointers[i].offset(0, 40)
+                    pointers[i].offset(0, direction * 40)
                     touchpad.sendMove(i, pointers[i])
                 }
                 touchpad.sync()