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

Commit 2c6f1950 authored by Jeremy Wu's avatar Jeremy Wu
Browse files

floss: propagate VC connection event to audio server

The audio server needs this information to determine whether software
volume adjustment is needed.

If VCP is connected before being identified as a group, the callback
is delayed until the group is notified to the audio server. This makes
things much simpler given the assumption that a device attaches to a
unqiue group id in the lifetime of its connection.

Bug: 317682584
Test: m Bluetooth

Change-Id: I45fa4309281fb22cc68651763f492bb48b539462
parent 0e40838d
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -1470,6 +1470,7 @@ impl IBluetoothMediaCallback for MediaCallback {
    ) {
    }
    fn on_lea_group_stream_status(&mut self, _group_id: i32, _status: BtLeAudioGroupStreamStatus) {}
    fn on_lea_vc_connected(&mut self, _addr: RawAddress, _group_id: i32) {}
    fn on_lea_group_volume_changed(&mut self, _group_id: i32, _volume: u8) {}
    fn on_bluetooth_audio_device_added(&mut self, _device: BluetoothAudioDevice) {}
    fn on_bluetooth_audio_device_removed(&mut self, _addr: RawAddress) {}
+3 −0
Original line number Diff line number Diff line
@@ -2984,6 +2984,9 @@ impl IBluetoothMediaCallback for IBluetoothMediaCallbackDBus {
    #[dbus_method("OnLeaGroupStreamStatus")]
    fn on_lea_group_stream_status(&mut self, group_id: i32, status: BtLeAudioGroupStreamStatus) {}

    #[dbus_method("OnLeaVcConnected")]
    fn on_lea_vc_connected(&mut self, addr: RawAddress, group_id: i32) {}

    #[dbus_method("OnLeaGroupVolumeChanged")]
    fn on_lea_group_volume_changed(&mut self, group_id: i32, volume: u8) {}
}
+5 −0
Original line number Diff line number Diff line
@@ -175,6 +175,11 @@ impl IBluetoothMediaCallback for BluetoothMediaCallbackDBus {
        dbus_generated!()
    }

    #[dbus_method("OnLeaVcConnected")]
    fn on_lea_vc_connected(&mut self, addr: RawAddress, group_id: i32) {
        dbus_generated!()
    }

    #[dbus_method("OnLeaGroupVolumeChanged")]
    fn on_lea_group_volume_changed(&mut self, group_id: i32, volume: u8) {
        dbus_generated!()
+29 −9
Original line number Diff line number Diff line
@@ -293,6 +293,8 @@ pub trait IBluetoothMediaCallback: RPCProxy {

    fn on_lea_group_stream_status(&mut self, group_id: i32, status: BtLeAudioGroupStreamStatus);

    fn on_lea_vc_connected(&mut self, addr: RawAddress, group_id: i32);

    fn on_lea_group_volume_changed(&mut self, group_id: i32, volume: u8);
}

@@ -479,6 +481,7 @@ pub struct BluetoothMedia {
    le_audio_unicast_monitor_mode_status: HashMap<i32, BtLeAudioUnicastMonitorModeStatus>,
    le_audio_group_stream_status: HashMap<i32, BtLeAudioGroupStreamStatus>,
    le_audio_delayed_audio_conf_updates: HashMap<i32, LEAAudioConf>,
    le_audio_delayed_vc_connection_updates: HashSet<RawAddress>,
    vc: Option<VolumeControl>,
    vc_states: HashMap<RawAddress, BtVcConnectionState>,
    csis: Option<CsisClient>,
@@ -546,6 +549,7 @@ impl BluetoothMedia {
            le_audio_unicast_monitor_mode_status: HashMap::new(),
            le_audio_group_stream_status: HashMap::new(),
            le_audio_delayed_audio_conf_updates: HashMap::new(),
            le_audio_delayed_vc_connection_updates: HashSet::new(),
            vc: None,
            vc_states: HashMap::new(),
            csis: None,
@@ -599,6 +603,13 @@ impl BluetoothMedia {
        self.notify_media_capability_updated(addr);
    }

    fn is_group_connected(&self, group: HashSet<RawAddress>) -> bool {
        group.iter().any(|&addr| {
            *self.le_audio_states.get(&addr).unwrap_or(&BtLeAudioConnectionState::Disconnected)
                == BtLeAudioConnectionState::Connected
        })
    }

    pub fn set_adapter(&mut self, adapter: Arc<Mutex<Box<Bluetooth>>>) {
        self.adapter = Some(adapter);
    }
@@ -817,6 +828,17 @@ impl BluetoothMedia {
                            .get(&addr)
                            .unwrap_or(&LEA_UNKNOWN_GROUP_ID);

                        let group =
                            self.le_audio_groups.get(&group_id).unwrap_or(&HashSet::new()).clone();

                        if self.is_group_connected(group) {
                            self.callbacks.lock().unwrap().for_all_callbacks(|callback| {
                                callback.on_lea_vc_connected(addr, group_id);
                            });
                        } else {
                            self.le_audio_delayed_vc_connection_updates.insert(addr);
                        }

                        // Sync group volume in case this new member has not been adjusted.
                        if let Some(volume) = self.le_audio_group_volume.get(&group_id) {
                            self.set_group_volume(group_id, *volume);
@@ -961,6 +983,12 @@ impl BluetoothMedia {
                            }
                        }

                        if self.le_audio_delayed_vc_connection_updates.remove(&addr) {
                            self.callbacks.lock().unwrap().for_all_callbacks(|callback| {
                                callback.on_lea_vc_connected(addr, group_id);
                            });
                        }

                        self.le_audio_states.insert(addr, state);
                    }
                    BtLeAudioConnectionState::Disconnected => {
@@ -1091,15 +1119,7 @@ impl BluetoothMedia {

                let group = self.le_audio_groups.get(&group_id).unwrap_or(&HashSet::new()).clone();

                let is_group_connected = group.iter().any(|&addr| {
                    *self
                        .le_audio_states
                        .get(&addr)
                        .unwrap_or(&BtLeAudioConnectionState::Disconnected)
                        == BtLeAudioConnectionState::Connected
                });

                if is_group_connected {
                if self.is_group_connected(group) {
                    self.callbacks.lock().unwrap().for_all_callbacks(|callback| {
                        callback.on_lea_audio_conf(
                            direction,