OSDN Git Service

AVRCP: Respond UID Changed for invalid Get Item Attributes command
authorHansong Zhang <hsz@google.com>
Mon, 14 May 2018 18:29:20 +0000 (11:29 -0700)
committerHansong Zhang <hsz@google.com>
Tue, 15 May 2018 20:34:29 +0000 (13:34 -0700)
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
(cherry picked from commit 335d6e62b0fe2d81375254c9c5114867d524fc19)

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

index 41177ac..0274a56 100644 (file)
@@ -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"
index 6e07f05..3a63719 100644 (file)
@@ -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(
index c0c31ac..63bd208 100644 (file)
@@ -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