Wait for stable window geometry in AnrTest

When AnrTest was switched to uinput, we lost the behaviour of waiting
for animations to complete prior to injection.

Likely, this caused the test to become flaky, because the activity
sometimes is not launched when we try to send input.

In this CL, we are adding a speculative fix for this by waiting for the
window geometry to stabilize before the injection starts.

Bug: 339924248
Test: atest AnrTest
Change-Id: I60ce69ce4ce8afe8b8fa3c9f48ff82c1a1ec9936
diff --git a/tests/Input/Android.bp b/tests/Input/Android.bp
index c0cbdc3..fc0b1f5 100644
--- a/tests/Input/Android.bp
+++ b/tests/Input/Android.bp
@@ -32,6 +32,7 @@
         "androidx.test.uiautomator_uiautomator",
         "compatibility-device-util-axt",
         "cts-input-lib",
+        "cts-wm-util",
         "flag-junit",
         "frameworks-base-testutils",
         "hamcrest-library",
diff --git a/tests/Input/src/com/android/test/input/AnrTest.kt b/tests/Input/src/com/android/test/input/AnrTest.kt
index 6b95f5c..8d3a5ea 100644
--- a/tests/Input/src/com/android/test/input/AnrTest.kt
+++ b/tests/Input/src/com/android/test/input/AnrTest.kt
@@ -29,6 +29,7 @@
 import android.os.SystemClock
 import android.provider.Settings
 import android.provider.Settings.Global.HIDE_ERROR_DIALOGS
+import android.server.wm.CtsWindowInfoUtils.waitForStableWindowGeometry
 import android.testing.PollingCheck
 
 import androidx.test.uiautomator.By
@@ -38,6 +39,8 @@
 
 import com.android.cts.input.UinputTouchScreen
 
+import java.util.concurrent.TimeUnit
+
 import org.junit.After
 import org.junit.Assert.assertEquals
 import org.junit.Assert.assertTrue
@@ -183,5 +186,6 @@
         val flags = " -W -n "
         val startCmd = "am start $flags $PACKAGE_NAME/.UnresponsiveGestureMonitorActivity"
         instrumentation.uiAutomation.executeShellCommand(startCmd)
+        waitForStableWindowGeometry(5L, TimeUnit.SECONDS)
     }
 }