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

Commit 3c25e8d1 authored by Ajay Panicker's avatar Ajay Panicker
Browse files

Use proper media ID when changing path

Use the current media ID on the path stack to retrieve folder contents.

Bug: 77237565
Test: run host native test net-test-avrcp
Change-Id: I88d0862f76d18a071a8530cd31954447b4e180fc
parent c3ad060f
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -216,6 +216,11 @@ std::vector<uint8_t> change_path_request = {0x72, 0x00, 0x0b, 0x00, 0x00,
                                            0x01, 0x00, 0x00, 0x00, 0x00,
                                            0x00, 0x00, 0x00, 0x02};

// AVRCP Browse Change Path Request up
std::vector<uint8_t> change_path_up_request = {0x72, 0x00, 0x0b, 0x00, 0x00,
                                               0x00, 0xFF, 0xFF, 0xFF, 0xFF,
                                               0xFF, 0xFF, 0xFF, 0xFF};

// AVRCP Browse Change Path Response with two items in current folder
std::vector<uint8_t> change_path_response = {0x72, 0x00, 0x05, 0x04,
                                             0x00, 0x00, 0x00, 0x02};
+9 −7
Original line number Diff line number Diff line
@@ -603,7 +603,8 @@ void Device::HandleChangePath(uint8_t label,

  if (pkt->GetDirection() == Direction::DOWN &&
      vfs_ids_.get_media_id(pkt->GetUid()) == "") {
    DEVICE_LOG(ERROR) << "No item found for UID=" << pkt->GetUid();
    DEVICE_LOG(ERROR) << __func__
                      << ": No item found for UID=" << pkt->GetUid();
    auto builder =
        ChangePathResponseBuilder::MakeBuilder(Status::DOES_NOT_EXIST, 0);
    send_message(label, true, std::move(builder));
@@ -611,14 +612,13 @@ void Device::HandleChangePath(uint8_t label,
  }

  if (pkt->GetDirection() == Direction::DOWN) {
    DEVICE_VLOG(2) << "Pushing Path to stack: \""
                   << vfs_ids_.get_media_id(pkt->GetUid()) << "\"";
    current_path_.push(vfs_ids_.get_media_id(pkt->GetUid()));
    DEVICE_VLOG(2) << "Pushing Path to stack: \"" << CurrentFolder() << "\"";
  } else {
    // Don't pop the root id off the stack
    if (current_path_.size() > 1)
    if (current_path_.size() > 1) {
      current_path_.pop();
    else {
    } else {
      DEVICE_LOG(ERROR) << "Trying to change directory up past root.";
      auto builder =
          ChangePathResponseBuilder::MakeBuilder(Status::DOES_NOT_EXIST, 0);
@@ -628,11 +628,13 @@ void Device::HandleChangePath(uint8_t label,

    DEVICE_VLOG(2) << "Popping Path from stack: new path=\"" << CurrentFolder()
                   << "\"";
    vfs_ids_.clear();
  }

  // All of the VFS ID's are no longer valid
  vfs_ids_.clear();

  media_interface_->GetFolderItems(
      curr_browsed_player_id_, vfs_ids_.get_media_id(pkt->GetUid()),
      curr_browsed_player_id_, CurrentFolder(),
      base::Bind(&Device::ChangePathResponse, base::Unretained(this), label,
                 pkt));
}
+79 −0
Original line number Diff line number Diff line
@@ -391,6 +391,85 @@ TEST_F(AvrcpDeviceTest, getVFSFolderTest) {
  SendBrowseMessage(1, request);
}

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

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

  FolderInfo info0 = {"test_id0", true, "Test Folder0"};
  FolderInfo info1 = {"test_id1", true, "Test Folder1"};
  ListItem item0 = {ListItem::FOLDER, info0, SongInfo()};
  ListItem item1 = {ListItem::FOLDER, info1, SongInfo()};
  std::vector<ListItem> list0 = {item0, item1};
  EXPECT_CALL(interface, GetFolderItems(_, "", _))
      .Times(1)
      .WillRepeatedly(InvokeCb<2>(list0));

  FolderInfo info2 = {"test_id2", true, "Test Folder2"};
  FolderInfo info3 = {"test_id3", true, "Test Folder3"};
  FolderInfo info4 = {"test_id4", true, "Test Folder4"};
  ListItem item2 = {ListItem::FOLDER, info2, SongInfo()};
  ListItem item3 = {ListItem::FOLDER, info3, SongInfo()};
  ListItem item4 = {ListItem::FOLDER, info4, SongInfo()};
  std::vector<ListItem> list1 = {item2, item3, item4};
  EXPECT_CALL(interface, GetFolderItems(_, "test_id1", _))
      .Times(3)
      .WillRepeatedly(InvokeCb<2>(list1));

  std::vector<ListItem> list2 = {};
  EXPECT_CALL(interface, GetFolderItems(_, "test_id3", _))
      .Times(1)
      .WillOnce(InvokeCb<2>(list2));

  // Populate the VFS ID map since we don't persist UIDs
  auto folder_items_response =
      GetFolderItemsResponseBuilder::MakeVFSBuilder(Status::NO_ERROR, 0x0000);
  folder_items_response->AddFolder(FolderItem(1, 0, true, "Test Folder0"));
  folder_items_response->AddFolder(FolderItem(2, 0, true, "Test Folder1"));
  EXPECT_CALL(response_cb,
              Call(1, true, matchPacket(std::move(folder_items_response))))
      .Times(1);
  auto request = TestBrowsePacket::Make(get_folder_items_request_vfs);
  SendBrowseMessage(1, request);

  // Change path down into Test Folder1
  auto change_path_response =
      ChangePathResponseBuilder::MakeBuilder(Status::NO_ERROR, list1.size());
  EXPECT_CALL(response_cb,
              Call(2, true, matchPacket(std::move(change_path_response))));
  request = TestBrowsePacket::Make(change_path_request);
  SendBrowseMessage(2, request);

  // Populate the VFS ID map since we don't persist UIDs
  folder_items_response =
      GetFolderItemsResponseBuilder::MakeVFSBuilder(Status::NO_ERROR, 0x0000);
  folder_items_response->AddFolder(FolderItem(1, 0, true, "Test Folder2"));
  folder_items_response->AddFolder(FolderItem(2, 0, true, "Test Folder3"));
  folder_items_response->AddFolder(FolderItem(3, 0, true, "Test Folder4"));
  EXPECT_CALL(response_cb,
              Call(3, true, matchPacket(std::move(folder_items_response))))
      .Times(1);
  request = TestBrowsePacket::Make(get_folder_items_request_vfs);
  SendBrowseMessage(3, request);

  // Change path down into Test Folder3
  change_path_response =
      ChangePathResponseBuilder::MakeBuilder(Status::NO_ERROR, list2.size());
  EXPECT_CALL(response_cb,
              Call(4, true, matchPacket(std::move(change_path_response))));
  request = TestBrowsePacket::Make(change_path_request);
  SendBrowseMessage(4, request);

  // Change path up back into Test Folder1
  change_path_response =
      ChangePathResponseBuilder::MakeBuilder(Status::NO_ERROR, list1.size());
  EXPECT_CALL(response_cb,
              Call(5, true, matchPacket(std::move(change_path_response))));
  request = TestBrowsePacket::Make(change_path_up_request);
  SendBrowseMessage(5, request);
}

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