Merge "Make ImePerfTest wait for animation end" into sc-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
28a77d5846
@@ -304,10 +304,9 @@ public class ImePerfTest extends ImePerfTestBase
|
|||||||
|
|
||||||
while (state.keepRunning(measuredTimeNs)) {
|
while (state.keepRunning(measuredTimeNs)) {
|
||||||
setImeListener(activity, latchStart, latchEnd);
|
setImeListener(activity, latchStart, latchEnd);
|
||||||
latchStart.set(new CountDownLatch(show ? 1 : 2));
|
|
||||||
latchEnd.set(new CountDownLatch(2));
|
|
||||||
// For measuring hide, lets show IME first.
|
// For measuring hide, lets show IME first.
|
||||||
if (!show) {
|
if (!show) {
|
||||||
|
initLatch(latchStart, latchEnd);
|
||||||
AtomicBoolean showCalled = new AtomicBoolean();
|
AtomicBoolean showCalled = new AtomicBoolean();
|
||||||
getInstrumentation().runOnMainSync(() -> {
|
getInstrumentation().runOnMainSync(() -> {
|
||||||
if (!isImeVisible(activity)) {
|
if (!isImeVisible(activity)) {
|
||||||
@@ -316,9 +315,10 @@ public class ImePerfTest extends ImePerfTestBase
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
if (showCalled.get()) {
|
if (showCalled.get()) {
|
||||||
PollingCheck.check("IME show animation should finish ", TIMEOUT_1_S_IN_MS,
|
PollingCheck.check("IME show animation should finish ",
|
||||||
() -> latchStart.get().getCount() == 1
|
TIMEOUT_1_S_IN_MS * 3,
|
||||||
&& latchEnd.get().getCount() == 1);
|
() -> latchStart.get().getCount() == 0
|
||||||
|
&& latchEnd.get().getCount() == 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!mIsTraceStarted && !state.isWarmingUp()) {
|
if (!mIsTraceStarted && !state.isWarmingUp()) {
|
||||||
@@ -328,6 +328,7 @@ public class ImePerfTest extends ImePerfTestBase
|
|||||||
|
|
||||||
AtomicLong startTime = new AtomicLong();
|
AtomicLong startTime = new AtomicLong();
|
||||||
AtomicBoolean unexpectedVisibility = new AtomicBoolean();
|
AtomicBoolean unexpectedVisibility = new AtomicBoolean();
|
||||||
|
initLatch(latchStart, latchEnd);
|
||||||
getInstrumentation().runOnMainSync(() -> {
|
getInstrumentation().runOnMainSync(() -> {
|
||||||
boolean isVisible = isImeVisible(activity);
|
boolean isVisible = isImeVisible(activity);
|
||||||
startTime.set(SystemClock.elapsedRealtimeNanos());
|
startTime.set(SystemClock.elapsedRealtimeNanos());
|
||||||
@@ -346,11 +347,15 @@ public class ImePerfTest extends ImePerfTestBase
|
|||||||
long timeElapsed = waitForAnimationStart(latchStart, startTime);
|
long timeElapsed = waitForAnimationStart(latchStart, startTime);
|
||||||
if (timeElapsed != ANIMATION_NOT_STARTED) {
|
if (timeElapsed != ANIMATION_NOT_STARTED) {
|
||||||
measuredTimeNs = timeElapsed;
|
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.
|
// hide IME before next iteration.
|
||||||
if (show) {
|
if (show) {
|
||||||
|
initLatch(latchStart, latchEnd);
|
||||||
activity.runOnUiThread(() -> controller.hide(WindowInsets.Type.ime()));
|
activity.runOnUiThread(() -> controller.hide(WindowInsets.Type.ime()));
|
||||||
try {
|
try {
|
||||||
latchEnd.get().await(TIMEOUT_1_S_IN_MS * 5, TimeUnit.MILLISECONDS);
|
latchEnd.get().await(TIMEOUT_1_S_IN_MS * 5, TimeUnit.MILLISECONDS);
|
||||||
@@ -372,6 +377,12 @@ public class ImePerfTest extends ImePerfTestBase
|
|||||||
addResultToState(state);
|
addResultToState(state);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void initLatch(AtomicReference<CountDownLatch> latchStart,
|
||||||
|
AtomicReference<CountDownLatch> latchEnd) {
|
||||||
|
latchStart.set(new CountDownLatch(1));
|
||||||
|
latchEnd.set(new CountDownLatch(1));
|
||||||
|
}
|
||||||
|
|
||||||
@UiThread
|
@UiThread
|
||||||
private boolean isImeVisible(@NonNull final Activity activity) {
|
private boolean isImeVisible(@NonNull final Activity activity) {
|
||||||
return activity.getWindow().getDecorView().getRootWindowInsets().isVisible(
|
return activity.getWindow().getDecorView().getRootWindowInsets().isVisible(
|
||||||
@@ -381,7 +392,7 @@ public class ImePerfTest extends ImePerfTestBase
|
|||||||
private long waitForAnimationStart(
|
private long waitForAnimationStart(
|
||||||
AtomicReference<CountDownLatch> latchStart, AtomicLong startTime) {
|
AtomicReference<CountDownLatch> latchStart, AtomicLong startTime) {
|
||||||
try {
|
try {
|
||||||
latchStart.get().await(TIMEOUT_1_S_IN_MS * 5, TimeUnit.MILLISECONDS);
|
latchStart.get().await(5, TimeUnit.SECONDS);
|
||||||
if (latchStart.get().getCount() != 0) {
|
if (latchStart.get().getCount() != 0) {
|
||||||
return ANIMATION_NOT_STARTED;
|
return ANIMATION_NOT_STARTED;
|
||||||
}
|
}
|
||||||
@@ -390,6 +401,12 @@ public class ImePerfTest extends ImePerfTestBase
|
|||||||
return SystemClock.elapsedRealtimeNanos() - startTime.get();
|
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) {
|
private void addResultToState(ManualBenchmarkState state) {
|
||||||
mTraceMethods.forAllSlices((key, slices) -> {
|
mTraceMethods.forAllSlices((key, slices) -> {
|
||||||
for (TraceMarkSlice slice : slices) {
|
for (TraceMarkSlice slice : slices) {
|
||||||
|
|||||||
Reference in New Issue
Block a user