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

Commit e0c41bdd authored by Ajay Panicker's avatar Ajay Panicker Committed by Myles Watson
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
(cherry picked from commit aeed100e)
parent 8bbf485e
Loading
Loading
Loading
Loading
+27 −41
Original line number Original line Diff line number Diff line
@@ -93,12 +93,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
        // 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.
        // because some CTs ask for it.
        if (Arrays.equals(itemAttr.mUid, AvrcpConstants.TRACK_IS_SELECTED)) {
        if (Arrays.equals(itemAttr.mUid, AvrcpConstants.TRACK_IS_SELECTED)) {
            if (DEBUG) Log.d(TAG, "getItemAttr: Remote requests for now playing contents:");
            mediaId = getActiveQueueItemId(mediaController);

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


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

            // Because we are database-unaware, we can just number the item here whatever we want
            // Because we are database-unaware, we can just number the item here whatever we want
            // because they have to re-poll it every time.
            // because they have to re-poll it every time.
            MediaSession.QueueItem current = getCurrentQueueItem(mediaController, SINGLE_QID);
            MediaMetadata metadata = mediaController.getMetadata();
            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();
            if (metadata == null) {
            if (metadata == null) {
                Log.w(TAG, "Controller has no metadata!? Making an empty one");
                Log.w(TAG, "Controller has no metadata!? Making an empty one");
                metadata = (new MediaMetadata.Builder()).build();
                metadata = (new MediaMetadata.Builder()).build();
@@ -171,8 +143,22 @@ public class AddressedMediaPlayer {
            bob.setExtras(fillBundle(metadata, desc.getExtras()));
            bob.setExtras(fillBundle(metadata, desc.getExtras()));


            // build queue item with the new metadata
            // build queue item with the new metadata
        desc = bob.build();
            MediaSession.QueueItem current = new QueueItem(bob.build(), SINGLE_QID);
        return new QueueItem(desc, 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) {
    private Bundle fillBundle(MediaMetadata metadata, Bundle currentExtras) {