Move libvirt and qemu flags to the launcher.

This removes the gflags dependency from vm_manager.

Bug: 114301828
Test: Run aosp_cf_x86_phone-userdebug locally, check config json.
Change-Id: Ifcbffdeb2ffe0e56d842053a1e55062960134143
diff --git a/host/commands/launch/main.cc b/host/commands/launch/main.cc
index 0cf4f28..aef2f25 100644
--- a/host/commands/launch/main.cc
+++ b/host/commands/launch/main.cc
@@ -184,6 +184,12 @@
 DEFINE_string(setupwizard_mode, "DISABLED",
 	      "One of DISABLED,OPTIONAL,REQUIRED");
 
+DEFINE_string(qemu_binary,
+              "/usr/bin/qemu-system-x86_64",
+              "The qemu binary to use");
+DEFINE_string(hypervisor_uri, "qemu:///system", "Hypervisor cannonical uri.");
+DEFINE_bool(log_xml, false, "Log the XML machine configuration");
+
 DECLARE_string(config_file);
 
 namespace {
@@ -617,6 +623,10 @@
   config->set_disable_dac_security(FLAGS_disable_dac_security);
   config->set_disable_app_armor_security(FLAGS_disable_app_armor_security);
 
+  config->set_qemu_binary(FLAGS_qemu_binary);
+  config->set_hypervisor_uri(FLAGS_hypervisor_uri);
+  config->set_log_xml(FLAGS_log_xml);
+
   if(!AdbUsbEnabled()) {
     config->disable_usb_adb();
   }
diff --git a/host/libs/config/cuttlefish_config.cpp b/host/libs/config/cuttlefish_config.cpp
index d1507f8..0ebe82d 100644
--- a/host/libs/config/cuttlefish_config.cpp
+++ b/host/libs/config/cuttlefish_config.cpp
@@ -119,6 +119,10 @@
 
 const char* kAdbMode = "adb_mode";
 const char* kSetupWizardMode = "setupwizard_mode";
+
+const char* kLogXml = "log_xml";
+const char* kHypervisorUri = "hypervisor_uri";
+const char* kQemuBinary = "qemu_binary";
 }  // namespace
 
 namespace vsoc {
@@ -488,6 +492,30 @@
   (*dictionary_)[kSetupWizardMode] = mode;
 }
 
+bool CuttlefishConfig::log_xml() const {
+  return (*dictionary_)[kLogXml].asBool();
+}
+
+void CuttlefishConfig::set_log_xml(bool log_xml) {
+  (*dictionary_)[kLogXml] = log_xml;
+}
+
+std::string CuttlefishConfig::hypervisor_uri() const {
+  return (*dictionary_)[kHypervisorUri].asString();
+}
+
+void CuttlefishConfig::set_hypervisor_uri(const std::string& hypervisor_uri) {
+  (*dictionary_)[kHypervisorUri] = hypervisor_uri;
+}
+
+std::string CuttlefishConfig::qemu_binary() const {
+  return (*dictionary_)[kQemuBinary].asString();
+}
+
+void CuttlefishConfig::set_qemu_binary(const std::string& qemu_binary) {
+  (*dictionary_)[kQemuBinary] = qemu_binary;
+}
+
 // Creates the (initially empty) config object and populates it with values from
 // the config file if the --config_file command line argument 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 cbe280d..6b24372 100644
--- a/host/libs/config/cuttlefish_config.h
+++ b/host/libs/config/cuttlefish_config.h
@@ -192,6 +192,15 @@
   void set_setupwizard_mode(const std::string& title);
   std::string setupwizard_mode() const;
 
+  void set_log_xml(bool log_xml);
+  bool log_xml() const;
+
+  void set_hypervisor_uri(const std::string& hypervisor_uri);
+  std::string hypervisor_uri() const;
+
+  void set_qemu_binary(const std::string& qemu_binary);
+  std::string qemu_binary() const;
+
  private:
   std::unique_ptr<Json::Value> dictionary_;
 
diff --git a/host/libs/vm_manager/Android.bp b/host/libs/vm_manager/Android.bp
index 3ab302d..0d077ea 100644
--- a/host/libs/vm_manager/Android.bp
+++ b/host/libs/vm_manager/Android.bp
@@ -32,7 +32,6 @@
     ],
     static_libs: [
         "libxml2",
-        "libgflags",
         "libcuttlefish_host_config",
         "libjsoncpp",
     ],
@@ -43,4 +42,4 @@
     name: "cf_qemu.sh",
     srcs: ["cf_qemu.sh"],
     defaults: ["cuttlefish_host_only"],
-}
\ No newline at end of file
+}
diff --git a/host/libs/vm_manager/libvirt_manager.cpp b/host/libs/vm_manager/libvirt_manager.cpp
index a331dc2..9c67391 100644
--- a/host/libs/vm_manager/libvirt_manager.cpp
+++ b/host/libs/vm_manager/libvirt_manager.cpp
@@ -24,7 +24,6 @@
 #include <sstream>
 #include <string>
 
-#include <gflags/gflags.h>
 #include <glog/logging.h>
 #include <libxml/tree.h>
 
@@ -33,9 +32,6 @@
 #include "common/libs/utils/users.h"
 #include "host/libs/config/cuttlefish_config.h"
 
-DEFINE_string(hypervisor_uri, "qemu:///system", "Hypervisor cannonical uri.");
-DEFINE_bool(log_xml, false, "Log the XML machine configuration");
-
 // A lot of useful information about the document created here can be found on
 // these websites:
 // - https://libvirt.org/formatdomain.html
@@ -261,10 +257,10 @@
   xmlNewProp(bend, xc("model"), xc("random"));
 }
 
-std::string GetLibvirtCommand() {
+static std::string GetLibvirtCommand(vsoc::CuttlefishConfig* config) {
   std::string cmd = "virsh";
-  if (!FLAGS_hypervisor_uri.empty()) {
-    cmd += " -c " + FLAGS_hypervisor_uri;
+  if (!config->hypervisor_uri().empty()) {
+    cmd += " -c " + config->hypervisor_uri();
   }
   return cmd;
 }
@@ -349,11 +345,11 @@
   : VmManager(config) {}
 
 bool LibvirtManager::Start() {
-  std::string start_command = GetLibvirtCommand();
+  std::string start_command = GetLibvirtCommand(config_);
   start_command += " create /dev/fd/0";
 
   std::string xml = BuildXmlConfig(config_);
-  if (FLAGS_log_xml) {
+  if (config_->log_xml()) {
     LOG(INFO) << "Using XML:\n" << xml;
   }
 
@@ -376,7 +372,7 @@
 }
 
 bool LibvirtManager::Stop() {
-  auto stop_command = GetLibvirtCommand();
+  auto stop_command = GetLibvirtCommand(config_);
   stop_command += " destroy " + config_->instance_name();
   return std::system(stop_command.c_str()) == 0;
 }
diff --git a/host/libs/vm_manager/qemu_manager.cpp b/host/libs/vm_manager/qemu_manager.cpp
index 7d7d92b..afd5848 100644
--- a/host/libs/vm_manager/qemu_manager.cpp
+++ b/host/libs/vm_manager/qemu_manager.cpp
@@ -30,7 +30,6 @@
 #include <thread>
 #include <vector>
 
-#include <gflags/gflags.h>
 #include <glog/logging.h>
 
 #include "common/libs/fs/shared_select.h"
@@ -39,10 +38,6 @@
 #include "common/libs/utils/users.h"
 #include "host/libs/config/cuttlefish_config.h"
 
-DEFINE_string(qemu_binary,
-              "/usr/bin/qemu-system-x86_64",
-              "The qemu binary to use");
-
 namespace vm_manager {
 
 namespace {
@@ -58,7 +53,7 @@
 
 pid_t BuildAndRunQemuCmd(vsoc::CuttlefishConfig* config) {
   // Set the config values in the environment
-  LogAndSetEnv("qemu_binary", FLAGS_qemu_binary);
+  LogAndSetEnv("qemu_binary", config->qemu_binary());
   LogAndSetEnv("instance_name", config->instance_name());
   LogAndSetEnv("memory_mb", std::to_string(config->memory_mb()));
   LogAndSetEnv("cpus", std::to_string(config->cpus()));