OSDN Git Service

Scale timeout with animation scale
authorJorim Jaggi <jjaggi@google.com>
Thu, 1 Feb 2018 14:03:59 +0000 (15:03 +0100)
committerJorim Jaggi <jjaggi@google.com>
Thu, 1 Feb 2018 14:03:59 +0000 (15:03 +0100)
So slowed down animations still work
Test: RemoteAnimationControllerTest
Test: go/wm-smoke-auto

Change-Id: I23116fdd0f2e75e4320bd77aee704d1e2a9de5e7

services/core/java/com/android/server/wm/RemoteAnimationController.java
services/tests/servicestests/src/com/android/server/wm/RemoteAnimationControllerTest.java

index 8269a3b..9251993 100644 (file)
@@ -92,7 +92,10 @@ class RemoteAnimationController {
             onAnimationFinished();
             return;
         }
-        mHandler.postDelayed(mTimeoutRunnable, TIMEOUT_MS);
+
+        // Scale the timeout with the animator scale the controlling app is using.
+        mHandler.postDelayed(mTimeoutRunnable,
+                (long) (TIMEOUT_MS * mService.getCurrentAnimatorScale()));
         try {
             mRemoteAnimationAdapter.getRunner().onAnimationStart(createAnimations(),
                     mFinishedCallback);
index f860195..26a7313 100644 (file)
@@ -19,12 +19,12 @@ package com.android.server.wm;
 import static android.view.WindowManager.LayoutParams.TYPE_BASE_APPLICATION;
 import static org.junit.Assert.assertEquals;
 import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.Mockito.never;
 import static org.mockito.Mockito.verify;
 import static org.mockito.Mockito.verifyZeroInteractions;
 
 import android.graphics.Point;
 import android.graphics.Rect;
-import android.platform.test.annotations.Postsubmit;
 import android.support.test.filters.FlakyTest;
 import android.support.test.filters.SmallTest;
 import android.support.test.runner.AndroidJUnit4;
@@ -137,6 +137,32 @@ public class RemoteAnimationControllerTest extends WindowTestsBase {
     }
 
     @Test
+    public void testTimeout_scaled() throws Exception {
+        sWm.setAnimationScale(2, 5.0f);
+        try{
+            final WindowState win = createWindow(null /* parent */, TYPE_BASE_APPLICATION, "testWin");
+            final AnimationAdapter adapter = mController.createAnimationAdapter(win.mAppToken,
+                    new Point(50, 100), new Rect(50, 100, 150, 150));
+            adapter.startAnimation(mMockLeash, mMockTransaction, mFinishedCallback);
+            mController.goodToGo();
+
+            mClock.fastForward(2500);
+            mHandler.timeAdvance();
+
+            verify(mMockRunner, never()).onAnimationCancelled();
+
+            mClock.fastForward(10000);
+            mHandler.timeAdvance();
+
+            verify(mMockRunner).onAnimationCancelled();
+            verify(mFinishedCallback).onAnimationFinished(eq(adapter));
+        } finally {
+            sWm.setAnimationScale(2, 1.0f);
+        }
+
+    }
+
+    @Test
     public void testZeroAnimations() throws Exception {
         mController.goodToGo();
         verifyZeroInteractions(mMockRunner);