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

Commit c7353aa0 authored by Ajay Panicker's avatar Ajay Panicker
Browse files

Refresh the now playing ID map when the now playing list changes

The Now Playing List ID's could be invalid if the now playing list
changes but there is not track change, like when adding a song to the
queue on the device.

Bug: 68812037
Test: Run host native test net_test_avrcp
Change-Id: I3c2c11aa87b64241f378819c38ae5cc21ffdb5ac
parent 3d75d1dc
Loading
Loading
Loading
Loading
+27 −6
Original line number Diff line number Diff line
@@ -180,11 +180,10 @@ void Device::HandleNotification(
    } break;

    case Event::NOW_PLAYING_CONTENT_CHANGED: {
      // Respond immediately since this notification doesn't require any info
      now_playing_changed_ = Notification(true, label);
      auto response =
          RegisterNotificationResponseBuilder::MakeNowPlayingBuilder(true);
      send_message(label, false, std::move(response));
      media_interface_->GetNowPlayingList(base::Bind(
          &Device::HandleNowPlayingNotificationResponse, base::Unretained(this),
          now_playing_changed_.second, true));
    } break;

    case Event::AVAILABLE_PLAYERS_CHANGED: {
@@ -1010,11 +1009,33 @@ void Device::HandleNowPlayingUpdate() {
    return;
  }

  media_interface_->GetNowPlayingList(
      base::Bind(&Device::HandleNowPlayingNotificationResponse,
                 base::Unretained(this), now_playing_changed_.second, false));
}

void Device::HandleNowPlayingNotificationResponse(
    uint8_t label, bool interim, std::string curr_song_id,
    std::vector<SongInfo> song_list) {
  if (!now_playing_changed_.first) {
    LOG(WARNING) << "Device is not registered for now playing updates";
    return;
  }

  now_playing_ids_.clear();
  for (const SongInfo& song : song_list) {
    now_playing_ids_.insert(song.media_id);
  }

  auto response =
      RegisterNotificationResponseBuilder::MakeNowPlayingBuilder(false);
      RegisterNotificationResponseBuilder::MakeNowPlayingBuilder(interim);
  send_message(now_playing_changed_.second, false, std::move(response));

  if (!interim) {
    active_labels_.erase(label);
    now_playing_changed_ = Notification(false, 0);
  }
}

void Device::HandlePlayPosUpdate() {
  DEVICE_VLOG(0) << __func__;
+3 −0
Original line number Diff line number Diff line
@@ -123,6 +123,9 @@ class Device {

  // NOW PLAYING LIST CHANGED
  virtual void HandleNowPlayingUpdate();
  virtual void HandleNowPlayingNotificationResponse(
      uint8_t label, bool interim, std::string curr_song_id,
      std::vector<SongInfo> song_list);

  // PLAY POSITION CHANGED
  virtual void HandlePlayPosUpdate();
+14 −0
Original line number Diff line number Diff line
@@ -224,6 +224,20 @@ TEST_F(AvrcpDeviceTest, nowPlayingTest) {

  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(_))
      .Times(2)
      .WillRepeatedly(InvokeCb<0>("test_id", list));

  // Test the interim response for now playing list changed
  auto interim_response =
      RegisterNotificationResponseBuilder::MakeNowPlayingBuilder(true);