drm_hwcomposer: Handle primary display in GetDisplayConnectionType()

Primary display should always be internal.

Closes: https://gitlab.freedesktop.org/drm-hwcomposer/drm-hwcomposer/-/issues/58
Signed-off-by: Roman Stratiienko <roman.o.stratiienko@globallogic.com>
diff --git a/hwc2_device/HwcDisplay.cpp b/hwc2_device/HwcDisplay.cpp
index 8936136..f18e00d 100644
--- a/hwc2_device/HwcDisplay.cpp
+++ b/hwc2_device/HwcDisplay.cpp
@@ -708,7 +708,14 @@
 
 #if PLATFORM_SDK_VERSION > 29
 HWC2::Error HwcDisplay::GetDisplayConnectionType(uint32_t *outType) {
-  if (connector_->internal())
+  if (IsInHeadlessMode()) {
+    *outType = static_cast<uint32_t>(HWC2::DisplayConnectionType::Internal);
+    return HWC2::Error::None;
+  }
+  /* Primary display should be always internal,
+   * otherwise SF will be unhappy and will crash
+   */
+  if (connector_->internal() || handle_ == kPrimaryDisplay)
     *outType = static_cast<uint32_t>(HWC2::DisplayConnectionType::Internal);
   else if (connector_->external())
     *outType = static_cast<uint32_t>(HWC2::DisplayConnectionType::External);
diff --git a/hwc2_device/HwcDisplay.h b/hwc2_device/HwcDisplay.h
index c3e0f6e..76456b7 100644
--- a/hwc2_device/HwcDisplay.h
+++ b/hwc2_device/HwcDisplay.h
@@ -33,6 +33,8 @@
 class Backend;
 class DrmHwcTwo;
 
+inline constexpr uint32_t kPrimaryDisplay = 0;
+
 class HwcDisplay {
  public:
   HwcDisplay(ResourceManager *resource_manager, DrmDevice *drm,
@@ -207,7 +209,8 @@
    * https://source.android.com/devices/graphics/hotplug#handling-common-scenarios
    */
   bool IsInHeadlessMode() {
-    return handle_ == 0 && connector_->state() != DRM_MODE_CONNECTED;
+    return handle_ == kPrimaryDisplay &&
+           connector_->state() != DRM_MODE_CONNECTED;
   }
 
  private: