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

Commit 132c7b51 authored by Jeremy Wu's avatar Jeremy Wu Committed by Gerrit Code Review
Browse files

Merge "Floss: disconnect all profiles when media profiles are cleared"

parents e83cfa05 eaf94cf7
Loading
Loading
Loading
Loading
+15 −9
Original line number Diff line number Diff line
@@ -73,6 +73,9 @@ pub trait IBluetoothMedia {

    /// connect to available but missing media profiles
    fn connect(&mut self, address: String);

    /// disconnect all profiles from the device
    /// NOTE: do not call this function from outside unless `is_complete_profiles_required`
    fn disconnect(&mut self, address: String);

    // Set the device as the active A2DP device
@@ -372,6 +375,7 @@ impl BluetoothMedia {
        self.delay_volume_update.remove(&profile);

        if is_profile_critical && self.is_complete_profiles_required() {
            BluetoothMedia::disconnect_device(self.tx.clone(), addr);
            self.notify_critical_profile_disconnected(addr);
        }

@@ -480,9 +484,6 @@ impl BluetoothMedia {
                        self.a2dp_caps.remove(&addr);
                        self.a2dp_audio_state.remove(&addr);
                        self.rm_connected_profile(addr, uuid::Profile::A2dpSink, true);
                        if self.is_complete_profiles_required() {
                            self.disconnect(addr.to_string());
                        }
                    }
                    _ => {
                        self.a2dp_states.insert(addr, state);
@@ -500,6 +501,13 @@ impl BluetoothMedia {
        }
    }

    fn disconnect_device(txl: Sender<Message>, addr: RawAddress) {
        let device = BluetoothDevice::new(addr.to_string(), "".to_string());
        topstack::get_runtime().spawn(async move {
            let _ = txl.send(Message::DisconnectDevice(device)).await;
        });
    }

    pub fn dispatch_avrcp_callbacks(&mut self, cb: AvrcpCallbacks) {
        match cb {
            AvrcpCallbacks::AvrcpDeviceConnected(addr, supported) => {
@@ -681,9 +689,6 @@ impl BluetoothMedia {
                        self.hfp_cap.remove(&addr);
                        self.hfp_audio_state.remove(&addr);
                        self.rm_connected_profile(addr, uuid::Profile::Hfp, true);
                        if self.is_complete_profiles_required() {
                            self.disconnect(addr.to_string());
                        }
                    }
                    BthfConnectionState::Connecting => {
                        info!("[{}]: hfp connecting.", DisplayAddress(&addr));
@@ -1929,9 +1934,9 @@ impl IBluetoothMedia for BluetoothMedia {
        true
    }

    // TODO(b/278963515): Currently this is designed to be called from both the
    // UI and via disconnection callbacks. Remove this workaround once the
    // proper fix has landed.
    // This may not disconnect all media profiles at once, but once the stack
    // is notified of the disconnection callback, `disconnect_device` will be
    // invoked as necessary to ensure the device is removed.
    fn disconnect(&mut self, address: String) {
        let addr = match RawAddress::from_string(address.clone()) {
            None => {
@@ -1957,6 +1962,7 @@ impl IBluetoothMedia for BluetoothMedia {
                uuid::Profile::A2dpSink => {
                    // Some headsets (b/278963515) will try reconnecting to A2DP
                    // when HFP is running but (requested to be) disconnected.
                    // TODO: Remove this workaround once proper fix lands.
                    if connected_profiles.contains(&Profile::Hfp) {
                        continue;
                    }
+6 −0
Original line number Diff line number Diff line
@@ -133,6 +133,9 @@ pub enum Message {
    // Dis callbacks
    Dis(ServiceCallbacks),

    // Device removal
    DisconnectDevice(BluetoothDevice),

    // Qualification Only
    QaCallbackDisconnected(u32),
    QaAddMediaPlayer(String, bool),
@@ -367,6 +370,9 @@ impl Stack {
                Message::Dis(callback) => {
                    bluetooth_dis.lock().unwrap().handle_callbacks(&callback);
                }
                Message::DisconnectDevice(addr) => {
                    bluetooth.lock().unwrap().disconnect_all_enabled_profiles(addr);
                }
                // Qualification Only
                Message::QaAddMediaPlayer(name, browsing_supported) => {
                    bluetooth_media.lock().unwrap().add_player(name, browsing_supported);