[SurfaceFlinger] Checking nullptr for HWC layer.
There were several places where we didn't check nullptr when accessing HWC
layer, which results in function call on nullptr when external display was
disconnected. This patch makes sure we check HWC layer before calling functions
on it.
BUG: 80325674
Test: Build, flash, boot
Change-Id: I302ad4eeea5c196daadcdccb596dac60b02d3845
Merged-In: I302ad4eeea5c196daadcdccb596dac60b02d3845
diff --git a/services/surfaceflinger/Layer.cpp b/services/surfaceflinger/Layer.cpp
index 2595ec1..1dc3f4c 100644
--- a/services/surfaceflinger/Layer.cpp
+++ b/services/surfaceflinger/Layer.cpp
@@ -486,6 +486,9 @@
void Layer::setGeometry(const sp<const DisplayDevice>& displayDevice, uint32_t z)
{
const auto hwcId = displayDevice->getHwcDisplayId();
+ if (!hasHwcLayer(hwcId)) {
+ return;
+ }
auto& hwcInfo = getBE().mHwcLayers[hwcId];
// enable this layer
@@ -1977,6 +1980,9 @@
}
void Layer::writeToProto(LayerProto* layerInfo, int32_t hwcId) {
+ if (!hasHwcLayer(hwcId)) {
+ return;
+ }
writeToProto(layerInfo, LayerVector::StateSet::Drawing);
const auto& hwcInfo = getBE().mHwcLayers.at(hwcId);