From 28be584ac4dcb68e6f2baf0d03ec933ee7f2edb4 Mon Sep 17 00:00:00 2001 From: Adrian Roos Date: Wed, 8 Mar 2023 17:02:36 +0000 Subject: [PATCH] IMMS tests: fix broken tests The test relied on another unrelated test initializing the ContentProvider that DeviceConfig uses. After Ia6f2ee781c431088cbb3417c1b6bac86cfce4c13, this is no longer happening. Working around it for now to unblock tests. Fixes: 272229177 Test: atest DefaultImeVisibilityApplierTest Change-Id: I51e4f28b885b6dbdf64e759d5978b89c9039db6b --- .../server/inputmethod/InputMethodDeviceConfigs.java | 7 +++++++ .../InputMethodManagerServiceTestBase.java | 11 +++++++++++ 2 files changed, 18 insertions(+) diff --git a/services/core/java/com/android/server/inputmethod/InputMethodDeviceConfigs.java b/services/core/java/com/android/server/inputmethod/InputMethodDeviceConfigs.java index dc2799e8e4340..6cd2493cfdff6 100644 --- a/services/core/java/com/android/server/inputmethod/InputMethodDeviceConfigs.java +++ b/services/core/java/com/android/server/inputmethod/InputMethodDeviceConfigs.java @@ -21,6 +21,8 @@ import static android.provider.InputMethodManagerDeviceConfig.KEY_HIDE_IME_WHEN_ import android.app.ActivityThread; import android.provider.DeviceConfig; +import com.android.internal.annotations.VisibleForTesting; + /** * Class for the device-level configuration related to the input method manager * platform features in {@link DeviceConfig}. @@ -56,4 +58,9 @@ final class InputMethodDeviceConfigs { public boolean shouldHideImeWhenNoEditorFocus() { return mHideImeWhenNoEditorFocus; } + + @VisibleForTesting + void destroy() { + DeviceConfig.removeOnPropertiesChangedListener(mDeviceConfigChangedListener); + } } diff --git a/services/tests/InputMethodSystemServerTests/src/com/android/server/inputmethod/InputMethodManagerServiceTestBase.java b/services/tests/InputMethodSystemServerTests/src/com/android/server/inputmethod/InputMethodManagerServiceTestBase.java index dbdffd05714aa..8c86f3e9efc58 100644 --- a/services/tests/InputMethodSystemServerTests/src/com/android/server/inputmethod/InputMethodManagerServiceTestBase.java +++ b/services/tests/InputMethodSystemServerTests/src/com/android/server/inputmethod/InputMethodManagerServiceTestBase.java @@ -65,6 +65,7 @@ import com.android.server.wm.WindowManagerInternal; import org.junit.After; import org.junit.Before; +import org.junit.BeforeClass; import org.mockito.Mock; import org.mockito.MockitoSession; import org.mockito.quality.Strictness; @@ -121,6 +122,14 @@ public class InputMethodManagerServiceTestBase { protected InputMethodManagerService mInputMethodManagerService; protected ServiceThread mServiceThread; + @BeforeClass + public static void setupClass() { + // Make sure DeviceConfig's lazy-initialized ContentProvider gets + // a real instance before we stub out all system services below. + // TODO(b/272229177): remove dependency on real ContentProvider + new InputMethodDeviceConfigs().destroy(); + } + @Before public void setUp() throws RemoteException { mMockingSession = @@ -230,6 +239,8 @@ public class InputMethodManagerServiceTestBase { @After public void tearDown() { + mInputMethodManagerService.mInputMethodDeviceConfigs.destroy(); + if (mServiceThread != null) { mServiceThread.quitSafely(); }