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.h b/services/surfaceflinger/DisplayHardware/HWComposer.h
index 0a090da..66edd65 100644
--- a/services/surfaceflinger/DisplayHardware/HWComposer.h
+++ b/services/surfaceflinger/DisplayHardware/HWComposer.h
@@ -231,9 +231,12 @@
virtual Hwc2::Composer* getComposer() const = 0;
- // Returns the first display connected at boot. It cannot be disconnected, which implies an
- // internal connection type. Its connection via HWComposer::onHotplug, which in practice is
- // immediately after HWComposer construction, must occur before any call to this function.
+ // Returns the first display connected at boot. Its connection via HWComposer::onHotplug,
+ // which in practice is immediately after HWComposer construction, must occur before any
+ // call to this function.
+ // The primary display can be temporarily disconnected from the perspective
+ // of this class. Callers must not call getPrimaryHwcDisplayId() or getPrimaryDisplayId()
+ // if isHeadless().
//
// TODO(b/182939859): Remove special cases for primary display.
virtual hal::HWDisplayId getPrimaryHwcDisplayId() const = 0;