diff options
| -rw-r--r-- | services/tests/wmtests/src/com/android/server/wm/DimmerTests.java | 135 | ||||
| -rw-r--r-- | services/tests/wmtests/src/com/android/server/wm/SystemServiceTestsBase.java | 5 |
2 files changed, 131 insertions, 9 deletions
diff --git a/services/tests/wmtests/src/com/android/server/wm/DimmerTests.java b/services/tests/wmtests/src/com/android/server/wm/DimmerTests.java index a831f6a382ed..9efbe3587ab2 100644 --- a/services/tests/wmtests/src/com/android/server/wm/DimmerTests.java +++ b/services/tests/wmtests/src/com/android/server/wm/DimmerTests.java @@ -25,8 +25,6 @@ import static com.android.server.wm.SurfaceAnimator.ANIMATION_TYPE_DIMMER; import static com.android.server.wm.utils.LastCallVerifier.lastCall; import static org.junit.Assert.assertNotNull; -import static org.junit.Assume.assumeFalse; -import static org.junit.Assume.assumeTrue; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyBoolean; import static org.mockito.ArgumentMatchers.anyInt; @@ -36,11 +34,14 @@ import static org.mockito.Mockito.when; import android.graphics.Rect; import android.platform.test.annotations.Presubmit; +import android.platform.test.annotations.RequiresFlagsDisabled; +import android.platform.test.annotations.RequiresFlagsEnabled; import android.view.SurfaceControl; import android.view.SurfaceSession; import com.android.server.testutils.StubTransaction; import com.android.server.wm.utils.MockAnimationAdapter; +import com.android.window.flags.Flags; import org.junit.Before; import org.junit.Test; @@ -176,8 +177,8 @@ public class DimmerTests extends WindowTestsBase { } @Test + @RequiresFlagsEnabled(Flags.FLAG_INTRODUCE_SMOOTHER_DIMMER) public void testDimBelowWithChildSurfaceCreatesSurfaceBelowChild_Smooth() { - assumeTrue(Dimmer.DIMMER_REFACTOR); final float alpha = 0.7f; final int blur = 50; mHost.addChild(mChild, 0); @@ -196,8 +197,8 @@ public class DimmerTests extends WindowTestsBase { } @Test + @RequiresFlagsDisabled(Flags.FLAG_INTRODUCE_SMOOTHER_DIMMER) public void testDimBelowWithChildSurfaceCreatesSurfaceBelowChild_Legacy() { - assumeFalse(Dimmer.DIMMER_REFACTOR); final float alpha = 0.7f; mHost.addChild(mChild, 0); mDimmer.adjustAppearance(mChild, alpha, 20); @@ -211,8 +212,8 @@ public class DimmerTests extends WindowTestsBase { } @Test + @RequiresFlagsEnabled(Flags.FLAG_INTRODUCE_SMOOTHER_DIMMER) public void testDimBelowWithChildSurfaceDestroyedWhenReset_Smooth() { - assumeTrue(Dimmer.DIMMER_REFACTOR); mHost.addChild(mChild, 0); final float alpha = 0.8f; @@ -231,8 +232,8 @@ public class DimmerTests extends WindowTestsBase { } @Test + @RequiresFlagsDisabled(Flags.FLAG_INTRODUCE_SMOOTHER_DIMMER) public void testDimBelowWithChildSurfaceDestroyedWhenReset_Legacy() { - assumeFalse(Dimmer.DIMMER_REFACTOR); mHost.addChild(mChild, 0); final float alpha = 0.8f; @@ -291,8 +292,8 @@ public class DimmerTests extends WindowTestsBase { } @Test + @RequiresFlagsEnabled(Flags.FLAG_INTRODUCE_SMOOTHER_DIMMER) public void testRemoveDimImmediately_Smooth() { - assumeTrue(Dimmer.DIMMER_REFACTOR); mHost.addChild(mChild, 0); mDimmer.adjustAppearance(mChild, 1, 2); mDimmer.adjustRelativeLayer(mChild, -1); @@ -311,8 +312,8 @@ public class DimmerTests extends WindowTestsBase { } @Test + @RequiresFlagsDisabled(Flags.FLAG_INTRODUCE_SMOOTHER_DIMMER) public void testRemoveDimImmediately_Legacy() { - assumeFalse(Dimmer.DIMMER_REFACTOR); mHost.addChild(mChild, 0); mDimmer.adjustAppearance(mChild, 1, 0); mDimmer.adjustRelativeLayer(mChild, -1); @@ -331,8 +332,8 @@ public class DimmerTests extends WindowTestsBase { } @Test + @RequiresFlagsDisabled(Flags.FLAG_INTRODUCE_SMOOTHER_DIMMER) public void testDimmerWithBlurUpdatesTransaction_Legacy() { - assumeFalse(Dimmer.DIMMER_REFACTOR); mHost.addChild(mChild, 0); final int blurRadius = 50; @@ -345,4 +346,120 @@ public class DimmerTests extends WindowTestsBase { verify(mHost.getPendingTransaction()).setBackgroundBlurRadius(dimLayer, blurRadius); verify(mHost.getPendingTransaction()).setRelativeLayer(dimLayer, mChild.mControl, -1); } + + /** + * mChild is requesting the dim values to be set directly. In this case, dim won't play the + * standard animation, but directly apply mChild's requests to the dim surface + */ + @Test + @RequiresFlagsEnabled(Flags.FLAG_INTRODUCE_SMOOTHER_DIMMER) + public void testContainerDimsOpeningAnimationByItself() { + mHost.addChild(mChild, 0); + + mDimmer.resetDimStates(); + mDimmer.adjustAppearance(mChild, 0.1f, 0); + mDimmer.adjustRelativeLayer(mChild, -1); + SurfaceControl dimLayer = mDimmer.getDimLayer(); + mDimmer.updateDims(mTransaction); + + mDimmer.resetDimStates(); + mDimmer.adjustAppearance(mChild, 0.2f, 0); + mDimmer.adjustRelativeLayer(mChild, -1); + mDimmer.updateDims(mTransaction); + + mDimmer.resetDimStates(); + mDimmer.adjustAppearance(mChild, 0.3f, 0); + mDimmer.adjustRelativeLayer(mChild, -1); + mDimmer.updateDims(mTransaction); + + verify(mTransaction).setAlpha(dimLayer, 0.2f); + verify(mTransaction).setAlpha(dimLayer, 0.3f); + verify(sTestAnimation, times(1)).startAnimation( + any(SurfaceControl.class), any(SurfaceControl.Transaction.class), + anyInt(), any(SurfaceAnimator.OnAnimationFinishedCallback.class)); + } + + /** + * Same as testContainerDimsOpeningAnimationByItself, but this is a more specific case in which + * alpha is animated to 0. This corner case is needed to verify that the layer is removed anyway + */ + @Test + @RequiresFlagsEnabled(Flags.FLAG_INTRODUCE_SMOOTHER_DIMMER) + public void testContainerDimsClosingAnimationByItself() { + mHost.addChild(mChild, 0); + + mDimmer.resetDimStates(); + mDimmer.adjustAppearance(mChild, 0.2f, 0); + mDimmer.adjustRelativeLayer(mChild, -1); + SurfaceControl dimLayer = mDimmer.getDimLayer(); + mDimmer.updateDims(mTransaction); + + mDimmer.resetDimStates(); + mDimmer.adjustAppearance(mChild, 0.1f, 0); + mDimmer.adjustRelativeLayer(mChild, -1); + mDimmer.updateDims(mTransaction); + + mDimmer.resetDimStates(); + mDimmer.adjustAppearance(mChild, 0f, 0); + mDimmer.adjustRelativeLayer(mChild, -1); + mDimmer.updateDims(mTransaction); + + mDimmer.resetDimStates(); + mDimmer.updateDims(mTransaction); + verify(mTransaction).remove(dimLayer); + } + + /** + * Check the handover of the dim between two windows and the consequent dim animation in between + */ + @Test + @RequiresFlagsEnabled(Flags.FLAG_INTRODUCE_SMOOTHER_DIMMER) + public void testMultipleContainersDimmingConsecutively() { + TestWindowContainer first = mChild; + TestWindowContainer second = new TestWindowContainer(mWm); + mHost.addChild(first, 0); + mHost.addChild(second, 1); + + mDimmer.adjustAppearance(first, 0.5f, 0); + mDimmer.adjustRelativeLayer(first, -1); + SurfaceControl dimLayer = mDimmer.getDimLayer(); + mDimmer.updateDims(mTransaction); + + mDimmer.resetDimStates(); + mDimmer.adjustAppearance(second, 0.9f, 0); + mDimmer.adjustRelativeLayer(second, -1); + mDimmer.updateDims(mTransaction); + + verify(sTestAnimation, times(2)).startAnimation( + any(SurfaceControl.class), any(SurfaceControl.Transaction.class), + anyInt(), any(SurfaceAnimator.OnAnimationFinishedCallback.class)); + verify(mTransaction).setAlpha(dimLayer, 0.5f); + verify(mTransaction).setAlpha(dimLayer, 0.9f); + } + + /** + * Two windows are trying to modify the dim at the same time, but only the last request before + * updateDims will be satisfied + */ + @Test + @RequiresFlagsEnabled(Flags.FLAG_INTRODUCE_SMOOTHER_DIMMER) + public void testMultipleContainersDimmingAtTheSameTime() { + TestWindowContainer first = mChild; + TestWindowContainer second = new TestWindowContainer(mWm); + mHost.addChild(first, 0); + mHost.addChild(second, 1); + + mDimmer.adjustAppearance(first, 0.5f, 0); + mDimmer.adjustRelativeLayer(first, -1); + SurfaceControl dimLayer = mDimmer.getDimLayer(); + mDimmer.adjustAppearance(second, 0.9f, 0); + mDimmer.adjustRelativeLayer(second, -1); + mDimmer.updateDims(mTransaction); + + verify(sTestAnimation, times(1)).startAnimation( + any(SurfaceControl.class), any(SurfaceControl.Transaction.class), + anyInt(), any(SurfaceAnimator.OnAnimationFinishedCallback.class)); + verify(mTransaction, never()).setAlpha(dimLayer, 0.5f); + verify(mTransaction).setAlpha(dimLayer, 0.9f); + } } diff --git a/services/tests/wmtests/src/com/android/server/wm/SystemServiceTestsBase.java b/services/tests/wmtests/src/com/android/server/wm/SystemServiceTestsBase.java index 3cb4a1d7b7ec..e65a9feed1aa 100644 --- a/services/tests/wmtests/src/com/android/server/wm/SystemServiceTestsBase.java +++ b/services/tests/wmtests/src/com/android/server/wm/SystemServiceTestsBase.java @@ -19,6 +19,8 @@ package com.android.server.wm; import static com.android.dx.mockito.inline.extended.ExtendedMockito.doReturn; import android.os.Handler; +import android.platform.test.flag.junit.CheckFlagsRule; +import android.platform.test.flag.junit.DeviceFlagsValueProvider; import android.platform.test.flag.junit.SetFlagsRule; import android.testing.DexmakerShareClassLoaderRule; @@ -39,6 +41,9 @@ class SystemServiceTestsBase { public final SystemServicesTestRule mSystemServicesTestRule = new SystemServicesTestRule( this::onBeforeSystemServicesCreated); + @Rule + public final CheckFlagsRule mCheckFlagsRule = DeviceFlagsValueProvider.createCheckFlagsRule(); + @WindowTestRunner.MethodWrapperRule public final WindowManagerGlobalLockRule mLockRule = new WindowManagerGlobalLockRule(mSystemServicesTestRule); |