Camera: Fix testMixedBurstReprocessing

For mixed burst reprocesssing, the images and results may not come
in the same order so for this case, we need to use timestamps to
find corresponding image and result.

Bug: 23771691
Change-Id: I6a302dd7436e079e37d1efd9c6a59aa8afbdc939
diff --git a/tests/tests/hardware/src/android/hardware/camera2/cts/ReprocessCaptureTest.java b/tests/tests/hardware/src/android/hardware/camera2/cts/ReprocessCaptureTest.java
index 8a60dc2..dd49c8d 100644
--- a/tests/tests/hardware/src/android/hardware/camera2/cts/ReprocessCaptureTest.java
+++ b/tests/tests/hardware/src/android/hardware/camera2/cts/ReprocessCaptureTest.java
@@ -1211,6 +1211,9 @@
             throw new IllegalArgumentException("isReprocessCaptures must have at least 1 capture.");
         }
 
+        boolean hasReprocessRequest = false;
+        boolean hasRegularRequest = false;
+
         TotalCaptureResult[] results = new TotalCaptureResult[isReprocessCaptures.length];
         for (int i = 0; i < isReprocessCaptures.length; i++) {
             // submit a capture and get the result if this entry is a reprocess capture.
@@ -1219,6 +1222,9 @@
                         /*inputResult*/null);
                 mImageWriter.queueInputImage(
                         mFirstImageReaderListener.getImage(CAPTURE_TIMEOUT_MS));
+                hasReprocessRequest = true;
+            } else {
+                hasRegularRequest = true;
             }
         }
 
@@ -1232,7 +1238,24 @@
         ImageResultHolder[] holders = new ImageResultHolder[isReprocessCaptures.length];
         for (int i = 0; i < isReprocessCaptures.length; i++) {
             Image image = getReprocessOutputImageReaderListener().getImage(CAPTURE_TIMEOUT_MS);
-            holders[i] = new ImageResultHolder(image, finalResults[i]);
+            if (hasReprocessRequest && hasRegularRequest) {
+                // If there are mixed requests, images and results may not be in the same order.
+                for (int j = 0; j < finalResults.length; j++) {
+                    if (finalResults[j] != null &&
+                            finalResults[j].get(CaptureResult.SENSOR_TIMESTAMP) ==
+                            image.getTimestamp()) {
+                        holders[i] = new ImageResultHolder(image, finalResults[j]);
+                        finalResults[j] = null;
+                        break;
+                    }
+                }
+
+                assertNotNull("Cannot find a result matching output image's timestamp: " +
+                        image.getTimestamp(), holders[i]);
+            } else {
+                // If no mixed requests, images and results should be in the same order.
+                holders[i] = new ImageResultHolder(image, finalResults[i]);
+            }
         }
 
         return holders;