Merge "Fix crash of test after finishing RecentsAnimationTest" into qt-dev
am: 0f10625790

Change-Id: Ifaad6ef5890dadce259e28ea4681fd6cb160dd55
diff --git a/services/tests/wmtests/src/com/android/server/wm/ActivityTestsBase.java b/services/tests/wmtests/src/com/android/server/wm/ActivityTestsBase.java
index 53b0add..4986a6d 100644
--- a/services/tests/wmtests/src/com/android/server/wm/ActivityTestsBase.java
+++ b/services/tests/wmtests/src/com/android/server/wm/ActivityTestsBase.java
@@ -585,7 +585,10 @@
         }
 
         void tearDown() {
-            mHandlerThread.quitSafely();
+            // Make sure there are no running messages and then quit the thread so the next test
+            // won't be affected.
+            mHandlerThread.getThreadHandler().runWithScissors(mHandlerThread::quit,
+                    0 /* timeout */);
         }
     }
 
@@ -630,7 +633,8 @@
             mWindowManager = prepareMockWindowManager();
             mKeyguardController = mock(KeyguardController.class);
 
-            // Do not schedule idle timeouts
+            // Do not schedule idle that may touch methods outside the scope of the test.
+            doNothing().when(this).scheduleIdleLocked();
             doNothing().when(this).scheduleIdleTimeoutLocked(any());
             // unit test version does not handle launch wake lock
             doNothing().when(this).acquireLaunchWakelock();