Do not crash on invalid dataspace
Prior logic caused device to crash when setting the dataspace for a
layer to hdr on a non-hdr device. Update to log the failure and perform
a no-op to match framework APIs.
Bug: 140029823
Test: build, boot, CtsViewTestCases:android.view.cts.ASurfaceControlTest
Change-Id: I9baf88a6d787e043b440ad4c2ebeb4c7a1fd90a2
diff --git a/native/android/surface_control.cpp b/native/android/surface_control.cpp
index 8fe4fec..53c0122 100644
--- a/native/android/surface_control.cpp
+++ b/native/android/surface_control.cpp
@@ -100,7 +100,11 @@
return getWideColorSupport(surfaceControl);
// These data space need HDR support.
case HAL_DATASPACE_BT2020_PQ:
- return getHdrSupport(surfaceControl);
+ if (!getHdrSupport(surfaceControl)) {
+ ALOGE("Invalid dataspace - device does not support hdr");
+ return false;
+ }
+ return true;
default:
return false;
}
@@ -458,10 +462,11 @@
CHECK_NOT_NULL(aSurfaceControl);
sp<SurfaceControl> surfaceControl = ASurfaceControl_to_SurfaceControl(aSurfaceControl);
- LOG_ALWAYS_FATAL_IF(!isDataSpaceValid(surfaceControl, aDataSpace), "invalid dataspace");
-
+ if (!isDataSpaceValid(surfaceControl, aDataSpace)) {
+ ALOGE("Failed to set buffer dataspace - invalid dataspace");
+ return;
+ }
Transaction* transaction = ASurfaceTransaction_to_Transaction(aSurfaceTransaction);
-
transaction->setDataspace(surfaceControl, static_cast<ui::Dataspace>(aDataSpace));
}
@@ -527,7 +532,10 @@
CHECK_NOT_NULL(aSurfaceControl);
sp<SurfaceControl> surfaceControl = ASurfaceControl_to_SurfaceControl(aSurfaceControl);
- LOG_ALWAYS_FATAL_IF(!isDataSpaceValid(surfaceControl, dataspace), "invalid dataspace");
+ if (!isDataSpaceValid(surfaceControl, dataspace)) {
+ ALOGE("Failed to set buffer dataspace - invalid dataspace");
+ return;
+ }
Transaction* transaction = ASurfaceTransaction_to_Transaction(aSurfaceTransaction);
half3 color;