Fix ValueAnimatorTest#testCancel

According to the API documentation, regarding ValueAnimator class the
cancel() must be called on the thread that is running the animation.
Otherwise it might have unexpected result of isRunning() due to thread
scheduling.

Change-Id: I58abd68e0715111cffba9f7a083a3dc0550416a2
diff --git a/tests/tests/animation/src/android/animation/cts/ValueAnimatorTest.java b/tests/tests/animation/src/android/animation/cts/ValueAnimatorTest.java
index 509be58..7e86ce7 100644
--- a/tests/tests/animation/src/android/animation/cts/ValueAnimatorTest.java
+++ b/tests/tests/animation/src/android/animation/cts/ValueAnimatorTest.java
@@ -108,7 +108,7 @@
     public void testCancel() throws Throwable {
         startAnimation(mValueAnimator);
         Thread.sleep(100);
-        mValueAnimator.cancel();
+        cancelAnimation(mValueAnimator);
         assertFalse(mValueAnimator.isRunning());
     }
 
@@ -258,6 +258,15 @@
         this.runTestOnUiThread(animationRunnable);
     }
 
+    private void cancelAnimation(final ValueAnimator mValueAnimator) throws Throwable {
+        Thread animationRunnable = new Thread() {
+            public void run() {
+                mValueAnimator.cancel();
+            }
+        };
+        this.runTestOnUiThread(animationRunnable);
+    }
+
     private String errorMessage(float[] values) {
         StringBuilder message = new StringBuilder();
         for (int i = 0; i < values.length; i++) {
@@ -266,4 +275,3 @@
         return message.toString();
     }
 }
-