From 78d189f07b85df7ef170ab4e132ae23fffed8d44 Mon Sep 17 00:00:00 2001 From: Riddle Hsu Date: Mon, 21 Mar 2022 18:53:27 +0800 Subject: [PATCH] Do not unregister CONSTRAIN_DISPLAY_APIS for WmTests Because it uses a static member to decide whether to register. If there are multiple tests depend on it, the tests after the first one will fail because the listener was removed in tearDown. Bug: 219640050 Test: atest SizeCompatTests Change-Id: Icd2e1e4edd3c986b0c714b97a2a4f50d78242fa0 --- .../src/com/android/server/wm/SystemServicesTestRule.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/services/tests/wmtests/src/com/android/server/wm/SystemServicesTestRule.java b/services/tests/wmtests/src/com/android/server/wm/SystemServicesTestRule.java index b2f0b420d67cd..ce861595535c9 100644 --- a/services/tests/wmtests/src/com/android/server/wm/SystemServicesTestRule.java +++ b/services/tests/wmtests/src/com/android/server/wm/SystemServicesTestRule.java @@ -18,6 +18,7 @@ package com.android.server.wm; import static android.app.WindowConfiguration.ACTIVITY_TYPE_HOME; import static android.app.WindowConfiguration.WINDOWING_MODE_FULLSCREEN; +import static android.provider.DeviceConfig.NAMESPACE_CONSTRAIN_DISPLAY_APIS; import static android.testing.DexmakerShareClassLoaderRule.runWithDexmakerShareClassLoader; import static android.view.Display.DEFAULT_DISPLAY; @@ -190,7 +191,11 @@ public class SystemServicesTestRule implements TestRule { private void setUpSystemCore() { doReturn(mock(Watchdog.class)).when(Watchdog::getInstance); doAnswer(invocation -> { - mDeviceConfigListeners.add(invocation.getArgument(2)); + // Exclude CONSTRAIN_DISPLAY_APIS because ActivityRecord#sConstrainDisplayApisConfig + // only registers once and it doesn't reference to outside. + if (!NAMESPACE_CONSTRAIN_DISPLAY_APIS.equals(invocation.getArgument(0))) { + mDeviceConfigListeners.add(invocation.getArgument(2)); + } // SizeCompatTests uses setNeverConstrainDisplayApisFlag, and ActivityRecordTests // uses splash_screen_exception_list. So still execute real registration. return invocation.callRealMethod();