Assert.assertTrue on instrumentation thread

BUG:37259172

Test: local CTS test

Change-Id: I5e9c21a63a0b6d11fedca8e75f39903826b1465a
diff --git a/tests/tests/uirendering/src/android/uirendering/cts/testclasses/BitmapTests.java b/tests/tests/uirendering/src/android/uirendering/cts/testclasses/BitmapTests.java
index f0afd53..ce7e4b5 100644
--- a/tests/tests/uirendering/src/android/uirendering/cts/testclasses/BitmapTests.java
+++ b/tests/tests/uirendering/src/android/uirendering/cts/testclasses/BitmapTests.java
@@ -99,9 +99,10 @@
             }
         }
 
+        RtOnlyFrameCounter counter = new RtOnlyFrameCounter();
+
         ViewInitializer initializer = new ViewInitializer() {
             Animator mAnimator;
-            RtOnlyFrameCounter mCounter = new RtOnlyFrameCounter();
 
             @Override
             public void initializeView(View view) {
@@ -128,19 +129,21 @@
                         child.setColor(Color.BLUE);
                     }
                 }, 1000);
-                getActivity().getWindow().addOnFrameMetricsAvailableListener(mCounter, handler);
+                getActivity().getWindow().addOnFrameMetricsAvailableListener(counter, handler);
             }
 
             @Override
             public void teardownView() {
                 mAnimator.cancel();
-                Assert.assertTrue(mCounter.isLargeEnough());
+                getActivity().getWindow().removeOnFrameMetricsAvailableListener(counter);
             }
         };
 
         createTest()
                 .addLayout(R.layout.frame_layout, initializer, true)
                 .runWithAnimationVerifier(new ColorCountVerifier(Color.RED, 0));
+
+        Assert.assertTrue(counter.isLargeEnough());
     }
 
     /*