Remove undefined behavior in getDisplayDecorationSupport
I3b46bae068ac3d482881dac96972a40e46581d34 introduced a bug when
converting between two different versions of DisplayDecorationSupport.
We attempt to set the member fields of an std::optional object before it
has a value. Use emplace to insert a value into the object.
Unfortunately, fixing this reveals b/241278870, which is a serious
regression. On the other hand, the current checked in code results in
undefined behavior, so prevent that. Once b/241278870 is fixed, it will
be simple to remove the check for 'false'.
Bug: 241277093
Test: manual
Change-Id: I53a56b792d99bb72d49d32b5d8f071353dae1b41
diff --git a/libs/gui/SurfaceComposerClient.cpp b/libs/gui/SurfaceComposerClient.cpp
index d365851..52217df 100644
--- a/libs/gui/SurfaceComposerClient.cpp
+++ b/libs/gui/SurfaceComposerClient.cpp
@@ -2720,12 +2720,16 @@
ComposerServiceAIDL::getComposerService()->getDisplayDecorationSupport(displayToken,
&gsupport);
std::optional<DisplayDecorationSupport> support;
- if (status.isOk() && gsupport.has_value()) {
- support->format = static_cast<aidl::android::hardware::graphics::common::PixelFormat>(
- gsupport->format);
- support->alphaInterpretation =
+ // TODO (b/241277093): Remove `false && ` once b/241278870 is fixed.
+ if (false && status.isOk() && gsupport.has_value()) {
+ support.emplace(DisplayDecorationSupport{
+ .format =
+ static_cast<aidl::android::hardware::graphics::common::PixelFormat>(
+ gsupport->format),
+ .alphaInterpretation =
static_cast<aidl::android::hardware::graphics::common::AlphaInterpretation>(
- gsupport->alphaInterpretation);
+ gsupport->alphaInterpretation)
+ });
}
return support;
}