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

Commit 134db4fd authored by Marie Janssen's avatar Marie Janssen
Browse files

AVRCP: Fix issues around trackChanged notification

When the track changes, sometimes the Queue ID changes before the
Metadata, and vice versa.  Indicate that the track info has changed in
either case.

Guard against unsolicited responses since we are triggering more often.

Use the MediaController info for GetItemAttributes when the requested
id matches the current id.

Test: connect to Chrysler CK, switch to next track a few times, look for
good data.
Bug: 37707672
Change-Id: I6bffd419e22e1a029e11f9340afde54be00d3efc
parent f154dde4
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -806,10 +806,15 @@ static jboolean registerNotificationRspTrackChangeNative(JNIEnv* env,
  }

  btrc_register_notification_t param;
  uint64_t uid = 0;
  for (int uid_idx = 0; uid_idx < BTRC_UID_SIZE; ++uid_idx) {
    param.track[uid_idx] = trk[uid_idx];
    uid = uid + (trk[uid_idx] << (BTRC_UID_SIZE - 1 - uid_idx));
  }

  ALOGV("%s: Sending track change notification: %d -> %llu", __func__, type,
        uid);

  bt_status_t status = sBluetoothAvrcpInterface->register_notification_rsp(
      BTRC_EVT_TRACK_CHANGE, (btrc_notification_type_t)type, &param);
  if (status != BT_STATUS_SUCCESS) {
+13 −8
Original line number Diff line number Diff line
@@ -175,18 +175,18 @@ public class AddressedMediaPlayer {
            return currentExtras;
        }

        String[] stringKeys = {MediaMetadata.METADATA_KEY_ARTIST, MediaMetadata.METADATA_KEY_ALBUM,
                MediaMetadata.METADATA_KEY_GENRE};
        String[] longKeys = {MediaMetadata.METADATA_KEY_TRACK_NUMBER,
                MediaMetadata.METADATA_KEY_NUM_TRACKS, MediaMetadata.METADATA_KEY_DURATION};

        Bundle bundle = currentExtras;
        if (bundle == null) bundle = new Bundle();

        String[] stringKeys = {MediaMetadata.METADATA_KEY_TITLE, MediaMetadata.METADATA_KEY_ARTIST,
                MediaMetadata.METADATA_KEY_ALBUM, MediaMetadata.METADATA_KEY_GENRE};
        for (String key : stringKeys) {
            String current = bundle.getString(key);
            if (current == null) bundle.putString(key, metadata.getString(key));
        }

        String[] longKeys = {MediaMetadata.METADATA_KEY_TRACK_NUMBER,
                MediaMetadata.METADATA_KEY_NUM_TRACKS, MediaMetadata.METADATA_KEY_DURATION};
        for (String key : longKeys) {
            if (!bundle.containsKey(key)) bundle.putLong(key, metadata.getLong(key));
        }
@@ -408,15 +408,20 @@ public class AddressedMediaPlayer {
        try {
            MediaDescription desc = item.getDescription();
            Bundle extras = desc.getExtras();
            if (item.getQueueId() == getActiveQueueItemId(mediaController)) {
                if (DEBUG) Log.d(TAG, "getAttrValue: item is active, filling extra data");
            boolean isCurrentTrack = item.getQueueId() == getActiveQueueItemId(mediaController);
            if (isCurrentTrack) {
                if (DEBUG) Log.d(TAG, "getAttrValue: item is active, using current data");
                extras = fillBundle(mediaController.getMetadata(), extras);
            }
            if (DEBUG) Log.d(TAG, "getAttrValue: item " + item + " : " + desc);
            switch (attr) {
                case AvrcpConstants.ATTRID_TITLE:
                    /* Title is mandatory attribute */
                    if (isCurrentTrack) {
                        attrValue = extras.getString(MediaMetadata.METADATA_KEY_TITLE);
                    } else {
                        attrValue = desc.getTitle().toString();
                    }
                    break;

                case AvrcpConstants.ATTRID_ARTIST:
+7 −5
Original line number Diff line number Diff line
@@ -974,12 +974,10 @@ public final class Avrcp {
        long oldQueueId = mCurrentPlayState.getActiveQueueItemId();
        long newQueueId = MediaSession.QueueItem.UNKNOWN_ID;
        if (newState != null) newQueueId = newState.getActiveQueueItemId();
        if ((oldQueueId != newQueueId) || (!currentAttributes.equals(mMediaAttributes))) {
            Log.v(TAG, "Media change: id " + oldQueueId + "➡" + newQueueId + ":"
        Log.v(TAG, "Media update: id " + oldQueueId + "➡" + newQueueId + ":"
                        + mMediaAttributes.toString());
        if (oldQueueId != newQueueId || !currentAttributes.equals(mMediaAttributes)) {
            sendTrackChangedRsp(false);
        } else {
            Log.v(TAG, "Media didn't change: id " + oldQueueId);
        }

        updatePlaybackState(newState);
@@ -1071,6 +1069,10 @@ public final class Avrcp {

    private void sendTrackChangedRsp(boolean requested) {
        MediaPlayerInfo info = getAddressedPlayerInfo();
        if (!requested && mTrackChangedNT != AvrcpConstants.NOTIFICATION_TYPE_INTERIM) {
            if (DEBUG) Log.d(TAG, "sendTrackChangedRsp: Not registered or requesting.");
            return;
        }
        if (info != null && !info.isBrowseSupported()) {
            // for players which does not support Browse or when no track is currently selected
            trackChangeRspForBrowseUnsupported(requested);