Loading services/core/java/com/android/server/wm/Dimmer.java +5 −2 Original line number Diff line number Diff line Loading @@ -211,15 +211,18 @@ class Dimmer { * child should call setAppearance again to request the Dim to continue. * If multiple containers call this method, only the changes relative to the topmost will be * applied. * The creation of the dim layer is delayed if the requested dim and blur are 0. * @param dimmingContainer Container requesting the dim * @param alpha Dim amount * @param blurRadius Blur amount */ protected void adjustAppearance(@NonNull WindowState dimmingContainer, float alpha, int blurRadius) { if (mDimState != null || (alpha != 0 || blurRadius != 0)) { final DimState d = obtainDimState(dimmingContainer); d.prepareLookChange(alpha, blurRadius); } } /** * Position the dim relatively to the dimming container. Loading services/tests/wmtests/src/com/android/server/wm/DimmerTests.java +29 −0 Original line number Diff line number Diff line Loading @@ -25,6 +25,7 @@ import static com.android.server.wm.utils.LastCallVerifier.lastCall; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyInt; import static org.mockito.ArgumentMatchers.eq; Loading Loading @@ -432,4 +433,32 @@ public class DimmerTests extends WindowTestsBase { verify(mTransaction, never()).setAlpha(dimLayer, 0.5f); verify(mTransaction).setAlpha(dimLayer, 0.9f); } /** * A window requesting to dim to 0 and without blur would cause the dim to be created and * destroyed continuously. * Ensure the dim layer is not created until the window is requesting valid values. */ @Test public void testDimNotCreatedIfNoAlphaNoBlur() { mDimmer.adjustAppearance(mChild1, 0.0f, 0); mDimmer.adjustPosition(mChild1, mChild1); assertNull(mDimmer.getDimLayer()); mDimmer.updateDims(mTransaction); assertNull(mDimmer.getDimLayer()); mDimmer.adjustAppearance(mChild1, 0.9f, 0); mDimmer.adjustPosition(mChild1, mChild1); assertNotNull(mDimmer.getDimLayer()); } /** * If there is a blur, then the dim layer is created even though alpha is 0 */ @Test public void testDimCreatedIfNoAlphaButHasBlur() { mDimmer.adjustAppearance(mChild1, 0.0f, 10); mDimmer.adjustPosition(mChild1, mChild1); assertNotNull(mDimmer.getDimLayer()); } } Loading
services/core/java/com/android/server/wm/Dimmer.java +5 −2 Original line number Diff line number Diff line Loading @@ -211,15 +211,18 @@ class Dimmer { * child should call setAppearance again to request the Dim to continue. * If multiple containers call this method, only the changes relative to the topmost will be * applied. * The creation of the dim layer is delayed if the requested dim and blur are 0. * @param dimmingContainer Container requesting the dim * @param alpha Dim amount * @param blurRadius Blur amount */ protected void adjustAppearance(@NonNull WindowState dimmingContainer, float alpha, int blurRadius) { if (mDimState != null || (alpha != 0 || blurRadius != 0)) { final DimState d = obtainDimState(dimmingContainer); d.prepareLookChange(alpha, blurRadius); } } /** * Position the dim relatively to the dimming container. Loading
services/tests/wmtests/src/com/android/server/wm/DimmerTests.java +29 −0 Original line number Diff line number Diff line Loading @@ -25,6 +25,7 @@ import static com.android.server.wm.utils.LastCallVerifier.lastCall; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyInt; import static org.mockito.ArgumentMatchers.eq; Loading Loading @@ -432,4 +433,32 @@ public class DimmerTests extends WindowTestsBase { verify(mTransaction, never()).setAlpha(dimLayer, 0.5f); verify(mTransaction).setAlpha(dimLayer, 0.9f); } /** * A window requesting to dim to 0 and without blur would cause the dim to be created and * destroyed continuously. * Ensure the dim layer is not created until the window is requesting valid values. */ @Test public void testDimNotCreatedIfNoAlphaNoBlur() { mDimmer.adjustAppearance(mChild1, 0.0f, 0); mDimmer.adjustPosition(mChild1, mChild1); assertNull(mDimmer.getDimLayer()); mDimmer.updateDims(mTransaction); assertNull(mDimmer.getDimLayer()); mDimmer.adjustAppearance(mChild1, 0.9f, 0); mDimmer.adjustPosition(mChild1, mChild1); assertNotNull(mDimmer.getDimLayer()); } /** * If there is a blur, then the dim layer is created even though alpha is 0 */ @Test public void testDimCreatedIfNoAlphaButHasBlur() { mDimmer.adjustAppearance(mChild1, 0.0f, 10); mDimmer.adjustPosition(mChild1, mChild1); assertNotNull(mDimmer.getDimLayer()); } }