Optimize testSharedSurfaceSwitch

Remove some unnecessary sleep statements and reduce the timer for the
required one.

With this change, the test time for Oriole on the stable build
(10337921) goes down from ~4m 18s to ~19s (~93% improvement).

To make sure there are no accidental regressions being introduced, I ran
the test for 50 iterations and each time it completed successfully and
finished within 18.8 - 19.2s.

Test: atest MultiViewTest#testSharedSurfaceSwitch
Bug: 287260354
Change-Id: I911f976e84b0dd4d3f86317c1cac4b1afb6384d4
diff --git a/tests/camera/src/android/hardware/camera2/cts/MultiViewTest.java b/tests/camera/src/android/hardware/camera2/cts/MultiViewTest.java
index 50f3b95..625d97c 100644
--- a/tests/camera/src/android/hardware/camera2/cts/MultiViewTest.java
+++ b/tests/camera/src/android/hardware/camera2/cts/MultiViewTest.java
@@ -16,33 +16,38 @@
 
 package android.hardware.camera2.cts;
 
-import static android.hardware.camera2.cts.CameraTestUtils.*;
-import static android.hardware.cts.helpers.CameraUtils.*;
+import static android.hardware.camera2.cts.CameraTestUtils.ImageDropperListener;
+import static android.hardware.camera2.cts.CameraTestUtils.MAX_READER_IMAGES;
+import static android.hardware.camera2.cts.CameraTestUtils.SimpleCaptureCallback;
+import static android.hardware.camera2.cts.CameraTestUtils.assertEquals;
+import static android.hardware.camera2.cts.CameraTestUtils.assertNotNull;
+import static android.hardware.camera2.cts.CameraTestUtils.assertTrue;
+import static android.hardware.camera2.cts.CameraTestUtils.fail;
+import static android.hardware.camera2.cts.CameraTestUtils.makeImageReader;
+import static android.hardware.cts.helpers.CameraUtils.getAvailableSurfaceTexture;
 
 import static org.junit.Assert.assertArrayEquals;
 
 import android.graphics.Bitmap;
 import android.graphics.ImageFormat;
 import android.graphics.SurfaceTexture;
+import android.hardware.HardwareBuffer;
 import android.hardware.camera2.CameraCharacteristics;
 import android.hardware.camera2.CameraDevice;
-import android.hardware.camera2.CameraAccessException;
-import android.hardware.camera2.CaptureRequest;
 import android.hardware.camera2.CaptureFailure;
+import android.hardware.camera2.CaptureRequest;
 import android.hardware.camera2.TotalCaptureResult;
 import android.hardware.camera2.cts.CameraTestUtils.ImageVerifierListener;
 import android.hardware.camera2.cts.helpers.StaticMetadata;
 import android.hardware.camera2.cts.rs.BitmapUtils;
 import android.hardware.camera2.cts.testcases.Camera2MultiViewTestCase;
-import android.hardware.camera2.cts.testcases.Camera2MultiViewTestCase.CameraPreviewListener;
 import android.hardware.camera2.params.OutputConfiguration;
-import android.hardware.HardwareBuffer;
 import android.media.Image;
 import android.media.ImageReader;
 import android.media.ImageWriter;
 import android.opengl.Matrix;
-import android.os.SystemClock;
 import android.os.ConditionVariable;
+import android.os.SystemClock;
 import android.util.Log;
 import android.util.Size;
 import android.view.Surface;
@@ -50,15 +55,15 @@
 
 import com.android.ex.camera2.blocking.BlockingCameraManager.BlockingOpenException;
 
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.HashMap;
 import java.util.List;
 
-import org.junit.runner.RunWith;
-import org.junit.runners.Parameterized;
-import org.junit.Test;
-
 /**
  * CameraDevice test by using combination of SurfaceView, TextureView and ImageReader
  */
@@ -816,15 +821,13 @@
         assertTrue("Unable to start preview", previewDone);
         mTextureView[0].setSurfaceTextureListener(null);
 
-        SystemClock.sleep(PREVIEW_TIME_MS);
-
         for (int i = 0; i < switchCount; i++) {
             //Add one more output surface while preview is streaming
             surfaceSharedOutput.addSurface(surfaces[1]);
             updateOutputConfiguration(cameraId, surfaceSharedOutput);
             int sequenceId = updateRepeatingRequest(cameraId, outputConfigurations, resultListener);
 
-            SystemClock.sleep(PREVIEW_TIME_MS);
+            SystemClock.sleep(100);
 
             //Try to remove the shared surface while while we still have active requests that
             //use it as output.
@@ -844,7 +847,6 @@
             checkForLastFrameInSequence(lastSequenceFrameNumber, resultListener);
             updateOutputConfiguration(cameraId, surfaceSharedOutput);
 
-            SystemClock.sleep(PREVIEW_TIME_MS);
         }
 
         stopPreview(cameraId);