CameraITS: fix largest size logic

Bug: 30705041
Change-Id: Ibc20aa802806458bd2e9f88226655e81d4022854
diff --git a/apps/CameraITS/pymodules/its/objects.py b/apps/CameraITS/pymodules/its/objects.py
index ac384fb..b2a49aa 100644
--- a/apps/CameraITS/pymodules/its/objects.py
+++ b/apps/CameraITS/pymodules/its/objects.py
@@ -183,7 +183,8 @@
         ar = match_ar_size[0] / float(match_ar_size[1])
         out_sizes = [s for s in out_sizes if
                 abs(ar - s[0] / float(s[1])) <= AR_TOLERANCE]
-    out_sizes.sort(reverse=True)
+    out_sizes.sort(reverse=True, key=lambda s: s[0]) # 1st pass, sort by width
+    out_sizes.sort(reverse=True, key=lambda s: s[0]*s[1]) # sort by area
     return out_sizes
 
 def set_filter_off_or_fast_if_possible(props, req, available_modes, filter):
diff --git a/apps/CtsVerifier/src/com/android/cts/verifier/camera/its/ItsService.java b/apps/CtsVerifier/src/com/android/cts/verifier/camera/its/ItsService.java
index 49525b7..6f54821 100644
--- a/apps/CtsVerifier/src/com/android/cts/verifier/camera/its/ItsService.java
+++ b/apps/CtsVerifier/src/com/android/cts/verifier/camera/its/ItsService.java
@@ -1161,12 +1161,13 @@
         } else {
             // No surface(s) specified at all.
             // Default: a single output surface which is full-res YUV.
-            Size sizes[] = ItsUtils.getYuvOutputSizes(mCameraCharacteristics);
+            Size maxYuvSize = ItsUtils.getMaxOutputSize(
+                    mCameraCharacteristics, ImageFormat.YUV_420_888);
             numSurfaces = backgroundRequest ? 2 : 1;
 
             outputSizes = new Size[numSurfaces];
             outputFormats = new int[numSurfaces];
-            outputSizes[0] = sizes[0];
+            outputSizes[0] = maxYuvSize;
             outputFormats[0] = ImageFormat.YUV_420_888;
             if (backgroundRequest) {
                 outputSizes[1] = new Size(640, 480);
diff --git a/apps/CtsVerifier/src/com/android/cts/verifier/camera/its/ItsUtils.java b/apps/CtsVerifier/src/com/android/cts/verifier/camera/its/ItsUtils.java
index 8763223..b0eaf35 100644
--- a/apps/CtsVerifier/src/com/android/cts/verifier/camera/its/ItsUtils.java
+++ b/apps/CtsVerifier/src/com/android/cts/verifier/camera/its/ItsUtils.java
@@ -153,10 +153,13 @@
         }
 
         Size maxSize = sizes[0];
+        int maxArea = maxSize.getWidth() * maxSize.getHeight();
         for (int i = 1; i < sizes.length; i++) {
-            if (sizes[i].getWidth() * sizes[i].getHeight() >
-                    maxSize.getWidth() * maxSize.getHeight()) {
+            int area = sizes[i].getWidth() * sizes[i].getHeight();
+            if (area > maxArea ||
+                    (area == maxArea && sizes[i].getWidth() > maxSize.getWidth())) {
                 maxSize = sizes[i];
+                maxArea = area;
             }
         }