Fix intermediate preview size selection for legacy.

Bug: 19606058
Change-Id: I4bf4c5bafdd5a50e46aa117b76d96381a3b82e5d
diff --git a/core/java/android/hardware/camera2/legacy/RequestThreadManager.java b/core/java/android/hardware/camera2/legacy/RequestThreadManager.java
index 691798f..cf3ed1c 100644
--- a/core/java/android/hardware/camera2/legacy/RequestThreadManager.java
+++ b/core/java/android/hardware/camera2/legacy/RequestThreadManager.java
@@ -413,6 +413,9 @@
         mParams.setPreviewFpsRange(bestRange[Camera.Parameters.PREVIEW_FPS_MIN_INDEX],
                 bestRange[Camera.Parameters.PREVIEW_FPS_MAX_INDEX]);
 
+        Size smallestSupportedJpegSize = calculatePictureSize(mCallbackOutputs,
+                callbackOutputSizes, mParams);
+
         if (previewOutputSizes.size() > 0) {
 
             Size largestOutput = SizeAreaComparator.findLargestByArea(previewOutputSizes);
@@ -420,6 +423,9 @@
             // Find largest jpeg dimension - assume to have the same aspect ratio as sensor.
             Size largestJpegDimen = ParameterUtils.getLargestSupportedJpegSizeByArea(mParams);
 
+            Size chosenJpegDimen = (smallestSupportedJpegSize != null) ? smallestSupportedJpegSize
+                    : largestJpegDimen;
+
             List<Size> supportedPreviewSizes = ParameterUtils.convertSizeList(
                     mParams.getSupportedPreviewSizes());
 
@@ -431,7 +437,7 @@
             for (Size s : supportedPreviewSizes) {
                 long currArea = s.getWidth() * s.getHeight();
                 long bestArea = bestPreviewDimen.getWidth() * bestPreviewDimen.getHeight();
-                if (checkAspectRatiosMatch(largestJpegDimen, s) && (currArea < bestArea &&
+                if (checkAspectRatiosMatch(chosenJpegDimen, s) && (currArea < bestArea &&
                         currArea >= largestOutputArea)) {
                     bestPreviewDimen = s;
                 }
@@ -452,8 +458,6 @@
             }
         }
 
-        Size smallestSupportedJpegSize = calculatePictureSize(mCallbackOutputs,
-                callbackOutputSizes, mParams);
         if (smallestSupportedJpegSize != null) {
             /*
              * Set takePicture size to the smallest supported JPEG size large enough