Skip to content

Commit a55dd5b

Browse files
committed
Vectorize --enable_host_bluetooth
The flag now means whether a particular device has a bluetooth implementation that relies on the host (netsimd or rootcanal). The old code enabled the host bluetooth functionality even when the flag value was false if netsim_bt was enabled. This behavior is maintained after this change. Equivalent to ag/Icc9f4f7b00dc3df87c810edd2565d2f71ea2af95 Bug=b/441907863
1 parent 6861d6f commit a55dd5b

File tree

10 files changed

+50
-41
lines changed

10 files changed

+50
-41
lines changed

base/cvd/cuttlefish/host/commands/assemble_cvd/assemble_cvd_flags.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,8 +131,9 @@ DEFINE_vec(
131131
pause_in_bootloader, CF_DEFAULTS_PAUSE_IN_BOOTLOADER?"true":"false",
132132
"Stop the bootflow in u-boot. You can continue the boot by connecting "
133133
"to the device console and typing in \"boot\".");
134-
DEFINE_bool(enable_host_bluetooth, CF_DEFAULTS_ENABLE_HOST_BLUETOOTH,
135-
"Enable the rootcanal which is Bluetooth emulator in the host.");
134+
DEFINE_vec(enable_host_bluetooth,
135+
fmt::format("{}", CF_DEFAULTS_ENABLE_HOST_BLUETOOTH),
136+
"Enable the rootcanal which is Bluetooth emulator in the host.");
136137
DEFINE_int32(
137138
rootcanal_instance_num, CF_DEFAULTS_ROOTCANAL_INSTANCE_NUM,
138139
"If it is greater than 0, use an existing rootcanal instance which is "

base/cvd/cuttlefish/host/commands/assemble_cvd/assemble_cvd_flags.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ DECLARE_vec(use_allocd);
6262
DECLARE_vec(use_cvdalloc);
6363
DECLARE_vec(enable_minimal_mode);
6464
DECLARE_vec(pause_in_bootloader);
65-
DECLARE_bool(enable_host_bluetooth);
65+
DECLARE_vec(enable_host_bluetooth);
6666
DECLARE_int32(rootcanal_instance_num);
6767
DECLARE_string(rootcanal_args);
6868
DECLARE_bool(enable_host_nfc);

base/cvd/cuttlefish/host/commands/assemble_cvd/flags.cc

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -411,17 +411,18 @@ Result<CuttlefishConfig> InitializeCuttlefishConfiguration(
411411
tmp_config_obj.set_ap_rootfs_image(ap_rootfs_image);
412412
tmp_config_obj.set_ap_kernel_image(FLAGS_ap_kernel_image);
413413

414+
// get flag default values and store into map
415+
auto name_to_default_value = CurrentFlagsToDefaultValue();
416+
// old flags but vectorized for multi-device instances
417+
int32_t instances_size = instance_nums.size();
418+
414419
// netsim flags allow all radios or selecting a specific radio
415420
bool is_any_netsim = FLAGS_netsim || FLAGS_netsim_bt || FLAGS_netsim_uwb;
416421
bool is_bt_netsim = FLAGS_netsim || FLAGS_netsim_bt;
417422
bool is_uwb_netsim = FLAGS_netsim || FLAGS_netsim_uwb;
418423

419-
// crosvm should create fifos for Bluetooth
420-
tmp_config_obj.set_enable_host_bluetooth(FLAGS_enable_host_bluetooth ||
421-
is_bt_netsim);
422-
423-
// rootcanal and bt_connector should handle Bluetooth (instead of netsim)
424-
tmp_config_obj.set_enable_host_bluetooth_connector(FLAGS_enable_host_bluetooth && !is_bt_netsim);
424+
std::vector<bool> enable_host_bluetooth_vec =
425+
CF_EXPECT(GET_FLAG_BOOL_VALUE(enable_host_bluetooth));
425426

426427
tmp_config_obj.set_enable_host_nfc(FLAGS_enable_host_nfc);
427428
tmp_config_obj.set_enable_host_nfc_connector(FLAGS_enable_host_nfc);
@@ -434,10 +435,6 @@ Result<CuttlefishConfig> InitializeCuttlefishConfiguration(
434435

435436
tmp_config_obj.set_enable_automotive_proxy(FLAGS_enable_automotive_proxy);
436437

437-
// get flag default values and store into map
438-
auto name_to_default_value = CurrentFlagsToDefaultValue();
439-
// old flags but vectorized for multi-device instances
440-
int32_t instances_size = instance_nums.size();
441438
std::vector<std::string> gnss_file_paths =
442439
CF_EXPECT(GET_FLAG_STR_VALUE(gnss_file_path));
443440
std::vector<std::string> fixed_location_file_paths =
@@ -982,6 +979,14 @@ Result<CuttlefishConfig> InitializeCuttlefishConfiguration(
982979

983980
instance.set_ethernet_tap_name(iface_config.ethernet_tap.name);
984981

982+
// crosvm should create fifos for Bluetooth
983+
bool enable_host_bluetooth = enable_host_bluetooth_vec[instance_index];
984+
// or is_bt_netsim is here for backwards compatibility only
985+
instance.set_has_bluetooth(enable_host_bluetooth || is_bt_netsim);
986+
// rootcanal and bt_connector should handle Bluetooth (instead of netsim)
987+
instance.set_enable_host_bluetooth_connector(enable_host_bluetooth &&
988+
!is_bt_netsim);
989+
985990
instance.set_uuid(FLAGS_uuid);
986991

987992
instance.set_environment_name(environment_name);

base/cvd/cuttlefish/host/commands/run_cvd/launch/bluetooth_connector.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ namespace cuttlefish {
4040
Result<std::optional<MonitorCommand>> BluetoothConnector(
4141
const CuttlefishConfig& config,
4242
const CuttlefishConfig::InstanceSpecific& instance) {
43-
if (!config.enable_host_bluetooth_connector()) {
43+
if (!instance.enable_host_bluetooth_connector()) {
4444
return {};
4545
}
4646
std::vector<std::string> fifo_paths = {

base/cvd/cuttlefish/host/commands/run_cvd/launch/root_canal.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,8 @@ class RootCanal : public CommandSource {
127127
// SetupFeature
128128
std::string Name() const override { return "RootCanal"; }
129129
bool Enabled() const override {
130-
return config_.enable_host_bluetooth_connector() && instance_.start_rootcanal();
130+
return instance_.enable_host_bluetooth_connector() &&
131+
instance_.start_rootcanal();
131132
}
132133

133134
private:

base/cvd/cuttlefish/host/libs/config/cuttlefish_config.cpp

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -211,23 +211,6 @@ void CuttlefishConfig::set_pica_uci_port(int pica_uci_port) {
211211
(*dictionary_)[kPicaUciPort] = pica_uci_port;
212212
}
213213

214-
static constexpr char kEnableHostBluetooth[] = "enable_host_bluetooth";
215-
void CuttlefishConfig::set_enable_host_bluetooth(bool enable_host_bluetooth) {
216-
(*dictionary_)[kEnableHostBluetooth] = enable_host_bluetooth;
217-
}
218-
bool CuttlefishConfig::enable_host_bluetooth() const {
219-
return (*dictionary_)[kEnableHostBluetooth].asBool();
220-
}
221-
222-
static constexpr char kEnableHostBluetoothConnector[] =
223-
"enable_host_bluetooth_connector";
224-
void CuttlefishConfig::set_enable_host_bluetooth_connector(bool enable_host_bluetooth) {
225-
(*dictionary_)[kEnableHostBluetoothConnector] = enable_host_bluetooth;
226-
}
227-
bool CuttlefishConfig::enable_host_bluetooth_connector() const {
228-
return (*dictionary_)[kEnableHostBluetoothConnector].asBool();
229-
}
230-
231214
static constexpr char kEnableAutomotiveProxy[] = "enable_automotive_proxy";
232215
void CuttlefishConfig::set_enable_automotive_proxy(
233216
bool enable_automotive_proxy) {

base/cvd/cuttlefish/host/libs/config/cuttlefish_config.h

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -125,20 +125,13 @@ class CuttlefishConfig {
125125
void set_enable_host_uwb_connector(bool enable_host_uwb);
126126
bool enable_host_uwb_connector() const;
127127

128-
void set_enable_host_bluetooth(bool enable_host_bluetooth);
129-
bool enable_host_bluetooth() const;
130-
131128
void set_enable_automotive_proxy(bool enable_automotive_proxy);
132129
bool enable_automotive_proxy() const;
133130

134131
// The vsock port used by vhal_proxy_server
135132
void set_vhal_proxy_server_port(int port);
136133
int vhal_proxy_server_port() const;
137134

138-
// Bluetooth is enabled by bt_connector and rootcanal
139-
void set_enable_host_bluetooth_connector(bool enable_host_bluetooth);
140-
bool enable_host_bluetooth_connector() const;
141-
142135
void set_enable_host_nfc(bool enable_host_nfc);
143136
bool enable_host_nfc() const;
144137

@@ -323,6 +316,10 @@ class CuttlefishConfig {
323316
std::string ethernet_bridge_name() const;
324317
std::string ethernet_mac() const;
325318
std::string ethernet_ipv6() const;
319+
bool has_bluetooth() const;
320+
// Bluetooth is enabled by bt_connector and rootcanal
321+
bool enable_host_bluetooth_connector() const;
322+
326323
uint32_t session_id() const;
327324
bool use_allocd() const;
328325
bool use_cvdalloc() const;
@@ -674,6 +671,8 @@ class CuttlefishConfig {
674671
void set_ethernet_bridge_name(const std::string& set_ethernet_bridge_name);
675672
void set_ethernet_mac(const std::string& mac);
676673
void set_ethernet_ipv6(const std::string& ip);
674+
void set_has_bluetooth(bool has_bluetooth);
675+
void set_enable_host_bluetooth_connector(bool enable_host_bluetooth);
677676
void set_session_id(uint32_t session_id);
678677
void set_use_allocd(bool use_allocd);
679678
void set_use_cvdalloc(bool use_cvdalloc);

base/cvd/cuttlefish/host/libs/config/cuttlefish_config_instance.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1596,6 +1596,26 @@ void CuttlefishConfig::MutableInstanceSpecific::set_ethernet_ipv6(
15961596
(*Dictionary())[kEthernetIPV6] = ip;
15971597
}
15981598

1599+
static constexpr char kHasBluetooth[] = "has_bluetooth";
1600+
bool CuttlefishConfig::InstanceSpecific::has_bluetooth() const {
1601+
return (*Dictionary())[kHasBluetooth].asBool();
1602+
}
1603+
void CuttlefishConfig::MutableInstanceSpecific::set_has_bluetooth(
1604+
bool has_bluetooth) {
1605+
(*Dictionary())[kHasBluetooth] = has_bluetooth;
1606+
}
1607+
1608+
static constexpr char kRequiresHostBluetoothConnector[] =
1609+
"enable_host_bluetooth_connector";
1610+
bool CuttlefishConfig::InstanceSpecific::enable_host_bluetooth_connector()
1611+
const {
1612+
return (*Dictionary())[kRequiresHostBluetoothConnector].asBool();
1613+
}
1614+
void CuttlefishConfig::MutableInstanceSpecific::
1615+
set_enable_host_bluetooth_connector(bool enable_host_bluetooth) {
1616+
(*Dictionary())[kRequiresHostBluetoothConnector] = enable_host_bluetooth;
1617+
}
1618+
15991619
static constexpr char kUseAllocd[] = "use_allocd";
16001620
bool CuttlefishConfig::InstanceSpecific::use_allocd() const {
16011621
return (*Dictionary())[kUseAllocd].asBool();

base/cvd/cuttlefish/host/libs/vm_manager/crosvm_manager.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -809,7 +809,7 @@ Result<std::vector<MonitorCommand>> CrosvmManager::StartCommands(
809809
instance.PerInstanceInternalPath("gatekeeper_fifo_vm.in"));
810810

811811
// /dev/hvc5 = bt
812-
if (config.enable_host_bluetooth()) {
812+
if (instance.has_bluetooth()) {
813813
crosvm_cmd.AddHvcReadWrite(
814814
instance.PerInstanceInternalPath("bt_fifo_vm.out"),
815815
instance.PerInstanceInternalPath("bt_fifo_vm.in"));

base/cvd/cuttlefish/host/libs/vm_manager/qemu_manager.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -568,7 +568,7 @@ Result<std::vector<MonitorCommand>> QemuManager::StartCommands(
568568
// /dev/hvc4 = gatekeeper
569569
add_hvc(instance.PerInstanceInternalPath("gatekeeper_fifo_vm"));
570570
// /dev/hvc5 = bt
571-
if (config.enable_host_bluetooth()) {
571+
if (instance.has_bluetooth()) {
572572
add_hvc(instance.PerInstanceInternalPath("bt_fifo_vm"));
573573
} else {
574574
add_hvc_sink();

0 commit comments

Comments
 (0)