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

Commit 91e2c791 authored by Ying Hsu's avatar Ying Hsu
Browse files

Floss: Fixing classic keyboard SDP and connection

If service discovery is ongoing, the connect_all_enabled_profiles()
might not have any profile to connect. In that case, we will retry
again once the UUIDs from a remote device are available.
Besides, we also remove the cancel_discovery() from
connect_all_enabled_profiles() as it could interrupt the service discovery
once a device is bonded.

Bug: 219021367
Tag: #floss
Test: manual test on BR/EDR keyboards and mouse
Change-Id: Ie0445520cfed9b5fa821a08f116df16ea6e45073
parent 52b2a225
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -450,7 +450,7 @@ impl CommandHandler {
                        .lock()
                        .unwrap()
                        .adapter_dbus
                        .as_ref()
                        .as_mut()
                        .unwrap()
                        .connect_all_enabled_profiles(device.clone());

@@ -471,7 +471,7 @@ impl CommandHandler {
                        .lock()
                        .unwrap()
                        .adapter_dbus
                        .as_ref()
                        .as_mut()
                        .unwrap()
                        .disconnect_all_enabled_profiles(device.clone());

+2 −2
Original line number Diff line number Diff line
@@ -445,12 +445,12 @@ impl IBluetooth for BluetoothDBus {
    }

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

    #[dbus_method("DisconnectAllEnabledProfiles")]
    fn disconnect_all_enabled_profiles(&self, device: BluetoothDevice) -> bool {
    fn disconnect_all_enabled_profiles(&mut self, device: BluetoothDevice) -> bool {
        dbus_generated!()
    }
}
+2 −2
Original line number Diff line number Diff line
@@ -296,12 +296,12 @@ impl IBluetooth for IBluetoothDBus {
    }

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

    #[dbus_method("DisconnectAllEnabledProfiles")]
    fn disconnect_all_enabled_profiles(&self, device: BluetoothDevice) -> bool {
    fn disconnect_all_enabled_profiles(&mut self, device: BluetoothDevice) -> bool {
        dbus_generated!()
    }
}
+21 −7
Original line number Diff line number Diff line
@@ -161,10 +161,10 @@ pub trait IBluetooth {
    fn sdp_search(&self, device: BluetoothDevice, uuid: Uuid128Bit) -> bool;

    /// Connect all profiles supported by device and enabled on adapter.
    fn connect_all_enabled_profiles(&self, device: BluetoothDevice) -> bool;
    fn connect_all_enabled_profiles(&mut self, device: BluetoothDevice) -> bool;

    /// Disconnect all profiles supported by device and enabled on adapter.
    fn disconnect_all_enabled_profiles(&self, device: BluetoothDevice) -> bool;
    fn disconnect_all_enabled_profiles(&mut self, device: BluetoothDevice) -> bool;
}

/// Serializable device used in various apis.
@@ -311,6 +311,8 @@ pub struct Bluetooth {
    state: BtState,
    tx: Sender<Message>,
    uuid_helper: UuidHelper,
    /// Used to delay connection until we have SDP results.
    wait_to_connect: bool,
}

impl Bluetooth {
@@ -339,6 +341,7 @@ impl Bluetooth {
            state: BtState::Off,
            tx,
            uuid_helper: UuidHelper::new(),
            wait_to_connect: false,
        }
    }

@@ -835,6 +838,12 @@ impl BtifBluetoothCallbacks for Bluetooth {
            Some(d) => {
                d.update_properties(properties);
                d.seen();

                let info = d.info.clone();
                let uuids = self.get_remote_uuids(info.clone());
                if self.wait_to_connect && uuids.len() > 0 {
                    self.connect_all_enabled_profiles(info);
                }
            }
            None => (),
        };
@@ -1333,7 +1342,7 @@ impl IBluetooth for Bluetooth {
        self.sdp.as_ref().unwrap().sdp_search(&mut addr.unwrap(), &uu) == BtStatus::Success
    }

    fn connect_all_enabled_profiles(&self, device: BluetoothDevice) -> bool {
    fn connect_all_enabled_profiles(&mut self, device: BluetoothDevice) -> bool {
        // Profile init must be complete before this api is callable
        if !self.profiles_ready {
            return false;
@@ -1345,10 +1354,8 @@ impl IBluetooth for Bluetooth {
            return false;
        }

        // BREDR connection won't work when Inquiry is in progress.
        self.cancel_discovery();

        // Check all remote uuids to see if they match enabled profiles and connect them.
        let mut has_enabled_uuids = false;
        let uuids = self.get_remote_uuids(device.clone());
        for uuid in uuids.iter() {
            match self.uuid_helper.is_known_profile(uuid) {
@@ -1372,15 +1379,22 @@ impl IBluetooth for Bluetooth {
                            _ => (),
                        }
                    }
                    has_enabled_uuids = true;
                }
                _ => {}
            }
        }

        // If SDP isn't completed yet, we wait for it to complete and retry the connection again.
        // Otherwise, this connection request is done, no retry is required.
        self.wait_to_connect = !has_enabled_uuids;
        return true;
    }

    fn disconnect_all_enabled_profiles(&self, device: BluetoothDevice) -> bool {
    fn disconnect_all_enabled_profiles(&mut self, device: BluetoothDevice) -> bool {
        // No need to retry connection as we are going to disconnect all enabled profiles.
        self.wait_to_connect = false;

        if !self.profiles_ready {
            return false;
        }