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

Commit 747b856a authored by Sonny Sasaka's avatar Sonny Sasaka Committed by Gerrit Code Review
Browse files

Merge changes I1be91d1e,Idffeec4f,I948b88e2

* changes:
  Floss: Move parse_uuid_string to UuidHelper
  Floss: Add Uuid::from([u8; 16])
  Floss: Refactor UuidHelper to use static data
parents 92b06ba1 e7808609
Loading
Loading
Loading
Loading
+5 −9
Original line number Original line Diff line number Diff line
@@ -15,7 +15,6 @@ use btstack::bluetooth_gatt::{
use btstack::socket_manager::{IBluetoothSocketManager, SocketResult};
use btstack::socket_manager::{IBluetoothSocketManager, SocketResult};
use btstack::uuid::{Profile, UuidHelper, UuidWrapper};
use btstack::uuid::{Profile, UuidHelper, UuidWrapper};
use manager_service::iface_bluetooth_manager::IBluetoothManager;
use manager_service::iface_bluetooth_manager::IBluetoothManager;
use std::convert::TryFrom;


const INDENT_CHAR: &str = " ";
const INDENT_CHAR: &str = " ";
const BAR1_CHAR: &str = "=";
const BAR1_CHAR: &str = "=";
@@ -335,8 +334,7 @@ impl CommandHandler {
                    let multi_adv_supported = adapter_dbus.is_multi_advertisement_supported();
                    let multi_adv_supported = adapter_dbus.is_multi_advertisement_supported();
                    let le_ext_adv_supported = adapter_dbus.is_le_extended_advertising_supported();
                    let le_ext_adv_supported = adapter_dbus.is_le_extended_advertising_supported();
                    let wbs_supported = adapter_dbus.is_wbs_supported();
                    let wbs_supported = adapter_dbus.is_wbs_supported();
                    let uuid_helper = UuidHelper::new();
                    let enabled_profiles = UuidHelper::get_enabled_profiles();
                    let enabled_profiles = uuid_helper.get_enabled_profiles();
                    let connected_profiles: Vec<Profile> = enabled_profiles
                    let connected_profiles: Vec<Profile> = enabled_profiles
                        .iter()
                        .iter()
                        .filter(|&&prof| adapter_dbus.get_profile_connection_state(prof) > 0)
                        .filter(|&&prof| adapter_dbus.get_profile_connection_state(prof) > 0)
@@ -358,7 +356,7 @@ impl CommandHandler {
                        DisplayList(
                        DisplayList(
                            uuids
                            uuids
                                .iter()
                                .iter()
                                .map(|&x| uuid_helper.known_uuid_to_string(&x))
                                .map(|&x| UuidHelper::known_uuid_to_string(&x))
                                .collect::<Vec<String>>()
                                .collect::<Vec<String>>()
                        )
                        )
                    );
                    );
@@ -637,7 +635,6 @@ impl CommandHandler {
                        )
                        )
                    };
                    };


                    let uuid_helper = UuidHelper::new();
                    print_info!("Address: {}", &device.address);
                    print_info!("Address: {}", &device.address);
                    print_info!("Name: {}", name);
                    print_info!("Name: {}", name);
                    print_info!("Alias: {}", alias);
                    print_info!("Alias: {}", alias);
@@ -652,7 +649,7 @@ impl CommandHandler {
                        DisplayList(
                        DisplayList(
                            uuids
                            uuids
                                .iter()
                                .iter()
                                .map(|&x| uuid_helper.known_uuid_to_string(&x))
                                .map(|&x| UuidHelper::known_uuid_to_string(&x))
                                .collect::<Vec<String>>()
                                .collect::<Vec<String>>()
                        )
                        )
                    );
                    );
@@ -963,11 +960,10 @@ impl CommandHandler {
                };
                };


                let data = AdvertiseData {
                let data = AdvertiseData {
                    service_uuids: vec![Uuid::try_from(vec![
                    service_uuids: vec![Uuid::from([
                        0x00, 0x00, 0xfe, 0xf3, 0x00, 0x00, 0x10, 0x00, 0x80, 0x00, 0x00, 0x80,
                        0x00, 0x00, 0xfe, 0xf3, 0x00, 0x00, 0x10, 0x00, 0x80, 0x00, 0x00, 0x80,
                        0x5f, 0x9b, 0x34, 0xfb,
                        0x5f, 0x9b, 0x34, 0xfb,
                    ])
                    ])],
                    .unwrap()],
                    solicit_uuids: Vec::new(),
                    solicit_uuids: Vec::new(),
                    transport_discovery_data: Vec::new(),
                    transport_discovery_data: Vec::new(),
                    manufacturer_data: HashMap::from([(0, vec![0, 1, 2])]),
                    manufacturer_data: HashMap::from([(0, vec![0, 1, 2])]),
+2 −2
Original line number Original line Diff line number Diff line
@@ -1323,7 +1323,7 @@ mod tests {
    const WANT_DEFAULT_ADAPTER: i32 = 0;
    const WANT_DEFAULT_ADAPTER: i32 = 0;


    fn make_state_machine(process_manager: MockProcessManager) -> StateMachineInternal {
    fn make_state_machine(process_manager: MockProcessManager) -> StateMachineInternal {
        let mut state_machine =
        let state_machine =
            StateMachineInternal::new(Box::new(process_manager), true, WANT_DEFAULT_ADAPTER);
            StateMachineInternal::new(Box::new(process_manager), true, WANT_DEFAULT_ADAPTER);
        state_machine
        state_machine
    }
    }
@@ -1332,7 +1332,7 @@ mod tests {
    fn initial_state_is_off() {
    fn initial_state_is_off() {
        tokio::runtime::Runtime::new().unwrap().block_on(async {
        tokio::runtime::Runtime::new().unwrap().block_on(async {
            let process_manager = MockProcessManager::new();
            let process_manager = MockProcessManager::new();
            let mut state_machine = make_state_machine(process_manager);
            let state_machine = make_state_machine(process_manager);
            assert_eq!(state_machine.get_process_state(0), ProcessState::Off);
            assert_eq!(state_machine.get_process_state(0), ProcessState::Off);
        })
        })
    }
    }
+1 −0
Original line number Original line Diff line number Diff line
@@ -12,6 +12,7 @@ btif_macros = { path = "btif_macros" }


dbus = "0.9.2"
dbus = "0.9.2"
itertools = "0.10.5"
itertools = "0.10.5"
lazy_static = "1.4"
log = "0.4.14"
log = "0.4.14"
nix = "0.19"
nix = "0.19"
num-derive = "0.3"
num-derive = "0.3"
+3 −3
Original line number Original line Diff line number Diff line
@@ -3,7 +3,7 @@ use crate::bluetooth_gatt::{
};
};
use crate::callbacks::Callbacks;
use crate::callbacks::Callbacks;
use crate::uuid;
use crate::uuid;
use crate::uuid::parse_uuid_string;
use crate::uuid::UuidHelper;
use crate::Message;
use crate::Message;
use crate::RPCProxy;
use crate::RPCProxy;
use bt_topshim::btif::BtTransport;
use bt_topshim::btif::BtTransport;
@@ -144,8 +144,8 @@ impl BatteryService {
                    return;
                    return;
                }
                }
                let (bas_uuid, battery_level_uuid) = match (
                let (bas_uuid, battery_level_uuid) = match (
                    parse_uuid_string(uuid::BAS),
                    UuidHelper::parse_string(uuid::BAS),
                    parse_uuid_string(CHARACTERISTIC_BATTERY_LEVEL),
                    UuidHelper::parse_string(CHARACTERISTIC_BATTERY_LEVEL),
                ) {
                ) {
                    (Some(bas_uuid), Some(battery_level_uuid)) => (bas_uuid, battery_level_uuid),
                    (Some(bas_uuid), Some(battery_level_uuid)) => (bas_uuid, battery_level_uuid),
                    _ => return,
                    _ => return,
+9 −12
Original line number Original line Diff line number Diff line
@@ -349,7 +349,6 @@ pub struct Bluetooth {
    sdp: Option<Sdp>,
    sdp: Option<Sdp>,
    state: BtState,
    state: BtState,
    tx: Sender<Message>,
    tx: Sender<Message>,
    uuid_helper: UuidHelper,
    /// Used to delay connection until we have SDP results.
    /// Used to delay connection until we have SDP results.
    wait_to_connect: bool,
    wait_to_connect: bool,
    // Internal API members
    // Internal API members
@@ -388,7 +387,6 @@ impl Bluetooth {
            sdp: None,
            sdp: None,
            state: BtState::Off,
            state: BtState::Off,
            tx,
            tx,
            uuid_helper: UuidHelper::new(),
            wait_to_connect: false,
            wait_to_connect: false,
            // Internal API members
            // Internal API members
            discoverable_timeout: None,
            discoverable_timeout: None,
@@ -1424,10 +1422,9 @@ impl IBluetooth for Bluetooth {
        // Wake is allowed if the device supports HIDP or HOGP only.
        // Wake is allowed if the device supports HIDP or HOGP only.
        match self.get_remote_device_property(&device, &BtPropertyType::Uuids) {
        match self.get_remote_device_property(&device, &BtPropertyType::Uuids) {
            Some(BluetoothProperty::Uuids(uuids)) => {
            Some(BluetoothProperty::Uuids(uuids)) => {
                let uu_helper = UuidHelper::new();
                return uuids.iter().any(|&x| {
                return uuids.iter().any(|&x| {
                    uu_helper.is_known_profile(&x.uu).map_or(false, |profile| {
                    UuidHelper::is_known_profile(&x.uu).map_or(false, |profile| {
                        profile == &Profile::Hid || profile == &Profile::Hogp
                        profile == Profile::Hid || profile == Profile::Hogp
                    })
                    })
                });
                });
            }
            }
@@ -1520,7 +1517,7 @@ impl IBluetooth for Bluetooth {
            return false;
            return false;
        }
        }


        let uu = Uuid { uu: uuid };
        let uu = Uuid::from(uuid);
        self.sdp.as_ref().unwrap().sdp_search(&mut addr.unwrap(), &uu) == BtStatus::Success
        self.sdp.as_ref().unwrap().sdp_search(&mut addr.unwrap(), &uu) == BtStatus::Success
    }
    }


@@ -1540,15 +1537,15 @@ impl IBluetooth for Bluetooth {
        let mut has_enabled_uuids = false;
        let mut has_enabled_uuids = false;
        let uuids = self.get_remote_uuids(device.clone());
        let uuids = self.get_remote_uuids(device.clone());
        for uuid in uuids.iter() {
        for uuid in uuids.iter() {
            match self.uuid_helper.is_known_profile(uuid) {
            match UuidHelper::is_known_profile(uuid) {
                Some(p) => {
                Some(p) => {
                    if self.uuid_helper.is_profile_enabled(&p) {
                    if UuidHelper::is_profile_enabled(&p) {
                        match p {
                        match p {
                            Profile::Hid | Profile::Hogp => {
                            Profile::Hid | Profile::Hogp => {
                                let status = self.hh.as_ref().unwrap().connect(&mut addr.unwrap());
                                let status = self.hh.as_ref().unwrap().connect(&mut addr.unwrap());
                                metrics::profile_connection_state_changed(
                                metrics::profile_connection_state_changed(
                                    addr.unwrap(),
                                    addr.unwrap(),
                                    *p as u32,
                                    p as u32,
                                    BtStatus::Success,
                                    BtStatus::Success,
                                    BthhConnectionState::Connecting as u32,
                                    BthhConnectionState::Connecting as u32,
                                );
                                );
@@ -1556,7 +1553,7 @@ impl IBluetooth for Bluetooth {
                                if status != BtStatus::Success {
                                if status != BtStatus::Success {
                                    metrics::profile_connection_state_changed(
                                    metrics::profile_connection_state_changed(
                                        addr.unwrap(),
                                        addr.unwrap(),
                                        *p as u32,
                                        p as u32,
                                        status,
                                        status,
                                        BthhConnectionState::Disconnected as u32,
                                        BthhConnectionState::Disconnected as u32,
                                    );
                                    );
@@ -1604,9 +1601,9 @@ impl IBluetooth for Bluetooth {


        let uuids = self.get_remote_uuids(device.clone());
        let uuids = self.get_remote_uuids(device.clone());
        for uuid in uuids.iter() {
        for uuid in uuids.iter() {
            match self.uuid_helper.is_known_profile(uuid) {
            match UuidHelper::is_known_profile(uuid) {
                Some(p) => {
                Some(p) => {
                    if self.uuid_helper.is_profile_enabled(&p) {
                    if UuidHelper::is_profile_enabled(&p) {
                        match p {
                        match p {
                            Profile::Hid | Profile::Hogp => {
                            Profile::Hid | Profile::Hogp => {
                                self.hh.as_ref().unwrap().disconnect(&mut addr.unwrap());
                                self.hh.as_ref().unwrap().disconnect(&mut addr.unwrap());
Loading