Merge "EmulatedCamera: Fix scaler crop region default for maximum resolution sensor pixel mode results." into sc-qpr1-dev
diff --git a/devices/EmulatedCamera/hwl/EmulatedRequestState.cpp b/devices/EmulatedCamera/hwl/EmulatedRequestState.cpp
index a1e553a..e7c62f9 100644
--- a/devices/EmulatedCamera/hwl/EmulatedRequestState.cpp
+++ b/devices/EmulatedCamera/hwl/EmulatedRequestState.cpp
@@ -969,8 +969,11 @@
   }
   if (zoom_ratio_supported_) {
     result->result_metadata->Set(ANDROID_CONTROL_ZOOM_RATIO, &zoom_ratio_, 1);
-    result->result_metadata->Set(ANDROID_SCALER_CROP_REGION,
-                                 scaler_crop_region_default_,
+    int32_t* chosen_crop_region = scaler_crop_region_default_;
+    if (sensor_pixel_mode_ == ANDROID_SENSOR_PIXEL_MODE_MAXIMUM_RESOLUTION) {
+      chosen_crop_region = scaler_crop_region_max_resolution_;
+    }
+    result->result_metadata->Set(ANDROID_SCALER_CROP_REGION, chosen_crop_region,
                                  ARRAY_SIZE(scaler_crop_region_default_));
   }
   if (report_extended_scene_mode_) {
@@ -2285,6 +2288,23 @@
       return BAD_VALUE;
     }
 
+    if (SupportsCapability(
+            ANDROID_REQUEST_AVAILABLE_CAPABILITIES_ULTRA_HIGH_RESOLUTION_SENSOR)) {
+      ret = static_metadata_->Get(
+          ANDROID_SENSOR_INFO_ACTIVE_ARRAY_SIZE_MAXIMUM_RESOLUTION, &entry);
+      if ((ret == OK) && (entry.count == 4)) {
+        scaler_crop_region_max_resolution_[0] = entry.data.i32[0];
+        scaler_crop_region_max_resolution_[1] = entry.data.i32[1];
+        scaler_crop_region_max_resolution_[2] = entry.data.i32[2];
+        scaler_crop_region_max_resolution_[3] = entry.data.i32[3];
+      } else {
+        ALOGE(
+            "%s: Sensor pixel array size maximum resolution is not available!",
+            __FUNCTION__);
+        return BAD_VALUE;
+      }
+    }
+
     if (available_requests_.find(ANDROID_SCALER_CROP_REGION) ==
         available_requests_.end()) {
       ALOGE(
diff --git a/devices/EmulatedCamera/hwl/EmulatedRequestState.h b/devices/EmulatedCamera/hwl/EmulatedRequestState.h
index 1591422..1987bfa 100644
--- a/devices/EmulatedCamera/hwl/EmulatedRequestState.h
+++ b/devices/EmulatedCamera/hwl/EmulatedRequestState.h
@@ -262,6 +262,7 @@
   bool report_rotate_and_crop_ = false;
   uint8_t rotate_and_crop_ = ANDROID_SCALER_ROTATE_AND_CROP_NONE;
   int32_t scaler_crop_region_default_[4] = {0, 0, 0, 0};
+  int32_t scaler_crop_region_max_resolution_[4] = {0, 0, 0, 0};
   std::set<uint8_t> available_rotate_crop_modes_;
 
   // android.statistics.*