Fix testSetPreviewTextureBothCallbacks wait timeout

The test assumes that
  SurfaceTexture.onFrameAvailableListener.onFrameAvailable()
is the first callback to be called and
  Camera.PreviewCallback.onPreviewFrame()
is called after. If onPreviewFrame is called first the CameraGLTest
will stop the camera preview which may cause onFrameAvailable to not
be called anymore.

Instead of stopping the camera preview in the onPreviewFrame function
the change stops the preview after each timeout wait in each test.

Change-Id: I18748fdca7a557ac059e69cfbfbcbf03e53bed49
diff --git a/tests/tests/hardware/src/android/hardware/cts/CameraGLTest.java b/tests/tests/hardware/src/android/hardware/cts/CameraGLTest.java
index 380e47d..8b0756e 100755
--- a/tests/tests/hardware/src/android/hardware/cts/CameraGLTest.java
+++ b/tests/tests/hardware/src/android/hardware/cts/CameraGLTest.java
@@ -171,7 +171,7 @@
         if (LOGV) Log.v(TAG, "Shutdown of camera complete.");
     }
 
-    /** The camera preview callback. Stops capture after the first callback */
+    /** The camera preview callback. */
     private final class PreviewCallback
             implements android.hardware.Camera.PreviewCallback {
         public void onPreviewFrame(byte [] data, Camera camera) {
@@ -179,7 +179,6 @@
             assertNotNull(data);
             Size size = camera.getParameters().getPreviewSize();
             assertEquals(size.width * size.height * 3 / 2, data.length);
-            mCamera.stopPreview();
             mPreviewDone.open();
         }
     }
@@ -350,6 +349,7 @@
             mCamera.setPreviewTexture(mSurfaceTexture);
             noTimeout = waitForPreviewDone();
             assertTrue("Timeout waiting for new preview callback!", noTimeout);
+            mCamera.stopPreview();
             terminateMessageLooper();
 
             // Check the order: setPreviewTexture->startPreview.
@@ -359,6 +359,7 @@
             mCamera.startPreview();
             noTimeout = waitForPreviewDone();
             assertTrue("Timeout waiting for new preview callback!", noTimeout);
+            mCamera.stopPreview();
 
             // Check the order: setting preview display to null->startPreview->
             // setPreviewTexture.
@@ -368,6 +369,7 @@
             mCamera.setPreviewTexture(mSurfaceTexture);
             noTimeout = waitForPreviewDone();
             assertTrue("Timeout waiting for new preview callback!", noTimeout);
+            mCamera.stopPreview();
             terminateMessageLooper();
         }
     };
@@ -396,6 +398,7 @@
             assertTrue("Timeout waiting for new frame from SurfaceTexture!", noTimeout);
             noTimeout = waitForPreviewDone();
             assertTrue("Timeout waiting for new preview callback!",noTimeout);
+            mCamera.stopPreview();
 
             mGLView.requestRender();
             terminateMessageLooper();
@@ -413,6 +416,7 @@
             assertTrue("Timeout waiting for new frame from SurfaceTexture!", noTimeout);
             noTimeout = waitForPreviewDone();
             assertTrue("Timeout waiting for new preview callback!", noTimeout);
+            mCamera.stopPreview();
 
             mGLView.requestRender();
 
@@ -424,6 +428,7 @@
             mCamera.setPreviewTexture(mSurfaceTexture);
             noTimeout = waitForPreviewDone();
             assertTrue(noTimeout);
+            mCamera.stopPreview();
             terminateMessageLooper();
         }
     };