Loading services/core/java/com/android/server/wm/SurfaceAnimationRunner.java +10 −3 Original line number Diff line number Diff line Loading @@ -26,6 +26,8 @@ import android.animation.Animator; import android.animation.AnimatorListenerAdapter; import android.animation.ValueAnimator; import android.annotation.Nullable; import android.hardware.power.V1_0.PowerHint; import android.os.PowerManagerInternal; import android.util.ArrayMap; import android.view.Choreographer; import android.view.SurfaceControl; Loading Loading @@ -57,6 +59,7 @@ class SurfaceAnimationRunner { private final AnimationHandler mAnimationHandler; private final Transaction mFrameTransaction; private final AnimatorFactory mAnimatorFactory; private final PowerManagerInternal mPowerManagerInternal; private boolean mApplyScheduled; @GuardedBy("mLock") Loading @@ -70,13 +73,15 @@ class SurfaceAnimationRunner { @GuardedBy("mLock") private boolean mAnimationStartDeferred; SurfaceAnimationRunner() { this(null /* callbackProvider */, null /* animatorFactory */, new Transaction()); SurfaceAnimationRunner(PowerManagerInternal powerManagerInternal) { this(null /* callbackProvider */, null /* animatorFactory */, new Transaction(), powerManagerInternal); } @VisibleForTesting SurfaceAnimationRunner(@Nullable AnimationFrameCallbackProvider callbackProvider, AnimatorFactory animatorFactory, Transaction frameTransaction) { AnimatorFactory animatorFactory, Transaction frameTransaction, PowerManagerInternal powerManagerInternal) { SurfaceAnimationThread.getHandler().runWithScissors(() -> mChoreographer = getSfInstance(), 0 /* timeout */); mFrameTransaction = frameTransaction; Loading @@ -87,6 +92,7 @@ class SurfaceAnimationRunner { mAnimatorFactory = animatorFactory != null ? animatorFactory : SfValueAnimator::new; mPowerManagerInternal = powerManagerInternal; } /** Loading Loading @@ -231,6 +237,7 @@ class SurfaceAnimationRunner { synchronized (mLock) { startPendingAnimationsLocked(); } mPowerManagerInternal.powerHint(PowerHint.INTERACTION, 0); } private void scheduleApplyTransaction() { Loading services/core/java/com/android/server/wm/WindowManagerService.java +1 −1 Original line number Diff line number Diff line Loading @@ -1061,7 +1061,7 @@ public class WindowManagerService extends IWindowManager.Stub PowerManager.SCREEN_BRIGHT_WAKE_LOCK | PowerManager.ON_AFTER_RELEASE, TAG_WM); mHoldingScreenWakeLock.setReferenceCounted(false); mSurfaceAnimationRunner = new SurfaceAnimationRunner(); mSurfaceAnimationRunner = new SurfaceAnimationRunner(mPowerManagerInternal); mAllowTheaterModeWakeFromLayout = context.getResources().getBoolean( com.android.internal.R.bool.config_allowTheaterModeWakeFromWindowLayout); Loading services/tests/servicestests/src/com/android/server/wm/SurfaceAnimationRunnerTest.java +20 −8 Original line number Diff line number Diff line Loading @@ -20,24 +20,23 @@ import static java.util.concurrent.TimeUnit.SECONDS; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; import static org.mockito.ArgumentMatchers.anyInt; import static org.mockito.Mockito.any; import static org.mockito.Mockito.atLeast; import static org.mockito.Mockito.atLeastOnce; import static org.mockito.Mockito.eq; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; import android.animation.AnimationHandler; import android.animation.AnimationHandler.AnimationFrameCallbackProvider; import android.animation.ValueAnimator; import android.graphics.Matrix; import android.graphics.Point; import android.os.PowerManagerInternal; import android.platform.test.annotations.Presubmit; import android.support.test.filters.FlakyTest; import android.support.test.filters.SmallTest; import android.support.test.runner.AndroidJUnit4; import android.util.Log; import android.view.Choreographer; import android.view.Choreographer.FrameCallback; import android.view.SurfaceControl; Loading @@ -46,7 +45,6 @@ import android.view.animation.Animation; import android.view.animation.TranslateAnimation; import com.android.server.wm.LocalAnimationAdapter.AnimationSpec; import com.android.server.wm.SurfaceAnimationRunner.AnimatorFactory; import org.junit.Before; import org.junit.Rule; Loading @@ -71,6 +69,7 @@ public class SurfaceAnimationRunnerTest extends WindowTestsBase { @Mock SurfaceControl mMockSurface; @Mock Transaction mMockTransaction; @Mock AnimationSpec mMockAnimationSpec; @Mock PowerManagerInternal mMockPowerManager; @Rule public MockitoRule mMockitoRule = MockitoJUnit.rule(); private SurfaceAnimationRunner mSurfaceAnimationRunner; Loading @@ -81,7 +80,7 @@ public class SurfaceAnimationRunnerTest extends WindowTestsBase { super.setUp(); mFinishCallbackLatch = new CountDownLatch(1); mSurfaceAnimationRunner = new SurfaceAnimationRunner(null /* callbackProvider */, null, mMockTransaction); mMockTransaction, mMockPowerManager); } private void finishedCallback() { Loading Loading @@ -113,7 +112,7 @@ public class SurfaceAnimationRunnerTest extends WindowTestsBase { @Test public void testCancel_notStarted() throws Exception { mSurfaceAnimationRunner = new SurfaceAnimationRunner(new NoOpFrameCallbackProvider(), null, mMockTransaction); mMockTransaction, mMockPowerManager); mSurfaceAnimationRunner .startAnimation(createTranslateAnimation(), mMockSurface, mMockTransaction, this::finishedCallback); Loading @@ -126,7 +125,7 @@ public class SurfaceAnimationRunnerTest extends WindowTestsBase { @Test public void testCancel_running() throws Exception { mSurfaceAnimationRunner = new SurfaceAnimationRunner(new NoOpFrameCallbackProvider(), null, mMockTransaction); mMockTransaction, mMockPowerManager); mSurfaceAnimationRunner.startAnimation(createTranslateAnimation(), mMockSurface, mMockTransaction, this::finishedCallback); waitUntilNextFrame(); Loading Loading @@ -156,7 +155,7 @@ public class SurfaceAnimationRunnerTest extends WindowTestsBase { listener.onAnimationUpdate(animation); }); } }, mMockTransaction); }, mMockTransaction, mMockPowerManager); when(mMockAnimationSpec.getDuration()).thenReturn(200L); mSurfaceAnimationRunner.startAnimation(mMockAnimationSpec, mMockSurface, mMockTransaction, this::finishedCallback); Loading Loading @@ -184,6 +183,19 @@ public class SurfaceAnimationRunnerTest extends WindowTestsBase { assertFinishCallbackCalled(); } @Test public void testPowerHint() throws Exception { mSurfaceAnimationRunner = new SurfaceAnimationRunner(new NoOpFrameCallbackProvider(), null, mMockTransaction, mMockPowerManager); mSurfaceAnimationRunner.startAnimation(createTranslateAnimation(), mMockSurface, mMockTransaction, this::finishedCallback); waitUntilNextFrame(); // TODO: For some reason we don't have access to PowerHint definition from the tests. For // now let's just verify that we got some kind of hint. verify(mMockPowerManager).powerHint(anyInt(), anyInt()); } private void waitUntilNextFrame() throws Exception { final CountDownLatch latch = new CountDownLatch(1); mSurfaceAnimationRunner.mChoreographer.postCallback(Choreographer.CALLBACK_COMMIT, Loading Loading
services/core/java/com/android/server/wm/SurfaceAnimationRunner.java +10 −3 Original line number Diff line number Diff line Loading @@ -26,6 +26,8 @@ import android.animation.Animator; import android.animation.AnimatorListenerAdapter; import android.animation.ValueAnimator; import android.annotation.Nullable; import android.hardware.power.V1_0.PowerHint; import android.os.PowerManagerInternal; import android.util.ArrayMap; import android.view.Choreographer; import android.view.SurfaceControl; Loading Loading @@ -57,6 +59,7 @@ class SurfaceAnimationRunner { private final AnimationHandler mAnimationHandler; private final Transaction mFrameTransaction; private final AnimatorFactory mAnimatorFactory; private final PowerManagerInternal mPowerManagerInternal; private boolean mApplyScheduled; @GuardedBy("mLock") Loading @@ -70,13 +73,15 @@ class SurfaceAnimationRunner { @GuardedBy("mLock") private boolean mAnimationStartDeferred; SurfaceAnimationRunner() { this(null /* callbackProvider */, null /* animatorFactory */, new Transaction()); SurfaceAnimationRunner(PowerManagerInternal powerManagerInternal) { this(null /* callbackProvider */, null /* animatorFactory */, new Transaction(), powerManagerInternal); } @VisibleForTesting SurfaceAnimationRunner(@Nullable AnimationFrameCallbackProvider callbackProvider, AnimatorFactory animatorFactory, Transaction frameTransaction) { AnimatorFactory animatorFactory, Transaction frameTransaction, PowerManagerInternal powerManagerInternal) { SurfaceAnimationThread.getHandler().runWithScissors(() -> mChoreographer = getSfInstance(), 0 /* timeout */); mFrameTransaction = frameTransaction; Loading @@ -87,6 +92,7 @@ class SurfaceAnimationRunner { mAnimatorFactory = animatorFactory != null ? animatorFactory : SfValueAnimator::new; mPowerManagerInternal = powerManagerInternal; } /** Loading Loading @@ -231,6 +237,7 @@ class SurfaceAnimationRunner { synchronized (mLock) { startPendingAnimationsLocked(); } mPowerManagerInternal.powerHint(PowerHint.INTERACTION, 0); } private void scheduleApplyTransaction() { Loading
services/core/java/com/android/server/wm/WindowManagerService.java +1 −1 Original line number Diff line number Diff line Loading @@ -1061,7 +1061,7 @@ public class WindowManagerService extends IWindowManager.Stub PowerManager.SCREEN_BRIGHT_WAKE_LOCK | PowerManager.ON_AFTER_RELEASE, TAG_WM); mHoldingScreenWakeLock.setReferenceCounted(false); mSurfaceAnimationRunner = new SurfaceAnimationRunner(); mSurfaceAnimationRunner = new SurfaceAnimationRunner(mPowerManagerInternal); mAllowTheaterModeWakeFromLayout = context.getResources().getBoolean( com.android.internal.R.bool.config_allowTheaterModeWakeFromWindowLayout); Loading
services/tests/servicestests/src/com/android/server/wm/SurfaceAnimationRunnerTest.java +20 −8 Original line number Diff line number Diff line Loading @@ -20,24 +20,23 @@ import static java.util.concurrent.TimeUnit.SECONDS; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; import static org.mockito.ArgumentMatchers.anyInt; import static org.mockito.Mockito.any; import static org.mockito.Mockito.atLeast; import static org.mockito.Mockito.atLeastOnce; import static org.mockito.Mockito.eq; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; import android.animation.AnimationHandler; import android.animation.AnimationHandler.AnimationFrameCallbackProvider; import android.animation.ValueAnimator; import android.graphics.Matrix; import android.graphics.Point; import android.os.PowerManagerInternal; import android.platform.test.annotations.Presubmit; import android.support.test.filters.FlakyTest; import android.support.test.filters.SmallTest; import android.support.test.runner.AndroidJUnit4; import android.util.Log; import android.view.Choreographer; import android.view.Choreographer.FrameCallback; import android.view.SurfaceControl; Loading @@ -46,7 +45,6 @@ import android.view.animation.Animation; import android.view.animation.TranslateAnimation; import com.android.server.wm.LocalAnimationAdapter.AnimationSpec; import com.android.server.wm.SurfaceAnimationRunner.AnimatorFactory; import org.junit.Before; import org.junit.Rule; Loading @@ -71,6 +69,7 @@ public class SurfaceAnimationRunnerTest extends WindowTestsBase { @Mock SurfaceControl mMockSurface; @Mock Transaction mMockTransaction; @Mock AnimationSpec mMockAnimationSpec; @Mock PowerManagerInternal mMockPowerManager; @Rule public MockitoRule mMockitoRule = MockitoJUnit.rule(); private SurfaceAnimationRunner mSurfaceAnimationRunner; Loading @@ -81,7 +80,7 @@ public class SurfaceAnimationRunnerTest extends WindowTestsBase { super.setUp(); mFinishCallbackLatch = new CountDownLatch(1); mSurfaceAnimationRunner = new SurfaceAnimationRunner(null /* callbackProvider */, null, mMockTransaction); mMockTransaction, mMockPowerManager); } private void finishedCallback() { Loading Loading @@ -113,7 +112,7 @@ public class SurfaceAnimationRunnerTest extends WindowTestsBase { @Test public void testCancel_notStarted() throws Exception { mSurfaceAnimationRunner = new SurfaceAnimationRunner(new NoOpFrameCallbackProvider(), null, mMockTransaction); mMockTransaction, mMockPowerManager); mSurfaceAnimationRunner .startAnimation(createTranslateAnimation(), mMockSurface, mMockTransaction, this::finishedCallback); Loading @@ -126,7 +125,7 @@ public class SurfaceAnimationRunnerTest extends WindowTestsBase { @Test public void testCancel_running() throws Exception { mSurfaceAnimationRunner = new SurfaceAnimationRunner(new NoOpFrameCallbackProvider(), null, mMockTransaction); mMockTransaction, mMockPowerManager); mSurfaceAnimationRunner.startAnimation(createTranslateAnimation(), mMockSurface, mMockTransaction, this::finishedCallback); waitUntilNextFrame(); Loading Loading @@ -156,7 +155,7 @@ public class SurfaceAnimationRunnerTest extends WindowTestsBase { listener.onAnimationUpdate(animation); }); } }, mMockTransaction); }, mMockTransaction, mMockPowerManager); when(mMockAnimationSpec.getDuration()).thenReturn(200L); mSurfaceAnimationRunner.startAnimation(mMockAnimationSpec, mMockSurface, mMockTransaction, this::finishedCallback); Loading Loading @@ -184,6 +183,19 @@ public class SurfaceAnimationRunnerTest extends WindowTestsBase { assertFinishCallbackCalled(); } @Test public void testPowerHint() throws Exception { mSurfaceAnimationRunner = new SurfaceAnimationRunner(new NoOpFrameCallbackProvider(), null, mMockTransaction, mMockPowerManager); mSurfaceAnimationRunner.startAnimation(createTranslateAnimation(), mMockSurface, mMockTransaction, this::finishedCallback); waitUntilNextFrame(); // TODO: For some reason we don't have access to PowerHint definition from the tests. For // now let's just verify that we got some kind of hint. verify(mMockPowerManager).powerHint(anyInt(), anyInt()); } private void waitUntilNextFrame() throws Exception { final CountDownLatch latch = new CountDownLatch(1); mSurfaceAnimationRunner.mChoreographer.postCallback(Choreographer.CALLBACK_COMMIT, Loading