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

Commit ea2fae34 authored by Jeremy Wu's avatar Jeremy Wu
Browse files

floss: add LEA volume update callback events

This CL propagates volume update events to the audio server.

Bug: 317682584
Test: m Bluetooth
Change-Id: Ic171b996bfa449559e61b6cce8ab25953efac6dc
parent 5ad043ee
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_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) {}
    fn on_absolute_volume_supported_changed(&mut self, _supported: bool) {}
+3 −0
Original line number Diff line number Diff line
@@ -2983,6 +2983,9 @@ impl IBluetoothMediaCallback for IBluetoothMediaCallbackDBus {

    #[dbus_method("OnLeaGroupStreamStatus")]
    fn on_lea_group_stream_status(&mut self, group_id: i32, status: BtLeAudioGroupStreamStatus) {}

    #[dbus_method("OnLeaGroupVolumeChanged")]
    fn on_lea_group_volume_changed(&mut self, group_id: i32, volume: u8) {}
}

pub(crate) struct BatteryManagerDBusRPC {
+5 −0
Original line number Diff line number Diff line
@@ -174,6 +174,11 @@ impl IBluetoothMediaCallback for BluetoothMediaCallbackDBus {
    fn on_lea_group_stream_status(&mut self, group_id: i32, status: BtLeAudioGroupStreamStatus) {
        dbus_generated!()
    }

    #[dbus_method("OnLeaGroupVolumeChanged")]
    fn on_lea_group_volume_changed(&mut self, group_id: i32, volume: u8) {
        dbus_generated!()
    }
}

#[allow(dead_code)]
+28 −0
Original line number Diff line number Diff line
@@ -292,6 +292,8 @@ pub trait IBluetoothMediaCallback: RPCProxy {
    );

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

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

pub trait IBluetoothTelephony {
@@ -470,6 +472,7 @@ pub struct BluetoothMedia {
    uhid: HashMap<RawAddress, UHid>,
    le_audio: Option<LeAudioClient>,
    le_audio_group_status: HashMap<i32, BtLeAudioGroupStatus>,
    le_audio_group_volume: HashMap<i32, u8>,
    le_audio_groups: HashMap<i32, HashSet<RawAddress>>,
    le_audio_node_to_group: HashMap<RawAddress, i32>,
    le_audio_states: HashMap<RawAddress, BtLeAudioConnectionState>,
@@ -536,6 +539,7 @@ impl BluetoothMedia {
            uhid: HashMap::new(),
            le_audio: None,
            le_audio_group_status: HashMap::new(),
            le_audio_group_volume: HashMap::new(),
            le_audio_groups: HashMap::new(),
            le_audio_node_to_group: HashMap::new(),
            le_audio_states: HashMap::new(),
@@ -830,6 +834,21 @@ impl BluetoothMedia {
                    "VolumeControlCallbacks::GroupVolumeState: group_id={}, volume={}, mute={}, is_autonomous={}",
                    group_id, volume, mute, is_autonomous
                );

                if let Some(old_volume) = self.le_audio_group_volume.insert(group_id, volume) {
                    if old_volume == volume {
                        return;
                    }
                }

                // This can come with ~300ms delay, thus notify only when
                // triggered by the headset. Otherwise expect the audio server
                // to know the expected volume.
                if is_autonomous {
                    self.callbacks.lock().unwrap().for_all_callbacks(|callback| {
                        callback.on_lea_group_volume_changed(group_id, volume);
                    });
                }
            }
            VolumeControlCallbacks::DeviceAvailable(addr, num_offset) => {
                info!(
@@ -995,6 +1014,11 @@ impl BluetoothMedia {
                                    old_group.remove(&addr);
                                    if old_group.is_empty() {
                                        self.le_audio_groups.remove(&old_group_id);
                                        self.le_audio_group_status.remove(&old_group_id);
                                        self.le_audio_group_volume.remove(&old_group_id);
                                        self.le_audio_group_stream_status.remove(&old_group_id);
                                        self.le_audio_delayed_audio_conf_updates
                                            .remove(&old_group_id);
                                    }
                                }
                            }
@@ -1017,6 +1041,10 @@ impl BluetoothMedia {
                                old_group.remove(&addr);
                                if old_group.is_empty() {
                                    self.le_audio_groups.remove(&old_group_id);
                                    self.le_audio_group_status.remove(&old_group_id);
                                    self.le_audio_group_volume.remove(&old_group_id);
                                    self.le_audio_group_stream_status.remove(&old_group_id);
                                    self.le_audio_delayed_audio_conf_updates.remove(&old_group_id);
                                }
                            }
                        } else {