SF: Do not assume existence of primary display

This CL adds checks and assertions to DisplayDevice and IBinder lookup
for the primary display. It also removes HWC_DISPLAY_PRIMARY constants
in the SurfaceFlinger class.

Bug: 74619554
Test: libsurfaceflinger_unittest
Change-Id: I966d3fd8843e0392cc48a39610d2105d80453747
diff --git a/services/surfaceflinger/BufferLayer.cpp b/services/surfaceflinger/BufferLayer.cpp
index 36eb9e3..3032fa5 100644
--- a/services/surfaceflinger/BufferLayer.cpp
+++ b/services/surfaceflinger/BufferLayer.cpp
@@ -326,7 +326,7 @@
     if (presentFence->isValid()) {
         mTimeStats.setPresentFence(layerName, mCurrentFrameNumber, presentFence);
         mFrameTracker.setActualPresentFence(std::shared_ptr<FenceTime>(presentFence));
-    } else {
+    } else if (mFlinger->getHwComposer().isConnected(HWC_DISPLAY_PRIMARY)) {
         // The HWC doesn't support present fences, so use the refresh
         // timestamp instead.
         const nsecs_t actualPresentTime =
@@ -706,7 +706,9 @@
         mProducer->setMaxDequeuedBufferCount(2);
     }
 
-    updateTransformHint(mFlinger->getDefaultDisplayDevice());
+    if (const auto display = mFlinger->getDefaultDisplayDevice()) {
+        updateTransformHint(display);
+    }
 }
 
 // ---------------------------------------------------------------------------