Clean up AnimationThread default handler

To avoid flakiness during unit tests. Note that this is a different
object than WindowManagerService.mAnimationHandler.

Bug: N/A
Test: Let them pass!
Change-Id: I71a775b0599facb4172c86b28d7a9f7e36c65673
This commit is contained in:
Wale Ogunwale
2019-11-21 07:19:07 -08:00
parent 84c262cf99
commit c9dfbc5fc8
3 changed files with 9 additions and 1 deletions

View File

@@ -40,6 +40,10 @@ class SystemServiceTestsBase {
mLockRule.waitForLocked(mSystemServicesTestRule::waitUntilWindowManagerHandlersIdle);
}
void cleanupWindowManagerHandlers() {
mLockRule.waitForLocked(mSystemServicesTestRule::cleanupWindowManagerHandlers);
}
boolean waitHandlerIdle(Handler handler) {
return waitHandlerIdle(handler, 0 /* timeout */);
}

View File

@@ -355,6 +355,8 @@ public class SystemServicesTestRule implements TestRule {
}
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);
}
@@ -367,6 +369,8 @@ public class SystemServicesTestRule implements TestRule {
wm.mH.removeMessages(WindowManagerService.H.FORCE_GC);
waitHandlerIdle(wm.mH);
waitHandlerIdle(wm.mAnimationHandler);
// This is a different handler object than the wm.mAnimationHandler above.
waitHandlerIdle(AnimationThread.getHandler());
waitHandlerIdle(SurfaceAnimationThread.getHandler());
}

View File

@@ -175,7 +175,7 @@ class WindowTestsBase extends SystemServiceTestsBase {
}
// Cleaned up everything in Handler.
mSystemServicesTestRule.cleanupWindowManagerHandlers();
cleanupWindowManagerHandlers();
} catch (Exception e) {
Log.e(TAG, "Failed to tear down test", e);
throw e;