HWComposer: Unset mPrimaryHwcDisplayId after disconnectDisplay
We should unset mPrimaryHwcDisplayId when disconnectDisplay()
is called for the primary display. This can happen during
display change and it will cause isHeadless() to be false.
This way SurfaceFlinger will call getPrimaryDisplayId()
which will crash.
Test: HWComposerTest
Test: libsurfaceflinger_unittest
Bug: 195900759
Change-Id: I3c00e3b864fef6f1b088ffae0539c1ad16b7492b
diff --git a/services/surfaceflinger/DisplayHardware/HWComposer.cpp b/services/surfaceflinger/DisplayHardware/HWComposer.cpp
index 256bca9..35dd2a8 100644
--- a/services/surfaceflinger/DisplayHardware/HWComposer.cpp
+++ b/services/surfaceflinger/DisplayHardware/HWComposer.cpp
@@ -669,6 +669,13 @@
mPhysicalDisplayIdMap.erase(hwcDisplayId);
mDisplayData.erase(displayId);
+
+ // Reset the primary display ID if we're disconnecting it.
+ // This way isHeadless() will return false, which is necessary
+ // because getPrimaryDisplayId() will crash.
+ if (mPrimaryHwcDisplayId == hwcDisplayId) {
+ mPrimaryHwcDisplayId.reset();
+ }
}
status_t HWComposer::setOutputBuffer(HalVirtualDisplayId displayId, const sp<Fence>& acquireFence,