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

Commit 315dcd4f authored by Ajay Panicker's avatar Ajay Panicker
Browse files

Don't add items to a response if a previous item fails to be added

Bug: 112164711
Test: Run native test net_test_avrcp
Change-Id: Iace287bb716b28eda62a8a0500deb99cc46ae485
parent 017c7e02
Loading
Loading
Loading
Loading
+8 −3
Original line number Diff line number Diff line
@@ -1036,7 +1036,7 @@ void Device::GetVFSListResponse(uint8_t label,
      // right now we always use folders of mixed type
      FolderItem folder_item(vfs_ids_.get_uid(folder.media_id), 0x00,
                             folder.is_playable, folder.name);
      builder->AddFolder(folder_item);
      if (!builder->AddFolder(folder_item)) break;
    } else if (items[i].type == ListItem::SONG) {
      auto song = items[i].song;
      auto title =
@@ -1053,7 +1053,9 @@ void Device::GetVFSListResponse(uint8_t label,
            filter_attributes_requested(song, pkt->GetAttributesRequested());
      }

      builder->AddSong(song_item);
      // If we fail to add a song, don't accidentally add one later that might
      // fit.
      if (!builder->AddSong(song_item)) break;
    }
  }

@@ -1086,7 +1088,10 @@ void Device::GetNowPlayingListResponse(
      item.attributes_ =
          filter_attributes_requested(song, pkt->GetAttributesRequested());
    }
    builder->AddSong(item);

    // If we fail to add a song, don't accidentally add one later that might
    // fit.
    if (!builder->AddSong(item)) break;
  }

  send_message(label, true, std::move(builder));
+12 −4
Original line number Diff line number Diff line
@@ -527,16 +527,24 @@ TEST_F(AvrcpDeviceTest, getFolderItemsMtuTest) {
      base::Bind([](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());

  Device device(RawAddress::kAny, true, cb, 0xFFFF,
                truncated_packet->size() + FolderItem::kHeaderSize() + 5);
  device.RegisterInterfaces(&interface, &a2dp_interface, nullptr);

  FolderInfo info0 = {"test_id0", true, "Test Folder0"};
  FolderInfo info1 = {"test_id1", true, "Test Folder1"};
  FolderInfo info2 = {"test_id1", true, "Truncated folder"};
  FolderInfo info2 = {"test_id2", true, "Truncated folder"};
  // Used to ensure that adding an item that would fit in the MTU fails if
  // adding a large item failed.
  FolderInfo small_info = {"test_id2", true, "Small"};

  ListItem item0 = {ListItem::FOLDER, info0, SongInfo()};
  ListItem item1 = {ListItem::FOLDER, info1, SongInfo()};
  ListItem item2 = {ListItem::FOLDER, info1, SongInfo()};
  std::vector<ListItem> list0 = {item0, item1, item2};
  ListItem item2 = {ListItem::FOLDER, info2, SongInfo()};
  ListItem item3 = {ListItem::FOLDER, small_info, SongInfo()};

  std::vector<ListItem> list0 = {item0, item1, item2, item3};
  EXPECT_CALL(interface, GetFolderItems(_, "", _))
      .WillRepeatedly(InvokeCb<2>(list0));