Merge "Make ImePerfTest wait for animation end" into sc-dev am: 28a77d5846 am: 8c6398c72d

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/15161272

Change-Id: I20dfb12a3c6b7f41e1c025e22c67dac0c3c0c719
This commit is contained in:
TreeHugger Robot
2021-07-16 06:12:21 +00:00
committed by Automerger Merge Worker

View File

@@ -306,10 +306,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)) {
@@ -318,9 +317,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()) {
@@ -330,6 +330,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());
@@ -348,11 +349,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);
@@ -374,6 +379,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(
@@ -383,7 +394,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;
}
@@ -392,6 +403,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) {