OSDN Git Service

Refresh the now playing ID map when the now playing list changes
authorAjay Panicker <apanicke@google.com>
Mon, 2 Apr 2018 22:36:35 +0000 (15:36 -0700)
committerAjay Panicker <apanicke@google.com>
Tue, 3 Apr 2018 19:39:22 +0000 (12:39 -0700)
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
(cherry picked from commit e016b53fa445e29dcc1d8594f5142f3a6f5358ef)

profile/avrcp/device.cc
profile/avrcp/device.h
profile/avrcp/tests/avrcp_device_test.cc

index 9d6c5e3..34e8d21 100644 (file)
@@ -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,10 +1009,32 @@ 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));
-  now_playing_changed_ = Notification(false, 0);
+
+  if (!interim) {
+    active_labels_.erase(label);
+    now_playing_changed_ = Notification(false, 0);
+  }
 }
 
 void Device::HandlePlayPosUpdate() {
index 17cd243..33b5662 100644 (file)
@@ -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();
index 35776fe..bcdcac2 100644 (file)
@@ -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);