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

Commit ff3147fc authored by tedwang's avatar tedwang
Browse files

Add respond Reject with Invalid parameter for Unknown Capability ID

Add handle Get Capabilities with Unknown Capability ID and unit test
for this.

Bug: 79269978
Test: Run host native test net_test_avrcp
Change-Id: I2cb606bcb6462190354bb471577d9383e43649c1
parent 1d01d1d4
Loading
Loading
Loading
Loading
+8 −0
Original line number Original line Diff line number Diff line
@@ -25,6 +25,14 @@ namespace {
std::vector<uint8_t> get_capabilities_request = {
std::vector<uint8_t> get_capabilities_request = {
    0x01, 0x48, 0x00, 0x00, 0x19, 0x58, 0x10, 0x00, 0x00, 0x01, 0x03};
    0x01, 0x48, 0x00, 0x00, 0x19, 0x58, 0x10, 0x00, 0x00, 0x01, 0x03};


// AVRCP Get Capabilities Request packet with Company ID
std::vector<uint8_t> get_capabilities_request_company_id = {
    0x01, 0x48, 0x00, 0x00, 0x19, 0x58, 0x10, 0x00, 0x00, 0x01, 0x02};

// AVRCP Get Capabilities Request packet with Unknown
std::vector<uint8_t> get_capabilities_request_unknown = {
    0x01, 0x48, 0x00, 0x00, 0x19, 0x58, 0x10, 0x00, 0x00, 0x01, 0x7f};

// AVRCP Get Capabilities Response to Company ID request
// AVRCP Get Capabilities Response to Company ID request
std::vector<uint8_t> get_capabilities_response_company_id = {
std::vector<uint8_t> get_capabilities_response_company_id = {
    0x0c, 0x48, 0x00, 0x00, 0x19, 0x58, 0x10, 0x00, 0x00,
    0x0c, 0x48, 0x00, 0x00, 0x19, 0x58, 0x10, 0x00, 0x00,
+42 −24
Original line number Original line Diff line number Diff line
@@ -90,30 +90,8 @@ void Device::VendorPacketHandler(uint8_t label,


  switch (pkt->GetCommandPdu()) {
  switch (pkt->GetCommandPdu()) {
    case CommandPdu::GET_CAPABILITIES: {
    case CommandPdu::GET_CAPABILITIES: {
      auto capability_request_pkt =
      HandleGetCapabilities(label,
          Packet::Specialize<GetCapabilitiesRequest>(pkt);
                            Packet::Specialize<GetCapabilitiesRequest>(pkt));
      if (capability_request_pkt->GetCapabilityRequested() ==
          Capability::COMPANY_ID) {
        auto response =
            GetCapabilitiesResponseBuilder::MakeCompanyIdBuilder(0x001958);
        response->AddCompanyId(0x002345);
        send_message_cb_.Run(label, false, std::move(response));
      } else {
        auto response =
            GetCapabilitiesResponseBuilder::MakeEventsSupportedBuilder(
                Event::PLAYBACK_STATUS_CHANGED);
        response->AddEvent(Event::TRACK_CHANGED);
        response->AddEvent(Event::PLAYBACK_POS_CHANGED);

        if (!avrcp13_compatibility_) {
          response->AddEvent(Event::AVAILABLE_PLAYERS_CHANGED);
          response->AddEvent(Event::ADDRESSED_PLAYER_CHANGED);
          response->AddEvent(Event::UIDS_CHANGED);
          response->AddEvent(Event::NOW_PLAYING_CONTENT_CHANGED);
        }

        send_message(label, false, std::move(response));
      }
    } break;
    } break;


    case CommandPdu::REGISTER_NOTIFICATION: {
    case CommandPdu::REGISTER_NOTIFICATION: {
@@ -155,6 +133,46 @@ void Device::VendorPacketHandler(uint8_t label,
  }
  }
}
}


void Device::HandleGetCapabilities(
    uint8_t label, const std::shared_ptr<GetCapabilitiesRequest>& pkt) {
  DEVICE_VLOG(4) << __func__
                 << ": capability=" << pkt->GetCapabilityRequested();

  switch (pkt->GetCapabilityRequested()) {
    case Capability::COMPANY_ID: {
      auto response =
          GetCapabilitiesResponseBuilder::MakeCompanyIdBuilder(0x001958);
      response->AddCompanyId(0x002345);
      send_message_cb_.Run(label, false, std::move(response));
    } break;

    case Capability::EVENTS_SUPPORTED: {
      auto response =
          GetCapabilitiesResponseBuilder::MakeEventsSupportedBuilder(
              Event::PLAYBACK_STATUS_CHANGED);
      response->AddEvent(Event::TRACK_CHANGED);
      response->AddEvent(Event::PLAYBACK_POS_CHANGED);

      if (!avrcp13_compatibility_) {
        response->AddEvent(Event::AVAILABLE_PLAYERS_CHANGED);
        response->AddEvent(Event::ADDRESSED_PLAYER_CHANGED);
        response->AddEvent(Event::UIDS_CHANGED);
        response->AddEvent(Event::NOW_PLAYING_CONTENT_CHANGED);
      }

      send_message(label, false, std::move(response));
    } break;

    default: {
      DEVICE_LOG(WARNING) << "Unhandled Capability: "
                          << pkt->GetCapabilityRequested();
      auto response = RejectBuilder::MakeBuilder(CommandPdu::GET_CAPABILITIES,
                                                 Status::INVALID_PARAMETER);
      send_message(label, false, std::move(response));
    } break;
  }
}

void Device::HandleNotification(
void Device::HandleNotification(
    uint8_t label, const std::shared_ptr<RegisterNotificationRequest>& pkt) {
    uint8_t label, const std::shared_ptr<RegisterNotificationRequest>& pkt) {
  DEVICE_VLOG(4) << __func__ << ": event=" << pkt->GetEventRegistered();
  DEVICE_VLOG(4) << __func__ << ": event=" << pkt->GetEventRegistered();
+4 −0
Original line number Original line Diff line number Diff line
@@ -114,6 +114,10 @@ class Device {
      uint8_t label, bool interim, std::string curr_song_id,
      uint8_t label, bool interim, std::string curr_song_id,
      std::vector<SongInfo> song_list);
      std::vector<SongInfo> song_list);


  // GET CAPABILITY
  virtual void HandleGetCapabilities(
      uint8_t label, const std::shared_ptr<GetCapabilitiesRequest>& pkt);

  // REGISTER NOTIFICATION
  // REGISTER NOTIFICATION
  virtual void HandleNotification(
  virtual void HandleNotification(
      uint8_t label, const std::shared_ptr<RegisterNotificationRequest>& pkt);
      uint8_t label, const std::shared_ptr<RegisterNotificationRequest>& pkt);
+49 −1
Original line number Original line Diff line number Diff line
@@ -938,5 +938,53 @@ TEST_F(AvrcpDeviceTest, mediaKeyInactiveDeviceTest) {
  SendMessage(1, play_released_pkt);
  SendMessage(1, play_released_pkt);
}
}


TEST_F(AvrcpDeviceTest, getCapabilitiesTest) {
  MockMediaInterface interface;
  NiceMock<MockA2dpInterface> a2dp_interface;

  test_device->RegisterInterfaces(&interface, &a2dp_interface, nullptr);

  // GetCapabilities with CapabilityID COMPANY_ID
  auto request_company_id_response =
      GetCapabilitiesResponseBuilder::MakeCompanyIdBuilder(0x001958);
  request_company_id_response->AddCompanyId(0x002345);
  EXPECT_CALL(
      response_cb,
      Call(1, false, matchPacket(std::move(request_company_id_response))))
      .Times(1);

  auto request_company_id =
      TestAvrcpPacket::Make(get_capabilities_request_company_id);
  SendMessage(1, request_company_id);

  // GetCapabilities with CapabilityID EVENTS_SUPPORTED
  auto request_events_supported_response =
      GetCapabilitiesResponseBuilder::MakeEventsSupportedBuilder(
          Event::PLAYBACK_STATUS_CHANGED);
  request_events_supported_response->AddEvent(Event::TRACK_CHANGED);
  request_events_supported_response->AddEvent(Event::PLAYBACK_POS_CHANGED);

  EXPECT_CALL(
      response_cb,
      Call(2, false, matchPacket(std::move(request_events_supported_response))))
      .Times(1);

  auto request_events_supported =
      TestAvrcpPacket::Make(get_capabilities_request);
  SendMessage(2, request_events_supported);

  // GetCapabilities with CapabilityID UNKNOWN
  auto request_unknown_response = RejectBuilder::MakeBuilder(
      CommandPdu::GET_CAPABILITIES, Status::INVALID_PARAMETER);

  EXPECT_CALL(response_cb,
              Call(3, false, matchPacket(std::move(request_unknown_response))))
      .Times(1);

  auto request_unknown =
      TestAvrcpPacket::Make(get_capabilities_request_unknown);
  SendMessage(3, request_unknown);
}

}  // namespace avrcp
}  // namespace avrcp
}  // namespace bluetooth
}  // namespace bluetooth