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

Commit eb629d7e authored by Garfield Tan's avatar Garfield Tan
Browse files

Cancel all pending anims when tearing down.

When I was trying to reproduce a TH failure in DisplayContentTests I ran
into a different failure that a SurfaceControl (an anim leash) is used
after being destroyed. Therefore cancel all pending anims before
destroying all SurfaceControls in WMSRule to avoid that.

Bug: None
Test: Tests pass.
Change-Id: Iec978605fa5a8d7dbb0f8afed7cd2e6463454d04
parent a034692c
Loading
Loading
Loading
Loading
+10 −0
Original line number Diff line number Diff line
@@ -164,6 +164,7 @@ public class WindowManagerServiceRule implements TestRule {
            }

            private void tearDown() {
                cancelAllPendingAnimations();
                waitUntilWindowManagerHandlersIdle();
                destroyAllSurfaceTransactions();
                destroyAllSurfaceControls();
@@ -178,6 +179,15 @@ public class WindowManagerServiceRule implements TestRule {
        return mService;
    }

    private void cancelAllPendingAnimations() {
        for (final WeakReference<SurfaceControl> reference : mSurfaceControls) {
            final SurfaceControl sc = reference.get();
            if (sc != null) {
                mService.mSurfaceAnimationRunner.onAnimationCancelled(sc);
            }
        }
    }

    void waitUntilWindowManagerHandlersIdle() {
        final WindowManagerService wm = getWindowManagerService();
        if (wm == null) {