Pass the daemon flag through the config.

Test: build and run locally
Bug: 123592422
Change-Id: I1dd8fb3ba720420453d6cb0ace4430a9cb00d1e6
diff --git a/host/commands/launch/main.cc b/host/commands/launch/main.cc
index 64900df..05d14d6 100644
--- a/host/commands/launch/main.cc
+++ b/host/commands/launch/main.cc
@@ -544,6 +544,7 @@
   tmp_config_obj.set_socket_forward_proxy_binary(
       FLAGS_socket_forward_proxy_binary);
   tmp_config_obj.set_socket_vsock_proxy_binary(FLAGS_socket_vsock_proxy_binary);
+  tmp_config_obj.set_run_as_daemon(FLAGS_daemon);
 
   if(!AdbUsbEnabled(tmp_config_obj)) {
     tmp_config_obj.disable_usb_adb();
@@ -858,7 +859,7 @@
   }
 
   LOG(INFO) << "The following files contain useful debugging information:";
-  if (FLAGS_daemon) {
+  if (config->run_as_daemon()) {
     LOG(INFO) << "  Launcher log: " << config->launcher_log_path();
   }
   LOG(INFO) << "  Android's logcat output: " << config->logcat_path();
@@ -877,7 +878,7 @@
     return cvd::LauncherExitCodes::kMonitorCreationFailed;
   }
   cvd::SharedFD foreground_launcher_pipe;
-  if (FLAGS_daemon) {
+  if (config->run_as_daemon()) {
     foreground_launcher_pipe = DaemonizeLauncher(*config);
     if (!foreground_launcher_pipe->IsOpen()) {
       return LauncherExitCodes::kDaemonizationError;
@@ -904,7 +905,9 @@
   // Only subscribe to boot events if running as daemon
   process_monitor.StartSubprocess(
       GetKernelLogMonitorCommand(*config,
-                                 FLAGS_daemon ? &boot_events_pipe : nullptr),
+                                 config->run_as_daemon()
+                                   ? &boot_events_pipe
+                                   : nullptr),
       GetOnSubprocessExitCallback(*config));
 
   SetUpHandlingOfBootEvents(&process_monitor, boot_events_pipe,
diff --git a/host/libs/config/cuttlefish_config.cpp b/host/libs/config/cuttlefish_config.cpp
index 59f2d4a..af7b36e 100644
--- a/host/libs/config/cuttlefish_config.cpp
+++ b/host/libs/config/cuttlefish_config.cpp
@@ -137,6 +137,8 @@
 const char* kVirtualUsbManagerBinary = "virtual_usb_manager_binary";
 const char* kSocketForwardProxyBinary = "socket_forward_proxy_binary";
 const char* kSocketVsockProxyBinary = "socket_vsock_proxy_binary";
+
+const char* kRunAsDaemon = "run_as_daemon";
 }  // namespace
 
 namespace vsoc {
@@ -659,6 +661,14 @@
   (*dictionary_)[kSocketVsockProxyBinary] = socket_vsock_proxy_binary;
 }
 
+bool CuttlefishConfig::run_as_daemon() const {
+  return (*dictionary_)[kRunAsDaemon].asBool();
+}
+
+void CuttlefishConfig::set_run_as_daemon(bool run_as_daemon) {
+  (*dictionary_)[kRunAsDaemon] = run_as_daemon;
+}
+
 // Creates the (initially empty) config object and populates it with values from
 // the config file if the CUTTLEFISH_CONFIG_FILE env variable is present.
 // Returns nullptr if there was an error loading from file
diff --git a/host/libs/config/cuttlefish_config.h b/host/libs/config/cuttlefish_config.h
index c5d5aff..24a14d8 100644
--- a/host/libs/config/cuttlefish_config.h
+++ b/host/libs/config/cuttlefish_config.h
@@ -248,6 +248,9 @@
   void set_socket_vsock_proxy_binary(const std::string& binary);
   std::string socket_vsock_proxy_binary() const;
 
+  void set_run_as_daemon(bool run_as_daemon);
+  bool run_as_daemon() const;
+
  private:
   std::unique_ptr<Json::Value> dictionary_;