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

Commit c3e2af6d authored by Wei-Luan Wang's avatar Wei-Luan Wang Committed by Gerrit Code Review
Browse files

Merge "Migrate base::Callback in the ctor of Device in avrcp" into main

parents ce52c0e6 09b1af40
Loading
Loading
Loading
Loading
+5 −4
Original line number Diff line number Diff line
@@ -268,7 +268,7 @@ void ConnectionHandler::InitiatorControlCb(uint8_t handle, uint8_t event,
      // devices SDP is completed after the device connects AVRCP so that
      // information isn't very useful when trying to control our
      // capabilities. For now always use AVRCP 1.6.
      auto&& callback = base::Bind(&ConnectionHandler::SendMessage,
      auto&& callback = base::BindRepeating(&ConnectionHandler::SendMessage,
                                            base::Unretained(this), handle);
      auto&& ctrl_mtu = avrc_->GetPeerMtu(handle) - AVCT_HDR_LEN;
      auto&& browse_mtu = avrc_->GetBrowseMtu(handle) - AVCT_HDR_LEN;
@@ -356,7 +356,8 @@ void ConnectionHandler::AcceptorControlCb(uint8_t handle, uint8_t event,
        AvrcpConnect(false, RawAddress::kAny);
        return;
      }
      auto&& callback = base::Bind(&ConnectionHandler::SendMessage,
      auto&& callback =
          base::BindRepeating(&ConnectionHandler::SendMessage,
                              weak_ptr_factory_.GetWeakPtr(), handle);
      auto&& ctrl_mtu = avrc_->GetPeerMtu(handle) - AVCT_HDR_LEN;
      auto&& browse_mtu = avrc_->GetBrowseMtu(handle) - AVCT_HDR_LEN;
+5 −5
Original line number Diff line number Diff line
@@ -48,9 +48,9 @@ namespace avrcp {
#define VOL_NOT_SUPPORTED -1
#define VOL_REGISTRATION_FAILED -2

Device::Device(
    const RawAddress& bdaddr, bool avrcp13_compatibility,
    base::Callback<void(uint8_t label, bool browse,
Device::Device(const RawAddress& bdaddr, bool avrcp13_compatibility,
               base::RepeatingCallback<
                   void(uint8_t label, bool browse,
                        std::unique_ptr<::bluetooth::PacketBuilder> message)>
                   send_msg_cb,
               uint16_t ctrl_mtu, uint16_t browse_mtu)
+9 −8
Original line number Diff line number Diff line
@@ -63,9 +63,9 @@ class Device {
   */
  friend class ConnectionHandler;

  Device(
      const RawAddress& bdaddr, bool avrcp13_compatibility,
      base::Callback<void(uint8_t label, bool browse,
  Device(const RawAddress& bdaddr, bool avrcp13_compatibility,
         base::RepeatingCallback<
             void(uint8_t label, bool browse,
                  std::unique_ptr<::bluetooth::PacketBuilder> message)>
             send_msg_cb,
         uint16_t ctrl_mtu, uint16_t browse_mtu);
@@ -334,7 +334,8 @@ class Device {
  // Enables AVRCP 1.3 Compatibility mode. This disables any AVRCP 1.4+ features
  // such as browsing and playlists but has the highest chance of working.
  bool avrcp13_compatibility_ = false;
  base::Callback<void(uint8_t label, bool browse,
  base::RepeatingCallback<void(
      uint8_t label, bool browse,
      std::unique_ptr<::bluetooth::PacketBuilder> message)>
      send_message_cb_;
  uint16_t ctrl_mtu_;
+5 −4
Original line number Diff line number Diff line
@@ -91,9 +91,10 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* Data, size_t Size) {
  FakePlayerSettingsInterface fpsi;

  std::vector<uint8_t> Packet(Data, Data + Size);
  Device device(RawAddress::kAny, true,
                base::Bind([](uint8_t, bool,
                              std::unique_ptr<::bluetooth::PacketBuilder>) {}),
  Device device(
      RawAddress::kAny, true,
      base::BindRepeating(
          [](uint8_t, bool, std::unique_ptr<::bluetooth::PacketBuilder>) {}),
      0xFFFF, 0xFFFF);
  device.RegisterInterfaces(&fmi, &fai, &fvi, &fpsi);

+25 −20
Original line number Diff line number Diff line
@@ -73,7 +73,8 @@ class AvrcpDeviceTest : public ::testing::Test {
    // NOTE: We use a wrapper lambda for the MockFunction in order to
    // add a const qualifier to the response. Otherwise the MockFunction
    // type doesn't match the callback type and a compiler error occurs.
    base::Callback<void(uint8_t, bool, AvrcpResponse)> cb = base::Bind(
    base::RepeatingCallback<void(uint8_t, bool, AvrcpResponse)> cb =
        base::BindRepeating(
            [](MockFunction<void(uint8_t, bool, const AvrcpResponse&)>* a,
               uint8_t b, bool c, AvrcpResponse d) { a->Call(b, c, d); },
            &response_cb);
@@ -114,8 +115,9 @@ class AvrcpDeviceTest : public ::testing::Test {
};

TEST_F(AvrcpDeviceTest, addressTest) {
  base::Callback<void(uint8_t, bool, AvrcpResponse)> cb =
      base::Bind([](MockFunction<void(uint8_t, bool, const AvrcpResponse&)>* a,
  base::RepeatingCallback<void(uint8_t, bool, AvrcpResponse)> cb =
      base::BindRepeating(
          [](MockFunction<void(uint8_t, bool, const AvrcpResponse&)>* a,
             uint8_t b, bool c, AvrcpResponse d) { a->Call(b, c, d); },
          &response_cb);

@@ -793,8 +795,9 @@ TEST_F(AvrcpDeviceTest, getElementAttributesMtuTest) {
  MockMediaInterface interface;
  NiceMock<MockA2dpInterface> a2dp_interface;

  base::Callback<void(uint8_t, bool, AvrcpResponse)> cb =
      base::Bind([](MockFunction<void(uint8_t, bool, const AvrcpResponse&)>* a,
  base::RepeatingCallback<void(uint8_t, bool, AvrcpResponse)> cb =
      base::BindRepeating(
          [](MockFunction<void(uint8_t, bool, const AvrcpResponse&)>* a,
             uint8_t b, bool c, AvrcpResponse d) { a->Call(b, c, d); },
          &response_cb);
  Device device(RawAddress::kAny, true, cb, truncated_packet->size(), 0xFFFF);
@@ -1016,8 +1019,9 @@ TEST_F(AvrcpDeviceTest, getFolderItemsMtuTest) {

  MockMediaInterface interface;
  NiceMock<MockA2dpInterface> a2dp_interface;
  base::Callback<void(uint8_t, bool, AvrcpResponse)> cb =
      base::Bind([](MockFunction<void(uint8_t, bool, const AvrcpResponse&)>* a,
  base::RepeatingCallback<void(uint8_t, bool, AvrcpResponse)> cb =
      base::BindRepeating(
          [](MockFunction<void(uint8_t, bool, const AvrcpResponse&)>* a,
             uint8_t b, bool c, AvrcpResponse d) { a->Call(b, c, d); },
          &response_cb);

@@ -1257,8 +1261,9 @@ TEST_F(AvrcpDeviceTest, getItemAttributesMtuTest) {

  MockMediaInterface interface;
  NiceMock<MockA2dpInterface> a2dp_interface;
  base::Callback<void(uint8_t, bool, AvrcpResponse)> cb =
      base::Bind([](MockFunction<void(uint8_t, bool, const AvrcpResponse&)>* a,
  base::RepeatingCallback<void(uint8_t, bool, AvrcpResponse)> cb =
      base::BindRepeating(
          [](MockFunction<void(uint8_t, bool, const AvrcpResponse&)>* a,
             uint8_t b, bool c, AvrcpResponse d) { a->Call(b, c, d); },
          &response_cb);
  Device device(RawAddress::kAny, true, cb, 0xFFFF, truncated_packet->size());