usb: Sort supported formats for Nami

GetQualifiedFormats will cause sorted resolutions to be unordered.
Move sort part to GetQualifiedFormats.

BUG=b:120077778
TEST=run ITS scenes 0 pass

Change-Id: Iad927e0881f35036f222d041914526b07e67a718
Reviewed-on: https://chromium-review.googlesource.com/c/1362700
Reviewed-by: Shik Chen <shik@chromium.org>
Commit-Queue: Heng-ruey Hsu <henryhsu@chromium.org>
Tested-by: Heng-ruey Hsu <henryhsu@chromium.org>
diff --git a/hal/usb/libcamera_hal.gyp b/hal/usb/libcamera_hal.gyp
index a6e2ab7..24f3efb 100644
--- a/hal/usb/libcamera_hal.gyp
+++ b/hal/usb/libcamera_hal.gyp
@@ -13,6 +13,7 @@
         'libcamera_exif',
         'libcamera_metadata',
         'libcamera_timezone',
+        'libcros_config',
         'libjda',
         'libsync',
         'libyuv',
diff --git a/hal/usb/stream_format.cc b/hal/usb/stream_format.cc
index 5ac1a0d..bef2db6 100644
--- a/hal/usb/stream_format.cc
+++ b/hal/usb/stream_format.cc
@@ -7,8 +7,11 @@
 
 #include <algorithm>
 #include <cmath>
+#include <memory>
+#include <string>
 #include <tuple>
 
+#include <chromeos-config/libcros_config/cros_config.h>
 #include <linux/videodev2.h>
 #include <system/graphics.h>
 
@@ -137,6 +140,21 @@
       qualified_formats.push_back(supported_format);
     }
   }
+
+  // Only sort resolutions for nami in M71 branch.
+  auto config = std::make_unique<brillo::CrosConfig>();
+  if (config->InitModel()) {
+    std::string name;
+    if (config->GetString("/identity", "platform-name", &name) &&
+        name == "Nami") {
+      // Sort the resolution from high to low for easier reading and consistent
+      // of different camera modules.
+      // CTS uses the first 2 resolutions to create streams. It also let CTS
+      // choose high resolutions.
+      std::sort(qualified_formats.begin(), qualified_formats.end());
+      std::reverse(qualified_formats.begin(), qualified_formats.end());
+    }
+  }
   return qualified_formats;
 }