Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 23aa7a93 authored by Hsin-chen Chuang's avatar Hsin-chen Chuang
Browse files

floss: SetFlossEnabled: Walk through virtual index instead of real index

Originally we list the real index, convert them into virtual, and
pass to Start/StopBluetooth. This is clearly wrong.

Bug: 306322786
Tag: #floss
Test: mmm packages/modules/Bluetooth
Test: Call SetFlossEnabled through btclient

Change-Id: I4ef271da99eb35f20e1d3126974768c2d665e306
parent da9b9a3e
Loading
Loading
Loading
Loading
+6 −6
Original line number Diff line number Diff line
@@ -156,15 +156,15 @@ impl IBluetoothManager for BluetoothManager {
                warn!("Failed to stop bluetoothd: {}", e);
            }
            migrate::migrate_bluez_devices();
            for hci in config_util::list_hci_devices() {
                if config_util::is_hci_n_enabled(hci) {
                    let _ = self.proxy.start_bluetooth(VirtualHciIndex(hci));
            for hci in self.proxy.get_valid_adapters().iter().map(|a| a.virt_hci) {
                if config_util::is_hci_n_enabled(hci.to_i32()) {
                    self.proxy.start_bluetooth(hci);
                }
            }
        } else if prev != enabled {
            for hci in config_util::list_hci_devices() {
                if config_util::is_hci_n_enabled(hci) {
                    let _ = self.proxy.stop_bluetooth(VirtualHciIndex(hci));
            for hci in self.proxy.get_valid_adapters().iter().map(|a| a.virt_hci) {
                if config_util::is_hci_n_enabled(hci.to_i32()) {
                    self.proxy.stop_bluetooth(hci);
                }
            }
            migrate::migrate_floss_devices();
+0 −29
Original line number Diff line number Diff line
@@ -147,10 +147,6 @@ pub fn set_default_adapter(adapter: i32) -> bool {
    }
}

pub fn list_hci_devices() -> Vec<i32> {
    hci_devices_string_to_int(list_hci_devices_string())
}

fn list_hci_devices_string() -> Vec<String> {
    match std::fs::read_dir(HCI_DEVICES_DIR) {
        Ok(entries) => entries
@@ -177,13 +173,6 @@ pub fn get_devpath_for_hci(hci: i32) -> Option<String> {
    }
}

fn hci_devices_string_to_int(devices: Vec<String>) -> Vec<i32> {
    devices
        .into_iter()
        .filter_map(|e| if e.starts_with("hci") { e[3..].parse::<i32>().ok() } else { None })
        .collect()
}

pub fn list_pid_files(pid_dir: &str) -> Vec<String> {
    match std::fs::read_dir(pid_dir) {
        Ok(entries) => entries
@@ -327,22 +316,4 @@ mod tests {
            true
        );
    }

    #[test]
    fn test_hci_devices_string_to_int_none() {
        assert_eq!(hci_devices_string_to_int(vec!["somethingelse".to_string()]), Vec::<i32>::new());
    }

    #[test]
    fn test_hci_devices_string_to_int_one() {
        assert_eq!(hci_devices_string_to_int(vec!["hci0".to_string()]), vec![0]);
    }

    #[test]
    fn test_hci_devices_string_to_int_two() {
        assert_eq!(
            hci_devices_string_to_int(vec!["hci0".to_string(), "hci1".to_string()]),
            vec![0, 1]
        );
    }
}