OSDN Git Service

Merge "AVRCP: Change notification variable when the interim response is sent" into...
[android-x86/system-bt.git] / profile / avrcp / device.cc
index 9a31ef3..9b25fac 100644 (file)
@@ -194,21 +194,18 @@ void Device::HandleNotification(
 
   switch (pkt->GetEventRegistered()) {
     case Event::TRACK_CHANGED: {
-      track_changed_ = Notification(true, label);
       media_interface_->GetNowPlayingList(
           base::Bind(&Device::TrackChangedNotificationResponse,
                      weak_ptr_factory_.GetWeakPtr(), label, true));
     } break;
 
     case Event::PLAYBACK_STATUS_CHANGED: {
-      play_status_changed_ = Notification(true, label);
       media_interface_->GetPlayStatus(
           base::Bind(&Device::PlaybackStatusNotificationResponse,
                      weak_ptr_factory_.GetWeakPtr(), label, true));
     } break;
 
     case Event::PLAYBACK_POS_CHANGED: {
-      play_pos_changed_ = Notification(true, label);
       play_pos_interval_ = pkt->GetInterval();
       media_interface_->GetPlayStatus(
           base::Bind(&Device::PlaybackPosNotificationResponse,
@@ -216,13 +213,15 @@ void Device::HandleNotification(
     } break;
 
     case Event::NOW_PLAYING_CONTENT_CHANGED: {
-      now_playing_changed_ = Notification(true, label);
-      media_interface_->GetNowPlayingList(base::Bind(
-          &Device::HandleNowPlayingNotificationResponse,
-          weak_ptr_factory_.GetWeakPtr(), now_playing_changed_.second, true));
+      media_interface_->GetNowPlayingList(
+          base::Bind(&Device::HandleNowPlayingNotificationResponse,
+                     weak_ptr_factory_.GetWeakPtr(), label, true));
     } break;
 
     case Event::AVAILABLE_PLAYERS_CHANGED: {
+      // TODO (apanicke): If we make a separate handler function for this, make
+      // sure to register the notification in the interim response.
+
       // Respond immediately since this notification doesn't require any info
       avail_players_changed_ = Notification(true, label);
       auto response =
@@ -232,13 +231,15 @@ void Device::HandleNotification(
     } break;
 
     case Event::ADDRESSED_PLAYER_CHANGED: {
-      addr_player_changed_ = Notification(true, label);
       media_interface_->GetMediaPlayerList(
           base::Bind(&Device::AddressedPlayerNotificationResponse,
                      weak_ptr_factory_.GetWeakPtr(), label, true));
     } break;
 
     case Event::UIDS_CHANGED: {
+      // TODO (apanicke): If we make a separate handler function for this, make
+      // sure to register the notification in the interim response.
+
       // Respond immediately since this notification doesn't require any info
       uids_changed_ = Notification(true, label);
       auto response =
@@ -351,7 +352,9 @@ void Device::TrackChangedNotificationResponse(uint8_t label, bool interim,
   DEVICE_VLOG(1) << __func__;
   uint64_t uid = 0;
 
-  if (!track_changed_.first) {
+  if (interim) {
+    track_changed_ = Notification(true, label);
+  } else if (!track_changed_.first) {
     DEVICE_VLOG(0) << __func__ << ": Device not registered for update";
     return;
   }
@@ -391,7 +394,9 @@ void Device::PlaybackStatusNotificationResponse(uint8_t label, bool interim,
   DEVICE_VLOG(1) << __func__;
   if (status.state == PlayState::PAUSED) play_pos_update_cb_.Cancel();
 
-  if (!play_status_changed_.first) {
+  if (interim) {
+    play_status_changed_ = Notification(true, label);
+  } else if (!play_status_changed_.first) {
     DEVICE_VLOG(0) << __func__ << ": Device not registered for update";
     return;
   }
@@ -422,7 +427,9 @@ void Device::PlaybackPosNotificationResponse(uint8_t label, bool interim,
                                              PlayStatus status) {
   DEVICE_VLOG(4) << __func__;
 
-  if (!play_pos_changed_.first) {
+  if (interim) {
+    play_pos_changed_ = Notification(true, label);
+  } else if (!play_pos_changed_.first) {
     DEVICE_VLOG(3) << __func__ << ": Device not registered for update";
     return;
   }
@@ -465,6 +472,14 @@ void Device::AddressedPlayerNotificationResponse(
     std::vector<MediaPlayerInfo> /* unused */) {
   DEVICE_VLOG(1) << __func__
                  << ": curr_player_id=" << (unsigned int)curr_player;
+
+  if (interim) {
+    addr_player_changed_ = Notification(true, label);
+  } else if (!addr_player_changed_.first) {
+    DEVICE_VLOG(3) << __func__ << ": Device not registered for update";
+    return;
+  }
+
   // If there is no set browsed player, use the current addressed player as the
   // default NOTE: Using any browsing commands before the browsed player is set
   // is a violation of the AVRCP Spec but there are some carkits that try too
@@ -1184,7 +1199,9 @@ void Device::HandleNowPlayingUpdate() {
 void Device::HandleNowPlayingNotificationResponse(
     uint8_t label, bool interim, std::string curr_song_id,
     std::vector<SongInfo> song_list) {
-  if (!now_playing_changed_.first) {
+  if (interim) {
+    now_playing_changed_ = Notification(true, label);
+  } else if (!now_playing_changed_.first) {
     LOG(WARNING) << "Device is not registered for now playing updates";
     return;
   }