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

Commit e2a90aa2 authored by Riddle Hsu's avatar Riddle Hsu
Browse files

Disallow unchecked message removal on shared handler

The dispose() of each shared handler threads in
SystemServicesTestRule#tearDown should be enough for test cleanup.

So remove the usages of removeCallbacksAndMessages to align the
policy of shared handler.

Bug: 235594693
Test: atest WmTests
Change-Id: I4662f06d1d45c62bba08f286643df17c39eec43d
parent c920cb83
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -40,7 +40,7 @@ public final class AnimationThread extends ServiceThread {
            sInstance = new AnimationThread();
            sInstance.start();
            sInstance.getLooper().setTraceTag(Trace.TRACE_TAG_WINDOW_MANAGER);
            sHandler = new Handler(sInstance.getLooper());
            sHandler = makeSharedHandler(sInstance.getLooper());
        }
    }

+1 −1
Original line number Diff line number Diff line
@@ -40,7 +40,7 @@ public final class SurfaceAnimationThread extends ServiceThread {
            sInstance = new SurfaceAnimationThread();
            sInstance.start();
            sInstance.getLooper().setTraceTag(Trace.TRACE_TAG_WINDOW_MANAGER);
            sHandler = new Handler(sInstance.getLooper());
            sHandler = makeSharedHandler(sInstance.getLooper());
        }
    }

+0 −4
Original line number Diff line number Diff line
@@ -47,10 +47,6 @@ class SystemServiceTestsBase {
        mLockRule.waitForLocked(mSystemServicesTestRule::waitUntilWindowAnimatorIdle);
    }

    void cleanupWindowManagerHandlers() {
        mLockRule.waitForLocked(mSystemServicesTestRule::cleanupWindowManagerHandlers);
    }

    boolean waitHandlerIdle(Handler handler) {
        return waitHandlerIdle(handler, 0 /* timeout */);
    }
+0 −14
Original line number Diff line number Diff line
@@ -370,8 +370,6 @@ public class SystemServicesTestRule implements TestRule {
        // This makes sure the posted messages without delay are processed, e.g.
        // DisplayPolicy#release, WindowManagerService#setAnimationScale.
        waitUntilWindowManagerHandlersIdle();
        // Clear all posted messages with delay, so they don't be executed at unexpected times.
        cleanupWindowManagerHandlers();
        // Needs to explicitly dispose current static threads because there could be messages
        // scheduled at a later time, and all mocks are invalid when it's executed.
        DisplayThread.dispose();
@@ -460,18 +458,6 @@ public class SystemServicesTestRule implements TestRule {
        return proc;
    }

    void cleanupWindowManagerHandlers() {
        final WindowManagerService wm = getWindowManagerService();
        if (wm == null) {
            return;
        }
        wm.mH.removeCallbacksAndMessages(null);
        wm.mAnimationHandler.removeCallbacksAndMessages(null);
        // This is a different handler object than the wm.mAnimationHandler above.
        AnimationThread.getHandler().removeCallbacksAndMessages(null);
        SurfaceAnimationThread.getHandler().removeCallbacksAndMessages(null);
    }

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