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

Commit aeed100e authored by Ajay Panicker's avatar Ajay Panicker
Browse files

Use the current item in the existing queue rather than using metadata

GPM adds additional info into the bundle under a specific key which contains
extra metadata. When a carkit (Magneti BMW does this) requests UID 0 with
getItemAttributes, we would construct a queueItem out of the current song.
This breaks with GPM as the metadata returned from getMetadata() from their
MediaController would not be filled or contain this additional bundle. Instead
always use updateNowPlayingList as it can construct a queue with all the info
we have.

Bug: 65166802
Test: Test switching playlists in GPM with Magneti BWM and see that more info
      other than the song title shows up.
Change-Id: Ie96b3a5eccb94b86337936c913c3e81b67745362
parent b79e00ad
Loading
Loading
Loading
Loading
+27 −41
Original line number Diff line number Diff line
@@ -96,12 +96,12 @@ public class AddressedMediaPlayer {
        // NOTE: this is out-of-spec (AVRCP 1.6.1 sec 6.10.4.3, p90) but we answer it anyway
        // because some CTs ask for it.
        if (Arrays.equals(itemAttr.mUid, AvrcpConstants.TRACK_IS_SELECTED)) {
            if (DEBUG) Log.d(TAG, "getItemAttr: Remote requests for now playing contents:");

            // get the current playing metadata and send.
            getItemAttrFilterAttr(bdaddr, itemAttr, getCurrentQueueItem(mediaController, mediaId),
                    mediaController);
            return;
            mediaId = getActiveQueueItemId(mediaController);
            if (DEBUG) {
                Log.d(TAG,
                        "getItemAttr: Remote requests for now playing contents, sending UID: "
                                + mediaId);
            }
        }

        if (DEBUG) Log.d(TAG, "getItemAttr-UID: 0x" + Utils.byteArrayToString(itemAttr.mUid));
@@ -125,38 +125,10 @@ public class AddressedMediaPlayer {
        if (items == null) {
            Log.i(TAG, "null queue from " + mediaController.getPackageName()
                            + ", constructing single-item list");
            MediaMetadata metadata = mediaController.getMetadata();

            // Because we are database-unaware, we can just number the item here whatever we want
            // because they have to re-poll it every time.
            MediaSession.QueueItem current = getCurrentQueueItem(mediaController, SINGLE_QID);
            items = new ArrayList<MediaSession.QueueItem>();
            items.add(current);
        }

        if (!items.equals(mNowPlayingList)) sendNowPlayingListChanged();
        mNowPlayingList = items;

        return mNowPlayingList;
    }

    private void sendNowPlayingListChanged() {
        if (mMediaInterface == null) return;
        if (DEBUG) Log.d(TAG, "sendNowPlayingListChanged()");
        mMediaInterface.nowPlayingChangedRsp(AvrcpConstants.NOTIFICATION_TYPE_CHANGED);
    }

    /* Constructs a queue item representing the current playing metadata from an
     * active controller with queue id |qid|.
     */
    private MediaSession.QueueItem getCurrentQueueItem(
            @Nullable MediaController controller, long qid) {
        if (controller == null) {
            MediaDescription.Builder bob = new MediaDescription.Builder();
            bob.setTitle(UNKNOWN_TITLE);
            return new QueueItem(bob.build(), qid);
        }

        MediaMetadata metadata = controller.getMetadata();
            MediaMetadata metadata = mediaController.getMetadata();
            if (metadata == null) {
                Log.w(TAG, "Controller has no metadata!? Making an empty one");
                metadata = (new MediaMetadata.Builder()).build();
@@ -174,8 +146,22 @@ public class AddressedMediaPlayer {
            bob.setExtras(fillBundle(metadata, desc.getExtras()));

            // build queue item with the new metadata
        desc = bob.build();
        return new QueueItem(desc, qid);
            MediaSession.QueueItem current = new QueueItem(bob.build(), SINGLE_QID);

            items = new ArrayList<MediaSession.QueueItem>();
            items.add(current);
        }

        if (!items.equals(mNowPlayingList)) sendNowPlayingListChanged();
        mNowPlayingList = items;

        return mNowPlayingList;
    }

    private void sendNowPlayingListChanged() {
        if (mMediaInterface == null) return;
        if (DEBUG) Log.d(TAG, "sendNowPlayingListChanged()");
        mMediaInterface.nowPlayingChangedRsp(AvrcpConstants.NOTIFICATION_TYPE_CHANGED);
    }

    private Bundle fillBundle(MediaMetadata metadata, Bundle currentExtras) {