WM Tests: Use a separate WindowManager instance per test
Fixes a bunch of flakes, where the WindowManagerService instance
was reused between tests, which caused delayed callbacks from a
previous test affecting state of a future test.
Also introduces a DexmakerShareClassLoaderRule to manage
the 'dexmaker.share_classloader' property instead of sprinkling
error prone System.setProperty() invocations all over the tests.
Change-Id: Ic9445d1b2cef594e79365c425632aabced6343a9
Fixes: 76111404
Fixes: 75991352
Fixes: 75991878
Fixes: 75992153
Test: atest services/tests/servicestests DexmakerShareClassLoaderRuleTest packages/SystemUI/tests packages/SystemUI/shared/tests
diff --git a/services/tests/servicestests/src/com/android/server/am/ActivityTestsBase.java b/services/tests/servicestests/src/com/android/server/am/ActivityTestsBase.java
index 6fb1b2e..ab2916b 100644
--- a/services/tests/servicestests/src/com/android/server/am/ActivityTestsBase.java
+++ b/services/tests/servicestests/src/com/android/server/am/ActivityTestsBase.java
@@ -31,6 +31,8 @@
import static org.mockito.Mockito.spy;
import com.android.server.wm.DisplayWindowController;
+
+import org.junit.Rule;
import org.mockito.invocation.InvocationOnMock;
import android.app.IApplicationThread;
@@ -47,6 +49,8 @@
import android.os.Looper;
import android.service.voice.IVoiceInteractionSession;
import android.support.test.InstrumentationRegistry;
+import android.testing.DexmakerShareClassLoaderRule;
+
import com.android.server.AttributeCache;
import com.android.server.wm.AppWindowContainerController;
import com.android.server.wm.PinnedStackWindowController;
@@ -64,6 +68,10 @@
public class ActivityTestsBase {
private static boolean sOneTimeSetupDone = false;
+ @Rule
+ public final DexmakerShareClassLoaderRule mDexmakerShareClassLoaderRule =
+ new DexmakerShareClassLoaderRule();
+
private final Context mContext = InstrumentationRegistry.getContext();
private HandlerThread mHandlerThread;
@@ -77,9 +85,6 @@
public void setUp() throws Exception {
if (!sOneTimeSetupDone) {
sOneTimeSetupDone = true;
-
- // Allows to mock package local classes and methods
- System.setProperty("dexmaker.share_classloader", "true");
MockitoAnnotations.initMocks(this);
}
mHandlerThread = new HandlerThread("ActivityTestsBaseThread");