drm_hwcomposer: Add headless mode support

Headless mode required to keep SurfaceFlinger alive when all displays are
disconnected, Without headless mode Android will continuously crash.
Only single internal (primary) display is required to be in HEADLESS mode
to prevent the crash. See [1].

[1]: https://source.android.com/devices/graphics/hotplug#handling-common-scenarios
Closes: https://gitlab.freedesktop.org/drm-hwcomposer/drm-hwcomposer/-/issues/57
Signed-off-by: Roman Stratiienko <roman.o.stratiienko@globallogic.com>
diff --git a/hwc2_device/HwcDisplay.h b/hwc2_device/HwcDisplay.h
index 6f46f5d..c3e0f6e 100644
--- a/hwc2_device/HwcDisplay.h
+++ b/hwc2_device/HwcDisplay.h
@@ -200,6 +200,16 @@
     return false;
   }
 
+  /* Headless mode required to keep SurfaceFlinger alive when all display are
+   * disconnected, Without headless mode Android will continuously crash.
+   * Only single internal (primary) display is required to be in HEADLESS mode
+   * to prevent the crash. See:
+   * https://source.android.com/devices/graphics/hotplug#handling-common-scenarios
+   */
+  bool IsInHeadlessMode() {
+    return handle_ == 0 && connector_->state() != DRM_MODE_CONNECTED;
+  }
+
  private:
   enum ClientFlattenningState : int32_t {
     Disabled = -3,