Merge "Make controller prop and default commands configurable in rootcanal" am: f5ea069e16 am: 54968a1386 am: 8866f1babb

Original change: https://android-review.googlesource.com/c/device/google/cuttlefish/+/1629489

Change-Id: Iad832738a37eb6d7be4ccb276a2969ba5db6c9cc
diff --git a/build/Android.bp b/build/Android.bp
index a8f856d..2a28d4d 100644
--- a/build/Android.bp
+++ b/build/Android.bp
@@ -79,6 +79,11 @@
     "webrtc_operator",
 ]
 
+cvd_bluetooth_config_files = [
+    "controller_properties.json",
+    "default_commands",
+]
+
 cvd_host_tests = [
     "cuttlefish_net_tests",
     "modem_simulator_test",
@@ -153,7 +158,8 @@
     multilib: {
         common: {
             deps: cvd_host_webrtc_assets +
-                cvd_host_model_simulator_files,
+                cvd_host_model_simulator_files +
+                cvd_bluetooth_config_files,
         },
     },
 
diff --git a/guest/hals/bt/data/Android.bp b/guest/hals/bt/data/Android.bp
new file mode 100644
index 0000000..9f9cf4e
--- /dev/null
+++ b/guest/hals/bt/data/Android.bp
@@ -0,0 +1,5 @@
+prebuilt_etc_host {
+    name: "default_commands",
+    src: "default_commands",
+    sub_dir: "rootcanal/data",
+}
\ No newline at end of file
diff --git a/guest/hals/bt/data/default_commands b/guest/hals/bt/data/default_commands
new file mode 100644
index 0000000..9182915
--- /dev/null
+++ b/guest/hals/bt/data/default_commands
@@ -0,0 +1,4 @@
+add beacon be:ac:01:55:00:01 1000
+add_device_to_phy 0 1
+add beacon be:ac:01:55:00:02 1000
+add_device_to_phy 1 1
\ No newline at end of file
diff --git a/host/commands/assemble_cvd/flags.cc b/host/commands/assemble_cvd/flags.cc
index ee90855..e034d11 100644
--- a/host/commands/assemble_cvd/flags.cc
+++ b/host/commands/assemble_cvd/flags.cc
@@ -97,6 +97,14 @@
 DEFINE_bool(enable_host_bluetooth, true,
             "Enable the root-canal which is Bluetooth emulator in the host.");
 
+DEFINE_string(bluetooth_controller_properties_file,
+              "etc/rootcanal/data/controller_properties.json",
+              "The configuartion file path for root-canal which is a Bluetooth "
+              "emulator.");
+DEFINE_string(
+    bluetooth_default_commands_file, "etc/rootcanal/data/default_commands",
+    "The default commands which root-canal executes when it launches.");
+
 /**
  *
  * crosvm sandbox feature requires /var/empty and seccomp directory
@@ -687,6 +695,10 @@
     instance.set_rootcanal_hci_port(7300 + num - 1);
     instance.set_rootcanal_link_port(7400 + num - 1);
     instance.set_rootcanal_test_port(7500 + num - 1);
+    instance.set_rootcanal_config_file(
+        FLAGS_bluetooth_controller_properties_file);
+    instance.set_rootcanal_default_commands_file(
+        FLAGS_bluetooth_default_commands_file);
 
     instance.set_device_title(FLAGS_device_title);
 
diff --git a/host/commands/run_cvd/launch.cc b/host/commands/run_cvd/launch.cc
index a4cabca..0445620 100644
--- a/host/commands/run_cvd/launch.cc
+++ b/host/commands/run_cvd/launch.cc
@@ -192,6 +192,12 @@
   command.AddParameter(instance.rootcanal_hci_port());
   // Link server port
   command.AddParameter(instance.rootcanal_link_port());
+  // Bluetooth controller properties file
+  command.AddParameter("--controller_properties_file=",
+                       instance.rootcanal_config_file());
+  // Default commands file
+  command.AddParameter("--default_commands_file=",
+                       instance.rootcanal_default_commands_file());
 
   process_monitor->AddCommand(std::move(command));
   return;
diff --git a/host/libs/config/cuttlefish_config.h b/host/libs/config/cuttlefish_config.h
index d4e6090..aaf01fb 100644
--- a/host/libs/config/cuttlefish_config.h
+++ b/host/libs/config/cuttlefish_config.h
@@ -370,6 +370,9 @@
     int rootcanal_hci_port() const;
     int rootcanal_link_port() const;
     int rootcanal_test_port() const;
+    std::string rootcanal_config_file() const;
+    std::string rootcanal_default_commands_file() const;
+
     std::string adb_device_name() const;
     std::string device_title() const;
     std::string gnss_file_path() const;
@@ -475,6 +478,9 @@
     void set_rootcanal_hci_port(int rootcanal_hci_port);
     void set_rootcanal_link_port(int rootcanal_link_port);
     void set_rootcanal_test_port(int rootcanal_test_port);
+    void set_rootcanal_config_file(const std::string& rootcanal_config_file);
+    void set_rootcanal_default_commands_file(
+        const std::string& rootcanal_default_commands_file);
     void set_device_title(const std::string& title);
     void set_mobile_bridge_name(const std::string& mobile_bridge_name);
     void set_mobile_tap_name(const std::string& mobile_tap_name);
diff --git a/host/libs/config/cuttlefish_config_instance.cpp b/host/libs/config/cuttlefish_config_instance.cpp
index 97fa6c8..ee18700 100644
--- a/host/libs/config/cuttlefish_config_instance.cpp
+++ b/host/libs/config/cuttlefish_config_instance.cpp
@@ -379,6 +379,29 @@
   (*Dictionary())[kRootcanalTestPort] = rootcanal_test_port;
 }
 
+static constexpr char kRootcanalConfigFile[] = "rootcanal_config_file";
+std::string CuttlefishConfig::InstanceSpecific::rootcanal_config_file() const {
+  return (*Dictionary())[kRootcanalConfigFile].asString();
+}
+void CuttlefishConfig::MutableInstanceSpecific::set_rootcanal_config_file(
+    const std::string& rootcanal_config_file) {
+  (*Dictionary())[kRootcanalConfigFile] =
+      DefaultHostArtifactsPath(rootcanal_config_file);
+}
+
+static constexpr char kRootcanalDefaultCommandsFile[] =
+    "rootcanal_default_commands_file";
+std::string
+CuttlefishConfig::InstanceSpecific::rootcanal_default_commands_file() const {
+  return (*Dictionary())[kRootcanalDefaultCommandsFile].asString();
+}
+void CuttlefishConfig::MutableInstanceSpecific::
+    set_rootcanal_default_commands_file(
+        const std::string& rootcanal_default_commands_file) {
+  (*Dictionary())[kRootcanalDefaultCommandsFile] =
+      DefaultHostArtifactsPath(rootcanal_default_commands_file);
+}
+
 static constexpr char kWebrtcDeviceId[] = "webrtc_device_id";
 void CuttlefishConfig::MutableInstanceSpecific::set_webrtc_device_id(
     const std::string& id) {