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

Commit e654aa46 authored by Vadim Caen's avatar Vadim Caen
Browse files

Wait for SurfaceAnimationThread before teardown

Dispose the SurfaceAnimationThread before tearing down the mocks in test do
avoid NPE due to mocks being teared down when the SurfaceAnimationRunner
callback are triggered.

Bug: b/144270260
Test: atest WmTests:DisplayContentTests
Change-Id: Iead191ab046379967210ca92db270e897ff43b68
parent 311fef7b
Loading
Loading
Loading
Loading
+17 −0
Original line number Diff line number Diff line
@@ -21,6 +21,7 @@ import static android.os.Process.THREAD_PRIORITY_DISPLAY;
import android.os.Handler;
import android.os.Trace;

import com.android.internal.annotations.VisibleForTesting;
import com.android.server.ServiceThread;

/**
@@ -56,4 +57,20 @@ public final class SurfaceAnimationThread extends ServiceThread {
            return sHandler;
        }
    }

    /**
     * Disposes current surface animation thread if it's initialized. Should only be used in tests
     * to set up a new environment.
     */
    @VisibleForTesting
    public static void dispose() {
        synchronized (SurfaceAnimationThread.class) {
            if (sInstance == null) {
                return;
            }

            getHandler().runWithScissors(() -> sInstance.quit(), 0 /* timeout */);
            sInstance = null;
        }
    }
}
+1 −0
Original line number Diff line number Diff line
@@ -311,6 +311,7 @@ public class SystemServicesTestRule implements TestRule {
        DisplayThread.dispose();
        AnimationThread.dispose();
        UiThread.dispose();
        SurfaceAnimationThread.dispose();
        mInputChannel.dispose();

        tearDownLocalServices();