Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit ccd5d507 authored by chaviw's avatar chaviw
Browse files

Wait for window animations to complete before injecting input for test

Some tests add windows that have animations and then inject input. The
inject input may occur before the windows are in their final position so
it causes test failures.
This change ensures that all windows that have pending animations
complete before proceeding to inject inputs for tests.

Bug: 122965081
Bug: 121122996
Bug: 123041491
Test: SearchView_CursorTest#testSuggestionSelection
Test: PopupMenuTest#testDismissalViaTouch
Test: ListPopupWindowTest
Change-Id: I648446be1e14d5101c0f8f97a0f157cde98b5aea
parent aab81fa8
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -1292,6 +1292,7 @@ class WindowContainer<E extends WindowContainer> extends ConfigurationContainer<
     * Called when an animation has finished running.
     */
    protected void onAnimationFinished() {
        mWmService.onAnimationFinished();
    }

    /**
+30 −3
Original line number Diff line number Diff line
@@ -372,6 +372,8 @@ public class WindowManagerService extends IWindowManager.Stub
    private static final int TRANSITION_ANIMATION_SCALE = 1;
    private static final int ANIMATION_DURATION_SCALE = 2;

    private static final int ANIMATION_COMPLETED_TIMEOUT_MS = 5000;

    final WindowTracing mWindowTracing;

    final private KeyguardDisableHandler mKeyguardDisableHandler;
@@ -7424,13 +7426,38 @@ public class WindowManagerService extends IWindowManager.Stub

    @Override
    public boolean injectInputAfterTransactionsApplied(InputEvent ev, int mode) {
        waitForAnimationsToComplete();

        synchronized (mGlobalLock) {
            mWindowPlacerLocked.performSurfacePlacementIfScheduled();
            new SurfaceControl.Transaction()
                    .syncInputWindows()
                    .apply(true);
        }

        new SurfaceControl.Transaction().syncInputWindows().apply(true);

        return mInputManager.injectInputEvent(ev, mode);
    }

    private void waitForAnimationsToComplete() {
        synchronized (mGlobalLock) {
            long timeoutRemaining = ANIMATION_COMPLETED_TIMEOUT_MS;
            while (mRoot.isSelfOrChildAnimating() && timeoutRemaining > 0) {
                long startTime = System.currentTimeMillis();
                try {
                    mGlobalLock.wait(timeoutRemaining);
                } catch (InterruptedException e) {
                }
                timeoutRemaining -= (System.currentTimeMillis() - startTime);
            }

            if (mRoot.isSelfOrChildAnimating()) {
                Log.w(TAG, "Timed out waiting for animations to complete.");
            }
        }
    }

    void onAnimationFinished() {
        synchronized (mGlobalLock) {
            mGlobalLock.notifyAll();
        }
    }
}
+1 −0
Original line number Diff line number Diff line
@@ -4485,6 +4485,7 @@ class WindowState extends WindowContainer<WindowState> implements WindowManagerP

    @Override
    protected void onAnimationFinished() {
        super.onAnimationFinished();
        mWinAnimator.onAnimationFinished();
    }