diff options
author | Taran Singh <tarandeep@google.com> | 2021-06-30 20:27:32 +0000 |
---|---|---|
committer | Taran Singh <tarandeep@google.com> | 2021-07-07 19:09:56 +0000 |
commit | dec9f8a79cda07eafaa66c207998adb69f416de9 (patch) | |
tree | 445b6e83439a3568e2892922b84c1640846dd3e8 | |
parent | 47d33c2c95ab5e28a6ffe6c22d6af02438701a05 (diff) |
Make ImePerfTest wait for animation end
In show/hide ImePerfTests we waited for animationStart, however, it also
makes sense to wait for animation end to prevent overlapping and
avoiding reporting incorrect stats.
Fix: 191915803
Test: atest ImePerfTests
Change-Id: I7ef40db249afecc64b6a2418ff1ed7f90ccb4515
-rw-r--r-- | apct-tests/perftests/inputmethod/src/android/inputmethod/ImePerfTest.java | 29 |
1 files changed, 23 insertions, 6 deletions
diff --git a/apct-tests/perftests/inputmethod/src/android/inputmethod/ImePerfTest.java b/apct-tests/perftests/inputmethod/src/android/inputmethod/ImePerfTest.java index 21c4491fc371..ab3c50b209e6 100644 --- a/apct-tests/perftests/inputmethod/src/android/inputmethod/ImePerfTest.java +++ b/apct-tests/perftests/inputmethod/src/android/inputmethod/ImePerfTest.java @@ -304,10 +304,9 @@ public class ImePerfTest extends ImePerfTestBase while (state.keepRunning(measuredTimeNs)) { setImeListener(activity, latchStart, latchEnd); - latchStart.set(new CountDownLatch(show ? 1 : 2)); - latchEnd.set(new CountDownLatch(2)); // For measuring hide, lets show IME first. if (!show) { + initLatch(latchStart, latchEnd); AtomicBoolean showCalled = new AtomicBoolean(); getInstrumentation().runOnMainSync(() -> { if (!isImeVisible(activity)) { @@ -316,9 +315,10 @@ public class ImePerfTest extends ImePerfTestBase } }); if (showCalled.get()) { - PollingCheck.check("IME show animation should finish ", TIMEOUT_1_S_IN_MS, - () -> latchStart.get().getCount() == 1 - && latchEnd.get().getCount() == 1); + PollingCheck.check("IME show animation should finish ", + TIMEOUT_1_S_IN_MS * 3, + () -> latchStart.get().getCount() == 0 + && latchEnd.get().getCount() == 0); } } if (!mIsTraceStarted && !state.isWarmingUp()) { @@ -328,6 +328,7 @@ public class ImePerfTest extends ImePerfTestBase AtomicLong startTime = new AtomicLong(); AtomicBoolean unexpectedVisibility = new AtomicBoolean(); + initLatch(latchStart, latchEnd); getInstrumentation().runOnMainSync(() -> { boolean isVisible = isImeVisible(activity); startTime.set(SystemClock.elapsedRealtimeNanos()); @@ -346,11 +347,15 @@ public class ImePerfTest extends ImePerfTestBase long timeElapsed = waitForAnimationStart(latchStart, startTime); if (timeElapsed != ANIMATION_NOT_STARTED) { measuredTimeNs = timeElapsed; + // wait for animation to end or we may start two animations and timing + // will not be measured accurately. + waitForAnimationEnd(latchEnd); } } // hide IME before next iteration. if (show) { + initLatch(latchStart, latchEnd); activity.runOnUiThread(() -> controller.hide(WindowInsets.Type.ime())); try { latchEnd.get().await(TIMEOUT_1_S_IN_MS * 5, TimeUnit.MILLISECONDS); @@ -372,6 +377,12 @@ public class ImePerfTest extends ImePerfTestBase addResultToState(state); } + private void initLatch(AtomicReference<CountDownLatch> latchStart, + AtomicReference<CountDownLatch> latchEnd) { + latchStart.set(new CountDownLatch(1)); + latchEnd.set(new CountDownLatch(1)); + } + @UiThread private boolean isImeVisible(@NonNull final Activity activity) { return activity.getWindow().getDecorView().getRootWindowInsets().isVisible( @@ -381,7 +392,7 @@ public class ImePerfTest extends ImePerfTestBase private long waitForAnimationStart( AtomicReference<CountDownLatch> latchStart, AtomicLong startTime) { try { - latchStart.get().await(TIMEOUT_1_S_IN_MS * 5, TimeUnit.MILLISECONDS); + latchStart.get().await(5, TimeUnit.SECONDS); if (latchStart.get().getCount() != 0) { return ANIMATION_NOT_STARTED; } @@ -390,6 +401,12 @@ public class ImePerfTest extends ImePerfTestBase return SystemClock.elapsedRealtimeNanos() - startTime.get(); } + private void waitForAnimationEnd(AtomicReference<CountDownLatch> latchEnd) { + try { + latchEnd.get().await(3, TimeUnit.SECONDS); + } catch (InterruptedException e) { } + } + private void addResultToState(ManualBenchmarkState state) { mTraceMethods.forAllSlices((key, slices) -> { for (TraceMarkSlice slice : slices) { |