Merge "Attempt to fix testShowImeCold flake"
diff --git a/apct-tests/perftests/inputmethod/src/android/inputmethod/ImePerfTest.java b/apct-tests/perftests/inputmethod/src/android/inputmethod/ImePerfTest.java
index 203bb54..2e44d82 100644
--- a/apct-tests/perftests/inputmethod/src/android/inputmethod/ImePerfTest.java
+++ b/apct-tests/perftests/inputmethod/src/android/inputmethod/ImePerfTest.java
@@ -245,7 +245,9 @@
         }
 
         long measuredTimeNs = 0;
-        while (state.keepRunning(measuredTimeNs)) {
+        boolean shouldRetry = false;
+        while (shouldRetry || state.keepRunning(measuredTimeNs)) {
+            shouldRetry = false;
             killBaselineIme();
             try (ImeSession imeSession = new ImeSession(BaselineIme.getName(
                     getInstrumentation().getContext()))) {
@@ -268,6 +270,14 @@
                 });
 
                 measuredTimeNs = waitForAnimationStart(latchStart, startTime);
+
+                if (measuredTimeNs == ANIMATION_NOT_STARTED) {
+                    // Animation didn't start within timeout,
+                    // retry for more samples.
+                    // TODO(b/264722663): Investigate the animation start failure reason.
+                    shouldRetry = true;
+                    Log.w(TAG, "Insets animation didn't start within timeout.");
+                }
                 mActivityRule.finishActivity();
             }
         }