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

Commit cd2f1b1c authored by Treehugger Robot's avatar Treehugger Robot Committed by Automerger Merge Worker
Browse files

Merge changes I6c755e4a,I648aead5 am: fe452b89

Original change: https://android-review.googlesource.com/c/platform/system/bt/+/1873294

Change-Id: I544715200058940ff6e39beff643ed1f319a8046
parents d25ac9a5 fe452b89
Loading
Loading
Loading
Loading
+22 −2
Original line number Diff line number Diff line
@@ -19,6 +19,8 @@
#include <memory>

#include "include/hardware/bluetooth.h"
#include "rust/cxx.h"
#include "src/profiles/a2dp.rs.h"
#include "types/raw_address.h"

namespace bluetooth {
@@ -37,6 +39,12 @@ btav_sink_callbacks_t g_a2dp_sink_callbacks = {
    audio_state_cb,
    audio_config_cb,
};

static RawAddress from_rust_address(const RustRawAddress& raddr) {
  RawAddress addr;
  addr.FromOctets(raddr.address.data());
  return addr;
}
}  // namespace internal

A2dpSinkIntf::~A2dpSinkIntf() {
@@ -54,11 +62,23 @@ std::unique_ptr<A2dpSinkIntf> GetA2dpSinkProfile(const unsigned char* btif) {
  return a2dp_sink;
}

int A2dpSinkIntf::init() {
int A2dpSinkIntf::init() const {
  return intf_->init(&internal::g_a2dp_sink_callbacks, 1);
}

void A2dpSinkIntf::cleanup() {
int A2dpSinkIntf::connect(RustRawAddress bt_addr) const {
  return intf_->connect(internal::from_rust_address(bt_addr));
}

int A2dpSinkIntf::disconnect(RustRawAddress bt_addr) const {
  return intf_->disconnect(internal::from_rust_address(bt_addr));
}

int A2dpSinkIntf::set_active_device(RustRawAddress bt_addr) const {
  return intf_->set_active_device(internal::from_rust_address(bt_addr));
}

void A2dpSinkIntf::cleanup() const {
  // TODO: Implement.
}

+10 −2
Original line number Diff line number Diff line
@@ -18,20 +18,28 @@

#include <memory>

#include "gd/rust/topshim/btav_sink/btav_sink_shim.h"
#include "include/hardware/bt_av.h"
#include "rust/cxx.h"
#include "types/raw_address.h"

namespace bluetooth {
namespace topshim {
namespace rust {

struct RustRawAddress;

class A2dpSinkIntf {
 public:
  A2dpSinkIntf(const btav_sink_interface_t* intf) : intf_(intf){};
  ~A2dpSinkIntf();

  // interface for Settings
  int init();
  void cleanup();
  int init() const;
  int connect(RustRawAddress bt_addr) const;
  int disconnect(RustRawAddress bt_addr) const;
  int set_active_device(RustRawAddress bt_addr) const;
  void cleanup() const;

 private:
  const btav_sink_interface_t* intf_;
+18 −3
Original line number Diff line number Diff line
@@ -182,8 +182,11 @@ pub mod ffi {

        unsafe fn GetA2dpSinkProfile(btif: *const u8) -> UniquePtr<A2dpSinkIntf>;

        fn init(self: Pin<&mut A2dpSinkIntf>) -> i32;
        fn cleanup(self: Pin<&mut A2dpSinkIntf>);
        fn init(self: &A2dpSinkIntf) -> i32;
        fn connect(self: &A2dpSinkIntf, bt_addr: RustRawAddress) -> i32;
        fn disconnect(self: &A2dpSinkIntf, bt_addr: RustRawAddress) -> i32;
        fn set_active_device(self: &A2dpSinkIntf, bt_addr: RustRawAddress) -> i32;
        fn cleanup(self: &A2dpSinkIntf);
    }
    extern "Rust" {
        fn connection_state_callback(addr: RustRawAddress, state: u32);
@@ -368,10 +371,22 @@ impl A2dpSink {
        if get_dispatchers().lock().unwrap().set::<A2dpSinkCb>(Arc::new(Mutex::new(callbacks))) {
            panic!("Tried to set dispatcher for A2dp Sink Callbacks while it already exists");
        }
        self.internal.pin_mut().init();
        self.internal.init();
        true
    }

    pub fn connect(&mut self, bt_addr: RawAddress) {
        self.internal.connect(bt_addr.into());
    }

    pub fn disconnect(&mut self, bt_addr: RawAddress) {
        self.internal.disconnect(bt_addr.into());
    }

    pub fn set_active_device(&mut self, bt_addr: RawAddress) {
        self.internal.set_active_device(bt_addr.into());
    }

    pub fn cleanup(&mut self) {}
}