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

Commit 09b1af40 authored by Wei-Luan Wang's avatar Wei-Luan Wang
Browse files

Migrate base::Callback in the ctor of Device in avrcp

base::Bind and base::Callback are deprecated. Migrate the usages to
proper replacements.

The callback |send_msg_cb| can be called multiple times so it should be
migrated to a RepeatingCallback.

Bug: 272116782
Test: m .

Change-Id: I6dcae165e51ca4509726f9f5c796364e5b7fe776
parent 08c97d80
Loading
Loading
Loading
Loading
+5 −4
Original line number Original line 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
      // devices SDP is completed after the device connects AVRCP so that
      // information isn't very useful when trying to control our
      // information isn't very useful when trying to control our
      // capabilities. For now always use AVRCP 1.6.
      // capabilities. For now always use AVRCP 1.6.
      auto&& callback = base::Bind(&ConnectionHandler::SendMessage,
      auto&& callback = base::BindRepeating(&ConnectionHandler::SendMessage,
                                            base::Unretained(this), handle);
                                            base::Unretained(this), handle);
      auto&& ctrl_mtu = avrc_->GetPeerMtu(handle) - AVCT_HDR_LEN;
      auto&& ctrl_mtu = avrc_->GetPeerMtu(handle) - AVCT_HDR_LEN;
      auto&& browse_mtu = avrc_->GetBrowseMtu(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);
        AvrcpConnect(false, RawAddress::kAny);
        return;
        return;
      }
      }
      auto&& callback = base::Bind(&ConnectionHandler::SendMessage,
      auto&& callback =
          base::BindRepeating(&ConnectionHandler::SendMessage,
                              weak_ptr_factory_.GetWeakPtr(), handle);
                              weak_ptr_factory_.GetWeakPtr(), handle);
      auto&& ctrl_mtu = avrc_->GetPeerMtu(handle) - AVCT_HDR_LEN;
      auto&& ctrl_mtu = avrc_->GetPeerMtu(handle) - AVCT_HDR_LEN;
      auto&& browse_mtu = avrc_->GetBrowseMtu(handle) - AVCT_HDR_LEN;
      auto&& browse_mtu = avrc_->GetBrowseMtu(handle) - AVCT_HDR_LEN;
+5 −5
Original line number Original line Diff line number Diff line
@@ -48,9 +48,9 @@ namespace avrcp {
#define VOL_NOT_SUPPORTED -1
#define VOL_NOT_SUPPORTED -1
#define VOL_REGISTRATION_FAILED -2
#define VOL_REGISTRATION_FAILED -2


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


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


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


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


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


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


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


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


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


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