Merge "Simplify Choreographer API."
diff --git a/tests/tests/view/src/android/view/cts/ChoreographerTest.java b/tests/tests/view/src/android/view/cts/ChoreographerTest.java
index 70804c3..b0e50d4 100644
--- a/tests/tests/view/src/android/view/cts/ChoreographerTest.java
+++ b/tests/tests/view/src/android/view/cts/ChoreographerTest.java
@@ -35,214 +35,102 @@
         Choreographer.setFrameDelay(oldFrameDelay);
     }
 
-    public void testScheduleAnimationDoesNothingIfNoListenersOrCallbacks() {
-        mChoreographer.scheduleAnimation();
-        assertFalse(mChoreographer.isAnimationScheduled());
-    }
-
-    public void testScheduleDrawDoesNothingIfNoListenersOrCallbacks() {
-        mChoreographer.scheduleDraw();
-        assertFalse(mChoreographer.isDrawScheduled());
-    }
-
-    public void testScheduleAnimationCausesAnimationListenersAndCallbacksToRun() {
+    public void testPostAnimationCallbackEventuallyRunsCallbacks() {
         MockRunnable addedCallback1 = new MockRunnable();
         MockRunnable addedCallback2 = new MockRunnable();
         MockRunnable removedCallback = new MockRunnable();
-        MockOnAnimateListener addedListener1 = new MockOnAnimateListener();
-        MockOnAnimateListener addedListener2 = new MockOnAnimateListener();
-        MockOnAnimateListener removedListener = new MockOnAnimateListener();
         try {
-            // Add and remove a few callbacks and listeners.
-            mChoreographer.postOnAnimateCallback(addedCallback1);
-            mChoreographer.postOnAnimateCallback(addedCallback2);
-            mChoreographer.postOnAnimateCallback(removedCallback);
-            mChoreographer.removeOnAnimateCallback(removedCallback);
-            mChoreographer.addOnAnimateListener(addedListener1);
-            mChoreographer.addOnAnimateListener(addedListener2);
-            mChoreographer.addOnAnimateListener(removedListener);
-            mChoreographer.removeOnAnimateListener(removedListener);
-            assertTrue(mChoreographer.isAnimationScheduled());
+            // Add and remove a few callbacks.
+            mChoreographer.postAnimationCallback(addedCallback1);
+            mChoreographer.postAnimationCallback(addedCallback2);
+            mChoreographer.postAnimationCallback(removedCallback);
+            mChoreographer.removeAnimationCallback(removedCallback);
 
             // Sleep for a couple of frames.
             sleep(NOMINAL_VSYNC_PERIOD * 3);
 
-            // We expect the remaining callbacks and listeners to have been invoked once.
+            // We expect the remaining callbacks to have been invoked once.
             assertEquals(1, addedCallback1.invocationCount);
             assertEquals(1, addedCallback2.invocationCount);
             assertEquals(0, removedCallback.invocationCount);
-            assertEquals(1, addedListener1.invocationCount);
-            assertEquals(1, addedListener2.invocationCount);
-            assertEquals(0, removedListener.invocationCount);
 
-            // Schedule another animation and wait a bit.
-            mChoreographer.scheduleAnimation();
-            assertTrue(mChoreographer.isAnimationScheduled());
-            sleep(NOMINAL_VSYNC_PERIOD * 3);
-
-            // We expect the listeners to have been invoked again because they are persistent
-            // but the callbacks will not have been invoked because they are one-shot.
-            assertEquals(1, addedCallback1.invocationCount);
-            assertEquals(1, addedCallback2.invocationCount);
-            assertEquals(0, removedCallback.invocationCount);
-            assertEquals(2, addedListener1.invocationCount);
-            assertEquals(2, addedListener2.invocationCount);
-            assertEquals(0, removedListener.invocationCount);
-
-            // If we post a callback again, then it should be invoked again along with the
-            // other listeners.
-            mChoreographer.postOnAnimateCallback(addedCallback1);
-            assertTrue(mChoreographer.isAnimationScheduled());
+            // If we post a callback again, then it should be invoked again.
+            mChoreographer.postAnimationCallback(addedCallback1);
             sleep(NOMINAL_VSYNC_PERIOD * 3);
 
             assertEquals(2, addedCallback1.invocationCount);
             assertEquals(1, addedCallback2.invocationCount);
             assertEquals(0, removedCallback.invocationCount);
-            assertEquals(3, addedListener1.invocationCount);
-            assertEquals(3, addedListener2.invocationCount);
-            assertEquals(0, removedListener.invocationCount);
         } finally {
-            mChoreographer.removeOnAnimateCallback(addedCallback1);
-            mChoreographer.removeOnAnimateCallback(addedCallback2);
-            mChoreographer.removeOnAnimateCallback(removedCallback);
-            mChoreographer.removeOnAnimateListener(addedListener1);
-            mChoreographer.removeOnAnimateListener(addedListener2);
-            mChoreographer.removeOnAnimateListener(removedListener);
+            mChoreographer.removeAnimationCallback(addedCallback1);
+            mChoreographer.removeAnimationCallback(addedCallback2);
+            mChoreographer.removeAnimationCallback(removedCallback);
         }
     }
 
-    public void testScheduleDrawCausesDrawListenersAndCallbacksToRun() {
+    public void testPostDrawCallbackEventuallyRunsCallbacks() {
         MockRunnable addedCallback1 = new MockRunnable();
         MockRunnable addedCallback2 = new MockRunnable();
         MockRunnable removedCallback = new MockRunnable();
-        MockOnDrawListener addedListener1 = new MockOnDrawListener();
-        MockOnDrawListener addedListener2 = new MockOnDrawListener();
-        MockOnDrawListener removedListener = new MockOnDrawListener();
         try {
-            // Add and remove a few callbacks and listeners.
-            mChoreographer.postOnDrawCallback(addedCallback1);
-            mChoreographer.postOnDrawCallback(addedCallback2);
-            mChoreographer.postOnDrawCallback(removedCallback);
-            mChoreographer.removeOnDrawCallback(removedCallback);
-            mChoreographer.addOnDrawListener(addedListener1);
-            mChoreographer.addOnDrawListener(addedListener2);
-            mChoreographer.addOnDrawListener(removedListener);
-            mChoreographer.removeOnDrawListener(removedListener);
-            assertTrue(mChoreographer.isDrawScheduled());
+            // Add and remove a few callbacks.
+            mChoreographer.postDrawCallback(addedCallback1);
+            mChoreographer.postDrawCallback(addedCallback2);
+            mChoreographer.postDrawCallback(removedCallback);
+            mChoreographer.removeDrawCallback(removedCallback);
 
             // Sleep for a couple of frames.
             sleep(NOMINAL_VSYNC_PERIOD * 3);
 
-            // We expect the remaining callbacks and listeners to have been invoked once.
+            // We expect the remaining callbacks to have been invoked once.
             assertEquals(1, addedCallback1.invocationCount);
             assertEquals(1, addedCallback2.invocationCount);
             assertEquals(0, removedCallback.invocationCount);
-            assertEquals(1, addedListener1.invocationCount);
-            assertEquals(1, addedListener2.invocationCount);
-            assertEquals(0, removedListener.invocationCount);
 
-            // Schedule another draw and wait a bit.
-            mChoreographer.scheduleDraw();
-            assertTrue(mChoreographer.isDrawScheduled());
-            sleep(NOMINAL_VSYNC_PERIOD * 3);
-
-            // We expect the listeners to have been invoked again because they are persistent
-            // but the callbacks will not have been invoked because they are one-shot.
-            assertEquals(1, addedCallback1.invocationCount);
-            assertEquals(1, addedCallback2.invocationCount);
-            assertEquals(0, removedCallback.invocationCount);
-            assertEquals(2, addedListener1.invocationCount);
-            assertEquals(2, addedListener2.invocationCount);
-            assertEquals(0, removedListener.invocationCount);
-
-            // If we post a callback again, then it should be invoked again along with the
-            // other listeners.
-            mChoreographer.postOnDrawCallback(addedCallback1);
-            assertTrue(mChoreographer.isDrawScheduled());
+            // If we post a callback again, then it should be invoked again.
+            mChoreographer.postDrawCallback(addedCallback1);
             sleep(NOMINAL_VSYNC_PERIOD * 3);
 
             assertEquals(2, addedCallback1.invocationCount);
             assertEquals(1, addedCallback2.invocationCount);
             assertEquals(0, removedCallback.invocationCount);
-            assertEquals(3, addedListener1.invocationCount);
-            assertEquals(3, addedListener2.invocationCount);
-            assertEquals(0, removedListener.invocationCount);
         } finally {
-            mChoreographer.removeOnDrawCallback(addedCallback1);
-            mChoreographer.removeOnDrawCallback(addedCallback2);
-            mChoreographer.removeOnDrawCallback(removedCallback);
-            mChoreographer.removeOnDrawListener(addedListener1);
-            mChoreographer.removeOnDrawListener(addedListener2);
-            mChoreographer.removeOnDrawListener(removedListener);
+            mChoreographer.removeDrawCallback(addedCallback1);
+            mChoreographer.removeDrawCallback(addedCallback2);
+            mChoreographer.removeDrawCallback(removedCallback);
         }
     }
 
-    public void testAddOnAnimateListenerThrowsIfListenerIsNull() {
+    public void testPostAnimationCallbackThrowsIfRunnableIsNull() {
         try {
-            mChoreographer.addOnAnimateListener(null);
+            mChoreographer.postAnimationCallback(null);
             fail("Expected IllegalArgumentException");
         } catch (IllegalArgumentException ex) {
             // expected
         }
     }
 
-    public void testRemoveOnAnimateListenerThrowsIfListenerIsNull() {
+    public void testRemoveAnimationCallbackThrowsIfRunnableIsNull() {
         try {
-            mChoreographer.removeOnAnimateListener(null);
+            mChoreographer.removeAnimationCallback(null);
             fail("Expected IllegalArgumentException");
         } catch (IllegalArgumentException ex) {
             // expected
         }
     }
 
-    public void testAddOnDrawListenerThrowsIfListenerIsNull() {
+    public void testPostDrawCallbackThrowsIfRunnableIsNull() {
         try {
-            mChoreographer.addOnDrawListener(null);
+            mChoreographer.postDrawCallback(null);
             fail("Expected IllegalArgumentException");
         } catch (IllegalArgumentException ex) {
             // expected
         }
     }
 
-    public void testRemoveOnDrawListenerThrowsIfListenerIsNull() {
+    public void testRemoveDrawCallbackThrowsIfRunnableIsNull() {
         try {
-            mChoreographer.removeOnDrawListener(null);
-            fail("Expected IllegalArgumentException");
-        } catch (IllegalArgumentException ex) {
-            // expected
-        }
-    }
-
-    public void testPostOnAnimateCallbackThrowsIfListenerIsNull() {
-        try {
-            mChoreographer.postOnAnimateCallback(null);
-            fail("Expected IllegalArgumentException");
-        } catch (IllegalArgumentException ex) {
-            // expected
-        }
-    }
-
-    public void testRemoveOnAnimateCallbackThrowsIfListenerIsNull() {
-        try {
-            mChoreographer.removeOnAnimateCallback(null);
-            fail("Expected IllegalArgumentException");
-        } catch (IllegalArgumentException ex) {
-            // expected
-        }
-    }
-
-    public void testPostOnDrawCallbackThrowsIfListenerIsNull() {
-        try {
-            mChoreographer.postOnDrawCallback(null);
-            fail("Expected IllegalArgumentException");
-        } catch (IllegalArgumentException ex) {
-            // expected
-        }
-    }
-
-    public void testRemoveOnDrawCallbackThrowsIfListenerIsNull() {
-        try {
-            mChoreographer.removeOnDrawCallback(null);
+            mChoreographer.removeDrawCallback(null);
             fail("Expected IllegalArgumentException");
         } catch (IllegalArgumentException ex) {
             // expected
@@ -265,22 +153,4 @@
             invocationCount += 1;
         }
     }
-
-    private static final class MockOnAnimateListener implements Choreographer.OnAnimateListener {
-        public int invocationCount;
-
-        @Override
-        public void onAnimate() {
-            invocationCount += 1;
-        }
-    }
-
-    private static final class MockOnDrawListener implements Choreographer.OnDrawListener {
-        public int invocationCount;
-
-        @Override
-        public void onDraw() {
-            invocationCount += 1;
-        }
-    }
 }