OSDN Git Service

Send addressed and available player change for PTS test
authortedwang <tedwang@google.com>
Fri, 18 May 2018 10:16:40 +0000 (18:16 +0800)
committerHansong Zhang <hsz@google.com>
Tue, 29 May 2018 23:31:14 +0000 (16:31 -0700)
Implement HandleAddressPlayerUpdate() and HandAvailablePlayerUpdate()
for PTS test.

Bug: 79375787 79376305
Test: PTS Test AVRCPTG/MPS/BV-05-C AVRCP/TG/MPS/BV-07-C
Change-Id: I6b976af8bdd1afcc9799c50c8e558939cf7be187

profile/avrcp/device.cc
profile/avrcp/device.h

index 3ab87dd..7baf770 100644 (file)
@@ -227,7 +227,7 @@ void Device::HandleNotification(
       addr_player_changed_ = Notification(true, label);
       media_interface_->GetMediaPlayerList(
           base::Bind(&Device::AddressedPlayerNotificationResponse,
-                     weak_ptr_factory_.GetWeakPtr(), label, false));
+                     weak_ptr_factory_.GetWeakPtr(), label, true));
     } break;
 
     case Event::UIDS_CHANGED: {
@@ -465,12 +465,28 @@ void Device::AddressedPlayerNotificationResponse(
 
   auto response =
       RegisterNotificationResponseBuilder::MakeAddressedPlayerBuilder(
-          true, curr_player, 0x0000);
+          interim, curr_player, 0x0000);
   send_message_cb_.Run(label, false, std::move(response));
 
   if (!interim) {
     active_labels_.erase(label);
     addr_player_changed_ = Notification(false, 0);
+    RejectNotification();
+  }
+}
+
+void Device::RejectNotification() {
+  DEVICE_VLOG(1) << __func__;
+  Notification* rejectNotification[] = {&play_status_changed_, &track_changed_,
+                                        &play_pos_changed_,
+                                        &now_playing_changed_};
+  for (int i = 0; i < 4; i++) {
+    uint8_t label = rejectNotification[i]->second;
+    auto response = RejectBuilder::MakeBuilder(
+        CommandPdu::REGISTER_NOTIFICATION, Status::ADDRESSED_PLAYER_CHANGED);
+    send_message_cb_.Run(label, false, std::move(response));
+    active_labels_.erase(label);
+    rejectNotification[i] = new Notification(false, 0);
   }
 }
 
@@ -1094,16 +1110,12 @@ void Device::SendFolderUpdate(bool available_players, bool addressed_player,
   DEVICE_VLOG(4) << __func__;
 
   if (available_players) {
-    // TODO (apanicke): Right now this isn't needed since we only show one
-    // player. Implement this in the future for a more complete
-    // implementation though.
+    HandleAvailablePlayerUpdate();
   }
 
   if (addressed_player) {
-    // TODO (apanicke): See above TODO.
+    HandleAddressedPlayerUpdate();
   }
-
-  CHECK(false) << "NEED TO IMPLEMENT";
 }
 
 void Device::HandleTrackUpdate() {
@@ -1178,6 +1190,37 @@ void Device::HandlePlayPosUpdate() {
       play_pos_changed_.second, false));
 }
 
+void Device::HandleAvailablePlayerUpdate() {
+  DEVICE_VLOG(1) << __func__;
+
+  if (!avail_players_changed_.first) {
+    LOG(WARNING) << "Device is not registered for available player updates";
+    return;
+  }
+
+  auto response =
+      RegisterNotificationResponseBuilder::MakeAvailablePlayersBuilder(false);
+  send_message_cb_.Run(avail_players_changed_.second, false,
+                       std::move(response));
+
+  if (!avail_players_changed_.first) {
+    active_labels_.erase(avail_players_changed_.second);
+    avail_players_changed_ = Notification(false, 0);
+  }
+}
+
+void Device::HandleAddressedPlayerUpdate() {
+  DEVICE_VLOG(1) << __func__;
+  if (!addr_player_changed_.first) {
+    DEVICE_LOG(WARNING)
+        << "Device is not registered for addressed player updates";
+    return;
+  }
+  media_interface_->GetMediaPlayerList(base::Bind(
+      &Device::AddressedPlayerNotificationResponse,
+      weak_ptr_factory_.GetWeakPtr(), addr_player_changed_.second, false));
+}
+
 void Device::DeviceDisconnected() {
   DEVICE_LOG(INFO) << "Device was disconnected";
   play_pos_update_cb_.Cancel();
index 7fcb3a5..27f7674 100644 (file)
@@ -149,7 +149,12 @@ class Device {
       uint8_t label, std::shared_ptr<GetElementAttributesRequest> pkt,
       SongInfo info);
 
+  // AVAILABLE PLAYER CHANGED
+  virtual void HandleAvailablePlayerUpdate();
+
   // ADDRESSED PLAYER CHANGED
+  virtual void HandleAddressedPlayerUpdate();
+  virtual void RejectNotification();
   virtual void AddressedPlayerNotificationResponse(
       uint8_t label, bool interim, uint16_t curr_player,
       std::vector<MediaPlayerInfo> /* unused */);