SF: avoid a nullptr access in RefreshRateOverlay / HDR overlay
Bug: 302312658
Test: presubmit + manual
Change-Id: I3a69e4520be7f52779e1f92e5621a6138de08797
diff --git a/services/surfaceflinger/HdrSdrRatioOverlay.cpp b/services/surfaceflinger/HdrSdrRatioOverlay.cpp
index 186e878..dfb1c1e 100644
--- a/services/surfaceflinger/HdrSdrRatioOverlay.cpp
+++ b/services/surfaceflinger/HdrSdrRatioOverlay.cpp
@@ -96,7 +96,18 @@
return buffer;
}
-HdrSdrRatioOverlay::HdrSdrRatioOverlay()
+std::unique_ptr<HdrSdrRatioOverlay> HdrSdrRatioOverlay::create() {
+ std::unique_ptr<HdrSdrRatioOverlay> overlay =
+ std::make_unique<HdrSdrRatioOverlay>(ConstructorTag{});
+ if (overlay->initCheck()) {
+ return overlay;
+ }
+
+ ALOGE("%s: Failed to create HdrSdrRatioOverlay", __func__);
+ return {};
+}
+
+HdrSdrRatioOverlay::HdrSdrRatioOverlay(ConstructorTag)
: mSurfaceControl(
SurfaceControlHolder::createSurfaceControlHolder(String8("HdrSdrRatioOverlay"))) {
if (!mSurfaceControl) {
@@ -109,6 +120,10 @@
.apply();
}
+bool HdrSdrRatioOverlay::initCheck() const {
+ return mSurfaceControl != nullptr;
+}
+
void HdrSdrRatioOverlay::changeHdrSdrRatio(float currentHdrSdrRatio) {
mCurrentHdrSdrRatio = currentHdrSdrRatio;
animate();