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

Commit 151431b0 authored by Treehugger Robot's avatar Treehugger Robot Committed by Gerrit Code Review
Browse files

Merge "floss: Send HfpVolumeChanged if HF triggers one"

parents f263f853 4380ec37
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -65,6 +65,11 @@ impl IBluetoothMediaCallback for BluetoothMediaCallbackDBus {
    fn on_absolute_volume_changed(&self, volume: i32) {
        dbus_generated!()
    }

    #[dbus_method("OnHfpVolumeChanged")]
    fn on_hfp_volume_changed(&self, volume: u32, addr: String) {
        dbus_generated!()
    }
}

#[allow(dead_code)]
+10 −0
Original line number Diff line number Diff line
@@ -72,6 +72,11 @@ pub trait IBluetoothMediaCallback {

    ///
    fn on_absolute_volume_changed(&self, volume: i32);

    /// Triggered when a Bluetooth device triggers a HFP AT command (AT+VGS) to
    /// notify AG about its speaker volume change. We need to notify audio
    /// client to reflect the change on the audio stack.
    fn on_hfp_volume_changed(&self, volume: u32, addr: String);
}

/// Serializable device used in.
@@ -263,6 +268,11 @@ impl BluetoothMedia {
                    }
                }
            }
            HfpCallbacks::VolumeUpdate(volume, addr) => {
                self.for_all_callbacks(|callback| {
                    callback.on_hfp_volume_changed(volume, addr.to_string());
                });
            }
        }
    }

+10 −4
Original line number Diff line number Diff line
@@ -42,6 +42,10 @@ static void audio_state_cb(bluetooth::headset::bthf_audio_state_t state, RawAddr
  rusty::hfp_audio_state_callback(state, raddr);
}

static void volume_update_cb(uint32_t volume, RawAddress* addr) {
  RustRawAddress raddr = rusty::CopyToRustAddress(*addr);
  rusty::hfp_volume_update_callback(volume, raddr);
}
}  // namespace internal

class DBusHeadsetCallbacks : public headset::Callbacks {
@@ -89,10 +93,12 @@ class DBusHeadsetCallbacks : public headset::Callbacks {

  void HangupCallCallback([[maybe_unused]] RawAddress* bd_addr) override {}

  void VolumeControlCallback(
      [[maybe_unused]] headset::bthf_volume_type_t type,
      [[maybe_unused]] int volume,
      [[maybe_unused]] RawAddress* bd_addr) override {}
  void VolumeControlCallback(headset::bthf_volume_type_t type, int volume, RawAddress* bd_addr) override {
    if (type != headset::bthf_volume_type_t::BTHF_VOLUME_TYPE_SPK || volume < 0) return;
    if (volume > 15) volume = 15;
    LOG_INFO("VolumeControlCallback %d from %s", volume, bd_addr->ToString().c_str());
    topshim::rust::internal::volume_update_cb(volume, bd_addr);
  }

  void DialCallCallback([[maybe_unused]] char* number, [[maybe_unused]] RawAddress* bd_addr) override {}

+10 −0
Original line number Diff line number Diff line
@@ -86,6 +86,7 @@ pub mod ffi {
    extern "Rust" {
        fn hfp_connection_state_callback(state: u32, addr: RustRawAddress);
        fn hfp_audio_state_callback(state: u32, addr: RustRawAddress);
        fn hfp_volume_update_callback(volume: u32, addr: RustRawAddress);
    }
}

@@ -105,6 +106,7 @@ impl Into<RawAddress> for ffi::RustRawAddress {
pub enum HfpCallbacks {
    ConnectionState(BthfConnectionState, RawAddress),
    AudioState(BthfAudioState, RawAddress),
    VolumeUpdate(u32, RawAddress),
}

pub struct HfpCallbacksDispatcher {
@@ -129,6 +131,14 @@ cb_variant!(
    }
);

cb_variant!(
    HfpCb,
    hfp_volume_update_callback -> HfpCallbacks::VolumeUpdate,
    u32, ffi::RustRawAddress -> RawAddress, {
        let _1 = _1.into();
    }
);

pub struct Hfp {
    internal: cxx::UniquePtr<ffi::HfpIntf>,
    _is_init: bool,