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

Commit 4f867958 authored by Hansong Zhang's avatar Hansong Zhang
Browse files

AVRCP: Respond UID Changed for invalid Get Item Attributes command

When we receive GetItenAttributes command with an invalid UidCounter
other than 0x0000, we should reply UID Changed (0x05)

Bug: 79270308
Test: PTS AVRCP/TG/MCN/CB/BI-05-C; unit test
Change-Id: I819991d083944de5a08b0cd4fd0fb33c63f0142a
parent dad243f7
Loading
Loading
Loading
Loading
+11 −0
Original line number Diff line number Diff line
@@ -271,6 +271,17 @@ std::vector<uint8_t> get_item_attributes_request_all_attributes = {
    0x02, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00,
    0x00, 0x05, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x07};

// AVRCP Get Item Attributes request with all attributes requested
// with the following fields:
//    scope = 0x03 (Now Playing List)
//    uid_counter = 0x0001
//    uid = 0x0000000000000001
std::vector<uint8_t> get_item_attributes_request_all_attributes_invalid = {
    0x73, 0x00, 0x28, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    0x01, 0x00, 0x01, 0x07, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
    0x02, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00,
    0x00, 0x05, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x07};

// AVRCP Get Item Attributes Response with the following attributes:
//    title = "Test Song"
//    artist = "Test Artist"
+9 −1
Original line number Diff line number Diff line
@@ -753,7 +753,15 @@ void Device::ChangePathResponse(uint8_t label,
void Device::HandleGetItemAttributes(
    uint8_t label, std::shared_ptr<GetItemAttributesRequest> pkt) {
  DEVICE_VLOG(2) << __func__ << ": scope=" << pkt->GetScope()
                 << " uid=" << loghex(pkt->GetUid());
                 << " uid=" << loghex(pkt->GetUid())
                 << " uid counter=" << loghex(pkt->GetUidCounter());
  if (pkt->GetUidCounter() != 0x0000) {  // For database unaware player, use 0
    DEVICE_LOG(WARNING) << "UidCounter is invalid";
    auto builder = GetItemAttributesResponseBuilder::MakeBuilder(
        Status::UIDS_CHANGED, browse_mtu_);
    send_message(label, true, std::move(builder));
    return;
  }
  switch (pkt->GetScope()) {
    case Scope::NOW_PLAYING: {
      media_interface_->GetNowPlayingList(
+38 −0
Original line number Diff line number Diff line
@@ -986,5 +986,43 @@ TEST_F(AvrcpDeviceTest, getCapabilitiesTest) {
  SendMessage(3, request_unknown);
}

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

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

  SongInfo info = {"test_id",
                   {// The attribute map
                    AttributeEntry(Attribute::TITLE, "Test Song"),
                    AttributeEntry(Attribute::ARTIST_NAME, "Test Artist"),
                    AttributeEntry(Attribute::ALBUM_NAME, "Test Album"),
                    AttributeEntry(Attribute::TRACK_NUMBER, "1"),
                    AttributeEntry(Attribute::TOTAL_NUMBER_OF_TRACKS, "2"),
                    AttributeEntry(Attribute::GENRE, "Test Genre"),
                    AttributeEntry(Attribute::PLAYING_TIME, "1000")}};
  std::vector<SongInfo> list = {info};

  EXPECT_CALL(interface, GetNowPlayingList(_))
      .WillRepeatedly(InvokeCb<0>("test_id", list));

  auto compare_to_full = GetItemAttributesResponseBuilder::MakeBuilder(
      Status::UIDS_CHANGED, 0xFFFF);
  compare_to_full->AddAttributeEntry(Attribute::TITLE, "Test Song");
  compare_to_full->AddAttributeEntry(Attribute::ARTIST_NAME, "Test Artist");
  compare_to_full->AddAttributeEntry(Attribute::ALBUM_NAME, "Test Album");
  compare_to_full->AddAttributeEntry(Attribute::TRACK_NUMBER, "1");
  compare_to_full->AddAttributeEntry(Attribute::TOTAL_NUMBER_OF_TRACKS, "2");
  compare_to_full->AddAttributeEntry(Attribute::GENRE, "Test Genre");
  compare_to_full->AddAttributeEntry(Attribute::PLAYING_TIME, "1000");
  EXPECT_CALL(response_cb,
              Call(1, true, matchPacket(std::move(compare_to_full))))
      .Times(1);

  auto request = TestBrowsePacket::Make(
      get_item_attributes_request_all_attributes_invalid);
  SendBrowseMessage(1, request);
}

}  // namespace avrcp
}  // namespace bluetooth