From df3a229ee1b454c1e85e466f1025c2fc2c6e5e4f Mon Sep 17 00:00:00 2001 From: Jeff Chang Date: Thu, 27 Oct 2022 19:31:41 +0800 Subject: [PATCH] Fix NPE when run the splitscreen test ccfed74e82bde9ea, add the toast maker in StageCoordinator. NPE is thrown when running the splitscreen test. It can't toast on a thread that has not been called Looper.prepare(). This CL adds the @UiThreadTest on needed tests to fix the NPE. Bug: 256087248 Test: atest com.android.wm.shell.splitscreen Change-Id: I9fef85c58570a9c1ca2741d1a8aa81439850cc88 --- .../wm/shell/splitscreen/SplitScreenControllerTests.java | 5 +++++ .../android/wm/shell/splitscreen/StageCoordinatorTests.java | 2 ++ 2 files changed, 7 insertions(+) diff --git a/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/splitscreen/SplitScreenControllerTests.java b/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/splitscreen/SplitScreenControllerTests.java index 55883ab2ef70c..d01f3d310fc3e 100644 --- a/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/splitscreen/SplitScreenControllerTests.java +++ b/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/splitscreen/SplitScreenControllerTests.java @@ -39,6 +39,7 @@ import android.content.ComponentName; import android.content.Intent; import android.content.pm.ActivityInfo; +import androidx.test.annotation.UiThreadTest; import androidx.test.ext.junit.runners.AndroidJUnit4; import androidx.test.filters.SmallTest; @@ -110,6 +111,7 @@ public class SplitScreenControllerTests extends ShellTestCase { } @Test + @UiThreadTest public void instantiateController_registerDumpCallback() { doReturn(mMainExecutor).when(mTaskOrganizer).getExecutor(); when(mDisplayController.getDisplayLayout(anyInt())).thenReturn(new DisplayLayout()); @@ -118,6 +120,7 @@ public class SplitScreenControllerTests extends ShellTestCase { } @Test + @UiThreadTest public void instantiateController_registerCommandCallback() { doReturn(mMainExecutor).when(mTaskOrganizer).getExecutor(); when(mDisplayController.getDisplayLayout(anyInt())).thenReturn(new DisplayLayout()); @@ -126,6 +129,7 @@ public class SplitScreenControllerTests extends ShellTestCase { } @Test + @UiThreadTest public void testControllerRegistersKeyguardChangeListener() { doReturn(mMainExecutor).when(mTaskOrganizer).getExecutor(); when(mDisplayController.getDisplayLayout(anyInt())).thenReturn(new DisplayLayout()); @@ -134,6 +138,7 @@ public class SplitScreenControllerTests extends ShellTestCase { } @Test + @UiThreadTest public void instantiateController_addExternalInterface() { doReturn(mMainExecutor).when(mTaskOrganizer).getExecutor(); when(mDisplayController.getDisplayLayout(anyInt())).thenReturn(new DisplayLayout()); diff --git a/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/splitscreen/StageCoordinatorTests.java b/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/splitscreen/StageCoordinatorTests.java index 835087007b30e..3569860b61282 100644 --- a/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/splitscreen/StageCoordinatorTests.java +++ b/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/splitscreen/StageCoordinatorTests.java @@ -50,6 +50,7 @@ import android.view.SurfaceSession; import android.window.WindowContainerToken; import android.window.WindowContainerTransaction; +import androidx.test.annotation.UiThreadTest; import androidx.test.ext.junit.runners.AndroidJUnit4; import androidx.test.filters.SmallTest; @@ -113,6 +114,7 @@ public class StageCoordinatorTests extends ShellTestCase { private StageCoordinator mStageCoordinator; @Before + @UiThreadTest public void setup() { MockitoAnnotations.initMocks(this); mStageCoordinator = spy(new StageCoordinator(mContext, DEFAULT_DISPLAY, mSyncQueue,