From a852bcb15f6206d91cb731338962f7d0cef6414a Mon Sep 17 00:00:00 2001 From: "Tadashi G. Takaoka" Date: Wed, 28 Oct 2020 13:05:17 +0900 Subject: [PATCH] Add PackageManagerInternal mock to prevent NPE This is a follow up of Idf5d954d89594f7b7a45650ab9173ae16e437dc9. Bug: 171844163 Bug: 171762932 Test: atest FrameworksServicesTests:com.android.server.am Change-Id: I821fef336849def8669bb53bfd1cdfde5d5262de --- .../android/server/am/AppErrorDialogTest.java | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/services/tests/servicestests/src/com/android/server/am/AppErrorDialogTest.java b/services/tests/servicestests/src/com/android/server/am/AppErrorDialogTest.java index 377bfd1170a6d..24f8eabdf5456 100644 --- a/services/tests/servicestests/src/com/android/server/am/AppErrorDialogTest.java +++ b/services/tests/servicestests/src/com/android/server/am/AppErrorDialogTest.java @@ -18,17 +18,25 @@ package com.android.server.am; import static androidx.test.platform.app.InstrumentationRegistry.getInstrumentation; +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.mock; + +import android.content.ComponentName; import android.content.Context; +import android.content.pm.PackageManagerInternal; import android.os.Handler; import androidx.test.annotation.UiThreadTest; import androidx.test.filters.FlakyTest; import androidx.test.filters.SmallTest; +import com.android.server.LocalServices; import com.android.server.appop.AppOpsService; import com.android.server.wm.ActivityTaskManagerService; +import org.junit.AfterClass; import org.junit.Before; +import org.junit.BeforeClass; import org.junit.Rule; import org.junit.Test; @@ -42,6 +50,18 @@ import java.io.File; @FlakyTest(bugId = 113616538) public class AppErrorDialogTest { + @BeforeClass + public static void setUpOnce() { + final PackageManagerInternal pm = mock(PackageManagerInternal.class); + doReturn(new ComponentName("", "")).when(pm).getSystemUiServiceComponent(); + LocalServices.addService(PackageManagerInternal.class, pm); + } + + @AfterClass + public static void tearDownOnce() { + LocalServices.removeServiceForTest(PackageManagerInternal.class); + } + @Rule public ServiceThreadRule mServiceThreadRule = new ServiceThreadRule();