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

Commit 32c916f2 authored by Treehugger Robot's avatar Treehugger Robot Committed by Gerrit Code Review
Browse files

Merge "Disable the Now Playing List for players with no active item"

parents b3197b48 4598dac7
Loading
Loading
Loading
Loading
+19 −5
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@

package com.android.bluetooth.avrcp;

import android.annotation.NonNull;
import android.content.BroadcastReceiver;
import android.content.ComponentName;
import android.content.Context;
@@ -222,19 +223,28 @@ public class MediaPlayerList {
        return ret;
    }

    @NonNull
    String getCurrentMediaId() {
        final MediaPlayerWrapper player = getActivePlayer();
        if (player == null) return "";

        final PlaybackState state = player.getPlaybackState();
        if (state == null || state.getActiveQueueItemId() == MediaSession.QueueItem.UNKNOWN_ID) {
            d("getCurrentMediaId: No active queue item Id: " + state);
        final List<Metadata> queue = player.getCurrentQueue();

        // Disable the now playing list if the player doesn't have a queue or provide an active
        // queue ID that can be used to determine the active song in the queue.
        if (state == null
                || state.getActiveQueueItemId() == MediaSession.QueueItem.UNKNOWN_ID
                || queue.size() == 0) {
            d("getCurrentMediaId: No active queue item Id sending empty mediaId: PlaybackState="
                     + state);
            return "";
        }

        return Util.NOW_PLAYING_PREFIX + state.getActiveQueueItemId();
    }

    @NonNull
    Metadata getCurrentSongInfo() {
        final MediaPlayerWrapper player = getActivePlayer();
        if (player == null) return Util.empty_data();
@@ -249,11 +259,15 @@ public class MediaPlayerList {
        return player.getPlaybackState();
    }

    @NonNull
    List<Metadata> getNowPlayingList() {
        final MediaPlayerWrapper player = getActivePlayer();
        if (player == null) {
        // Only send the current song for the now playing if there is no active song. See
        // |getCurrentMediaId()| for reasons why there might be no active song.
        if (getCurrentMediaId().equals("")) {
            List<Metadata> ret = new ArrayList<Metadata>();
            ret.add(Util.empty_data());
            Metadata data = getCurrentSongInfo();
            data.mediaId = "";
            ret.add(data);
            return ret;
        }