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

Commit f3e95f0d authored by Abhishek Pandit-Subedi's avatar Abhishek Pandit-Subedi Committed by Automerger Merge Worker
Browse files

Merge changes I934f7646,I02cac651 am: b4c02d11 am: cbca6291 am: 9b26218c am: 0ed66b91

parents f01ee2a1 0ed66b91
Loading
Loading
Loading
Loading
+26 −8
Original line number Diff line number Diff line
@@ -5,7 +5,7 @@ use std::sync::{Arc, Mutex};
use crate::callbacks::BtGattCallback;
use crate::ClientContext;
use crate::{console_red, console_yellow, print_error, print_info};
use bt_topshim::btif::BtTransport;
use bt_topshim::btif::{BtConnectionState, BtTransport};
use btstack::bluetooth::{BluetoothDevice, IBluetooth, IBluetoothQA};
use btstack::bluetooth_gatt::IBluetoothGatt;
use btstack::uuid::{Profile, UuidHelper, UuidWrapper};
@@ -171,7 +171,7 @@ fn build_commands() -> HashMap<String, CommandOption> {
    command_options.insert(
        String::from("list"),
        CommandOption {
            rules: vec![String::from("list <bonded|found>")],
            rules: vec![String::from("list <bonded|found|connected>")],
            description: String::from(
                "List bonded or found remote devices. Use: list <bonded|found>",
            ),
@@ -552,7 +552,7 @@ impl CommandHandler {
                        name: String::from("Classic Device"),
                    };

                    let (name, alias, device_type, class, bonded, connected, uuids) = {
                    let (name, alias, device_type, class, bonded, connection_state, uuids) = {
                        let ctx = self.context.lock().unwrap();
                        let adapter = ctx.adapter_dbus.as_ref().unwrap();

@@ -561,10 +561,14 @@ impl CommandHandler {
                        let alias = adapter.get_remote_alias(device.clone());
                        let class = adapter.get_remote_class(device.clone());
                        let bonded = adapter.get_bond_state(device.clone());
                        let connected = adapter.get_connection_state(device.clone());
                        let connection_state = match adapter.get_connection_state(device.clone()) {
                            BtConnectionState::NotConnected => "Not Connected",
                            BtConnectionState::ConnectedOnly => "Connected",
                            _ => "Connected and Paired",
                        };
                        let uuids = adapter.get_remote_uuids(device.clone());

                        (name, alias, device_type, class, bonded, connected, uuids)
                        (name, alias, device_type, class, bonded, connection_state, uuids)
                    };

                    let uuid_helper = UuidHelper::new();
@@ -573,8 +577,8 @@ impl CommandHandler {
                    print_info!("Alias: {}", alias);
                    print_info!("Type: {:?}", device_type);
                    print_info!("Class: {}", class);
                    print_info!("Bonded: {}", bonded);
                    print_info!("Connected: {}", connected);
                    print_info!("Bond State: {:?}", bonded);
                    print_info!("Connection State: {}", connection_state);
                    print_info!(
                        "Uuids: {}",
                        DisplayList(
@@ -828,7 +832,7 @@ impl CommandHandler {
            return;
        }

        enforce_arg_len(args, 1, "list <bonded|found>", || match &args[0][0..] {
        enforce_arg_len(args, 1, "list <bonded|found|connected>", || match &args[0][0..] {
            "bonded" => {
                print_info!("Known bonded devices:");
                let devices = self
@@ -849,6 +853,20 @@ impl CommandHandler {
                    print_info!("[{:17}] {}", key, val.name);
                }
            }
            "connected" => {
                print_info!("Connected devices:");
                let devices = self
                    .context
                    .lock()
                    .unwrap()
                    .adapter_dbus
                    .as_ref()
                    .unwrap()
                    .get_connected_devices();
                for device in devices.iter() {
                    print_info!("[{:17}] {}", device.address, device.name);
                }
            }
            _ => {
                println!("Invalid argument '{}'", args[0]);
            }
+16 −3
Original line number Diff line number Diff line
//! D-Bus proxy implementations of the APIs.

use bt_topshim::btif::{
    BtDeviceType, BtPropertyType, BtSspVariant, BtStatus, BtTransport, Uuid, Uuid128Bit,
    BtBondState, BtConnectionState, BtDeviceType, BtPropertyType, BtSspVariant, BtStatus,
    BtTransport, Uuid, Uuid128Bit,
};
use bt_topshim::profiles::gatt::GattStatus;
use bt_topshim::profiles::socket::SocketType;
@@ -49,6 +50,8 @@ fn make_object_path(idx: i32, name: &str) -> dbus::Path {
    dbus::Path::new(format!("/org/chromium/bluetooth/hci{}/{}", idx, name)).unwrap()
}

impl_dbus_arg_enum!(BtBondState);
impl_dbus_arg_enum!(BtConnectionState);
impl_dbus_arg_enum!(BtDeviceType);
impl_dbus_arg_enum!(BtPropertyType);
impl_dbus_arg_enum!(BtSspVariant);
@@ -353,7 +356,7 @@ impl IBluetooth for BluetoothDBus {
    }

    #[dbus_method("GetBondState")]
    fn get_bond_state(&self, device: BluetoothDevice) -> u32 {
    fn get_bond_state(&self, device: BluetoothDevice) -> BtBondState {
        dbus_generated!()
    }

@@ -397,8 +400,18 @@ impl IBluetooth for BluetoothDBus {
        dbus_generated!()
    }

    #[dbus_method("GetRemoteConnected")]
    fn get_remote_connected(&self, device: BluetoothDevice) -> bool {
        dbus_generated!()
    }

    #[dbus_method("GetConnectedDevices")]
    fn get_connected_devices(&self) -> Vec<BluetoothDevice> {
        dbus_generated!()
    }

    #[dbus_method("GetConnectionState")]
    fn get_connection_state(&self, device: BluetoothDevice) -> u32 {
    fn get_connection_state(&self, device: BluetoothDevice) -> BtConnectionState {
        dbus_generated!()
    }

+16 −3
Original line number Diff line number Diff line
extern crate bt_shim;

use bt_topshim::btif::{
    BtDeviceType, BtPropertyType, BtSspVariant, BtStatus, BtTransport, Uuid, Uuid128Bit,
    BtBondState, BtConnectionState, BtDeviceType, BtPropertyType, BtSspVariant, BtStatus,
    BtTransport, Uuid, Uuid128Bit,
};
use bt_topshim::profiles::socket::SocketType;

@@ -112,6 +113,8 @@ impl IBluetoothCallback for BluetoothCallbackDBus {
    }
}

impl_dbus_arg_enum!(BtBondState);
impl_dbus_arg_enum!(BtConnectionState);
impl_dbus_arg_enum!(BtDeviceType);
impl_dbus_arg_enum!(BtPropertyType);
impl_dbus_arg_enum!(BtSspVariant);
@@ -269,7 +272,7 @@ impl IBluetooth for IBluetoothDBus {
    }

    #[dbus_method("GetBondState")]
    fn get_bond_state(&self, device: BluetoothDevice) -> u32 {
    fn get_bond_state(&self, device: BluetoothDevice) -> BtBondState {
        dbus_generated!()
    }

@@ -313,8 +316,18 @@ impl IBluetooth for IBluetoothDBus {
        dbus_generated!()
    }

    #[dbus_method("GetRemoteConnected")]
    fn get_remote_connected(&self, _device: BluetoothDevice) -> bool {
        dbus_generated!()
    }

    #[dbus_method("GetConnectedDevices")]
    fn get_connected_devices(&self) -> Vec<BluetoothDevice> {
        dbus_generated!()
    }

    #[dbus_method("GetConnectionState")]
    fn get_connection_state(&self, device: BluetoothDevice) -> u32 {
    fn get_connection_state(&self, device: BluetoothDevice) -> BtConnectionState {
        dbus_generated!()
    }

+2 −2
Original line number Diff line number Diff line
@@ -114,8 +114,7 @@ fn main() -> Result<(), Box<dyn Error>> {
        tx.clone(),
    ))));

    let bt_sock_mgr =
        Arc::new(Mutex::new(Box::new(BluetoothSocketManager::new(intf.clone(), tx.clone()))));
    let bt_sock_mgr = Arc::new(Mutex::new(Box::new(BluetoothSocketManager::new(tx.clone()))));

    topstack::get_runtime().block_on(async {
        // Connect to D-Bus system bus.
@@ -244,6 +243,7 @@ fn main() -> Result<(), Box<dyn Error>> {
            bluetooth.enable();

            bluetooth_gatt.lock().unwrap().init_profiles(tx.clone());
            bt_sock_mgr.lock().unwrap().initialize(intf.clone());
        }

        // Serve clients forever.
+46 −9
Original line number Diff line number Diff line
@@ -2,8 +2,9 @@

use bt_topshim::btif::{
    BaseCallbacks, BaseCallbacksDispatcher, BluetoothInterface, BluetoothProperty, BtAclState,
    BtBondState, BtDeviceType, BtDiscoveryState, BtHciErrorCode, BtPinCode, BtPropertyType,
    BtScanMode, BtSspVariant, BtState, BtStatus, BtTransport, RawAddress, Uuid, Uuid128Bit,
    BtBondState, BtConnectionState, BtDeviceType, BtDiscoveryState, BtHciErrorCode, BtPinCode,
    BtPropertyType, BtScanMode, BtSspVariant, BtState, BtStatus, BtTransport, RawAddress, Uuid,
    Uuid128Bit,
};
use bt_topshim::{
    metrics,
@@ -127,7 +128,7 @@ pub trait IBluetooth {
    fn get_bonded_devices(&self) -> Vec<BluetoothDevice>;

    /// Gets the bond state of a single device.
    fn get_bond_state(&self, device: BluetoothDevice) -> u32;
    fn get_bond_state(&self, device: BluetoothDevice) -> BtBondState;

    /// Set pin on bonding device.
    fn set_pin(&self, device: BluetoothDevice, accept: bool, pin_code: Vec<u8>) -> bool;
@@ -153,8 +154,14 @@ pub trait IBluetooth {
    /// Gets the class of the remote device.
    fn get_remote_class(&self, device: BluetoothDevice) -> u32;

    /// Gets whether the remote device is connected.
    fn get_remote_connected(&self, device: BluetoothDevice) -> bool;

    /// Returns a list of connected devices.
    fn get_connected_devices(&self) -> Vec<BluetoothDevice>;

    /// Gets the connection state of a single device.
    fn get_connection_state(&self, device: BluetoothDevice) -> u32;
    fn get_connection_state(&self, device: BluetoothDevice) -> BtConnectionState;

    /// Gets the connection state of a specific profile.
    fn get_profile_connection_state(&self, profile: Profile) -> u32;
@@ -1181,10 +1188,10 @@ impl IBluetooth for Bluetooth {
        devices
    }

    fn get_bond_state(&self, device: BluetoothDevice) -> u32 {
    fn get_bond_state(&self, device: BluetoothDevice) -> BtBondState {
        match self.bonded_devices.get(&device.address) {
            Some(device) => device.bond_state.to_u32().unwrap(),
            None => BtBondState::NotBonded.to_u32().unwrap(),
            Some(device) => device.bond_state.clone(),
            None => BtBondState::NotBonded,
        }
    }

@@ -1309,14 +1316,44 @@ impl IBluetooth for Bluetooth {
        }
    }

    fn get_connection_state(&self, device: BluetoothDevice) -> u32 {
    fn get_remote_connected(&self, device: BluetoothDevice) -> bool {
        self.get_connection_state(device) != BtConnectionState::NotConnected
    }

    fn get_connected_devices(&self) -> Vec<BluetoothDevice> {
        let bonded_connected: HashMap<String, BluetoothDevice> = self
            .bonded_devices
            .iter()
            .filter(|(_, v)| v.acl_state == BtAclState::Connected)
            .map(|(k, v)| (k.clone(), v.info.clone()))
            .collect();
        let mut found_connected: Vec<BluetoothDevice> = self
            .found_devices
            .iter()
            .filter(|(k, v)| {
                v.acl_state == BtAclState::Connected
                    && !bonded_connected.contains_key(&k.to_string())
            })
            .map(|(_, v)| v.info.clone())
            .collect();

        let mut all =
            bonded_connected.iter().map(|(_, v)| v.clone()).collect::<Vec<BluetoothDevice>>();
        all.append(&mut found_connected);

        all
    }

    fn get_connection_state(&self, device: BluetoothDevice) -> BtConnectionState {
        let addr = RawAddress::from_string(device.address.clone());

        if addr.is_none() {
            warn!("Can't check connection state. Address {} is not valid.", device.address);
            return 0;
            return BtConnectionState::NotConnected;
        }

        // The underlying api adds whether this is ENCRYPTED_BREDR or ENCRYPTED_LE.
        // As long as it is non-zero, it is connected.
        self.intf.lock().unwrap().get_connection_state(&addr.unwrap())
    }

Loading