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

Commit 4598dac7 authored by Ajay Panicker's avatar Ajay Panicker
Browse files

Disable the Now Playing List for players with no active item

If there is some reason we cant determine the current active item in the
now playing list of the player, disable their now playing list. We do
this by only returning a one item now playing list consisting of the
current item.

Bug: 76128322
Test: View the now playing list on a carkit using a player that doesn't
      have an active item (Used VLC for this test)

Change-Id: I52e2f8daead3baf1028b47e1907871b5506de399
parent ef8c625a
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;
        }