Loading services/core/java/com/android/server/display/ColorFade.java +7 −1 Original line number Diff line number Diff line Loading @@ -156,9 +156,15 @@ final class ColorFade { mMode = mode; DisplayInfo displayInfo = mDisplayManagerInternal.getDisplayInfo(mDisplayId); if (displayInfo == null) { // displayInfo can be null if the associated display has been removed. There // is a delay between the display being removed and ColorFade being dismissed. return false; } // Get the display size and layer stack. // This is not expected to change while the color fade surface is showing. DisplayInfo displayInfo = mDisplayManagerInternal.getDisplayInfo(mDisplayId); mDisplayLayerStack = displayInfo.layerStack; mDisplayWidth = displayInfo.getNaturalWidth(); mDisplayHeight = displayInfo.getNaturalHeight(); Loading services/tests/servicestests/src/com/android/server/display/ColorFadeTest.java 0 → 100644 +75 −0 Original line number Diff line number Diff line /* * Copyright (C) 2022 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.android.server.display; import static androidx.test.platform.app.InstrumentationRegistry.getInstrumentation; import static org.junit.Assert.assertFalse; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.when; import android.content.Context; import android.hardware.display.DisplayManagerInternal; import android.platform.test.annotations.Presubmit; import androidx.test.filters.SmallTest; import androidx.test.runner.AndroidJUnit4; import com.android.server.LocalServices; import org.junit.After; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Mock; import org.mockito.MockitoAnnotations; @SmallTest @Presubmit @RunWith(AndroidJUnit4.class) public class ColorFadeTest { private static final int DISPLAY_ID = 123; private Context mContext; @Mock private DisplayManagerInternal mDisplayManagerInternalMock; @Before public void setUp() { MockitoAnnotations.initMocks(this); addLocalServiceMock(DisplayManagerInternal.class, mDisplayManagerInternalMock); mContext = getInstrumentation().getTargetContext(); } @After public void tearDown() { LocalServices.removeServiceForTest(DisplayManagerInternal.class); } @Test public void testPrepareColorFadeForInvalidDisplay() { when(mDisplayManagerInternalMock.getDisplayInfo(eq(DISPLAY_ID))).thenReturn(null); ColorFade colorFade = new ColorFade(DISPLAY_ID); assertFalse(colorFade.prepare(mContext, ColorFade.MODE_FADE)); } private static <T> void addLocalServiceMock(Class<T> clazz, T mock) { LocalServices.removeServiceForTest(clazz); LocalServices.addService(clazz, mock); } } Loading
services/core/java/com/android/server/display/ColorFade.java +7 −1 Original line number Diff line number Diff line Loading @@ -156,9 +156,15 @@ final class ColorFade { mMode = mode; DisplayInfo displayInfo = mDisplayManagerInternal.getDisplayInfo(mDisplayId); if (displayInfo == null) { // displayInfo can be null if the associated display has been removed. There // is a delay between the display being removed and ColorFade being dismissed. return false; } // Get the display size and layer stack. // This is not expected to change while the color fade surface is showing. DisplayInfo displayInfo = mDisplayManagerInternal.getDisplayInfo(mDisplayId); mDisplayLayerStack = displayInfo.layerStack; mDisplayWidth = displayInfo.getNaturalWidth(); mDisplayHeight = displayInfo.getNaturalHeight(); Loading
services/tests/servicestests/src/com/android/server/display/ColorFadeTest.java 0 → 100644 +75 −0 Original line number Diff line number Diff line /* * Copyright (C) 2022 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.android.server.display; import static androidx.test.platform.app.InstrumentationRegistry.getInstrumentation; import static org.junit.Assert.assertFalse; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.when; import android.content.Context; import android.hardware.display.DisplayManagerInternal; import android.platform.test.annotations.Presubmit; import androidx.test.filters.SmallTest; import androidx.test.runner.AndroidJUnit4; import com.android.server.LocalServices; import org.junit.After; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Mock; import org.mockito.MockitoAnnotations; @SmallTest @Presubmit @RunWith(AndroidJUnit4.class) public class ColorFadeTest { private static final int DISPLAY_ID = 123; private Context mContext; @Mock private DisplayManagerInternal mDisplayManagerInternalMock; @Before public void setUp() { MockitoAnnotations.initMocks(this); addLocalServiceMock(DisplayManagerInternal.class, mDisplayManagerInternalMock); mContext = getInstrumentation().getTargetContext(); } @After public void tearDown() { LocalServices.removeServiceForTest(DisplayManagerInternal.class); } @Test public void testPrepareColorFadeForInvalidDisplay() { when(mDisplayManagerInternalMock.getDisplayInfo(eq(DISPLAY_ID))).thenReturn(null); ColorFade colorFade = new ColorFade(DISPLAY_ID); assertFalse(colorFade.prepare(mContext, ColorFade.MODE_FADE)); } private static <T> void addLocalServiceMock(Class<T> clazz, T mock) { LocalServices.removeServiceForTest(clazz); LocalServices.addService(clazz, mock); } }