Avoid unnecessary error messages from hwcomposer under crosvm

When the vnc server isn't started, there is no vsock server on the
host for the hwcomposer to connect to, so it fails its connection
attempt, logs it and continues working without sending the composed
frames to the host. Instead, it shouldn't even try to connect when the
server is known to not be available.

Test: run locally
Bug: 132114593
Change-Id: I3ec2bc0b2e97ba73c87ccbced710480d42846872
diff --git a/guest/hals/hwcomposer/cutf_cvm/Android.bp b/guest/hals/hwcomposer/cutf_cvm/Android.bp
index 09bccd8..5a54d14 100644
--- a/guest/hals/hwcomposer/cutf_cvm/Android.bp
+++ b/guest/hals/hwcomposer/cutf_cvm/Android.bp
@@ -30,6 +30,7 @@
     export_include_dirs: ["."],
     static_libs: ["libyuv_static", "hwcomposer_common"],
     shared_libs: [
+        "cuttlefish_auto_resources",
         "liblog",
         "libhardware",
         "libbase",
diff --git a/guest/hals/hwcomposer/cutf_cvm/base_composer.cpp b/guest/hals/hwcomposer/cutf_cvm/base_composer.cpp
index 23be7e1..a1f1597 100644
--- a/guest/hals/hwcomposer/cutf_cvm/base_composer.cpp
+++ b/guest/hals/hwcomposer/cutf_cvm/base_composer.cpp
@@ -77,30 +77,34 @@
 }
 
 FrameBuffer::FrameBuffer()
-    : screen_server_(cvd::SharedFD::VsockClient(
-          2, property_get_int32("ro.boot.vsock_frames_port", 5580),
-          SOCK_STREAM)),
-      broadcast_thread_([this]() { BroadcastLoop(); }) {
-  if (screen_server_->IsOpen()) {
-    // TODO(b/128842613): Get this info from the configuration server
-    int32_t screen_params[4];
-    auto res = screen_server_->Read(screen_params, sizeof(screen_params));
-    if (res == sizeof(screen_params)) {
-      x_res_ = screen_params[0];
-      y_res_ = screen_params[1];
-      dpi_ = screen_params[2];
-      refresh_rate_ = screen_params[3];
+    : broadcast_thread_([this]() { BroadcastLoop(); }) {
+  auto vsock_frames_port = property_get_int32("ro.boot.vsock_frames_port", -1);
+  if (vsock_frames_port > 0) {
+    screen_server_ = cvd::SharedFD::VsockClient(2, vsock_frames_port,
+                                                SOCK_STREAM);
+    if (screen_server_->IsOpen()) {
+      // TODO(b/128842613): Get this info from the configuration server
+      int32_t screen_params[4];
+      auto res = screen_server_->Read(screen_params, sizeof(screen_params));
+      if (res == sizeof(screen_params)) {
+        x_res_ = screen_params[0];
+        y_res_ = screen_params[1];
+        dpi_ = screen_params[2];
+        refresh_rate_ = screen_params[3];
+      } else {
+        LOG(ERROR) << "Unable to get screen configuration parameters from screen "
+                   << "server (" << res << "): " << screen_server_->StrError();
+      }
     } else {
-      LOG(ERROR) << "Unable to get screen configuration parameters from screen "
-                 << "server (" << res << "): " << screen_server_->StrError();
+      LOG(ERROR) << "Unable to connect to screen server: "
+                 << screen_server_->StrError();
     }
   } else {
-    LOG(ERROR) << "Unable to connect to screen server: "
-               << screen_server_->StrError();
+    LOG(INFO) << "No screen server configured, operating on headless mode";
   }
   // This needs to happen no matter what, otherwise there won't be a buffer for
   // the set calls to compose on.
-  inner_buffer_ = std::vector<char>(FrameBuffer::buffer_size() * 8);
+  inner_buffer_ = std::vector<char>(buffer_size() * 8);
 }
 
 FrameBuffer::~FrameBuffer() {
diff --git a/host/commands/launch/flags.cc b/host/commands/launch/flags.cc
index ed50269..6c0867d 100644
--- a/host/commands/launch/flags.cc
+++ b/host/commands/launch/flags.cc
@@ -486,7 +486,7 @@
   tmp_config_obj.set_logcat_vsock_port(FLAGS_logcat_vsock_port);
   tmp_config_obj.set_config_server_port(FLAGS_config_server_port);
   tmp_config_obj.set_frames_vsock_port(FLAGS_frames_vsock_port);
-  if (!tmp_config_obj.enable_ivserver()) {
+  if (!tmp_config_obj.enable_ivserver() && tmp_config_obj.enable_vnc_server()) {
     tmp_config_obj.add_kernel_cmdline(concat("androidboot.vsock_frames_port=",
                                              FLAGS_frames_vsock_port));
   }