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

Commit c379b32f authored by android-build-team Robot's avatar android-build-team Robot
Browse files

Merge cherrypicks of [2455372, 2455337, 2455612, 2455497] into oc-release

Change-Id: I05e7158e88bbdba30984eac8f4ab0eaf8cb0a55c
parents a861c973 3e25adee
Loading
Loading
Loading
Loading
+23 −11
Original line number Diff line number Diff line
@@ -54,12 +54,14 @@ public class AddressedMediaPlayer {
    private final List<MediaSession.QueueItem> mEmptyNowPlayingList;

    private long mLastTrackIdSent;
    private boolean mNowPlayingListUpdated;

    public AddressedMediaPlayer(AvrcpMediaRspInterface mediaInterface) {
        mEmptyNowPlayingList = new ArrayList<MediaSession.QueueItem>();
        mNowPlayingList = mEmptyNowPlayingList;
        mMediaInterface = mediaInterface;
        mLastTrackIdSent = MediaSession.QueueItem.UNKNOWN_ID;
        mNowPlayingListUpdated = false;
    }

    void cleanup() {
@@ -67,12 +69,12 @@ public class AddressedMediaPlayer {
        mNowPlayingList = mEmptyNowPlayingList;
        mMediaInterface = null;
        mLastTrackIdSent = MediaSession.QueueItem.UNKNOWN_ID;
        mNowPlayingListUpdated = false;
    }

    /* get now playing list from addressed player */
    void getFolderItemsNowPlaying(byte[] bdaddr, AvrcpCmd.FolderItemsCmd reqObj,
            @Nullable MediaController mediaController) {
        if (DEBUG) Log.v(TAG, "getFolderItemsNowPlaying");
        if (mediaController == null) {
            // No players (if a player exists, we would have selected it)
            Log.e(TAG, "mediaController = null, sending no available players response");
@@ -120,7 +122,10 @@ public class AddressedMediaPlayer {
            @Nullable MediaController mediaController) {
        if (mediaController == null) return mEmptyNowPlayingList;
        List<MediaSession.QueueItem> items = mediaController.getQueue();
        if (items == mNowPlayingList) return mNowPlayingList;
        if (items != null && !mNowPlayingListUpdated) {
            mNowPlayingList = items;
            return mNowPlayingList;
        }
        if (items == null) {
            Log.i(TAG, "null queue from " + mediaController.getPackageName()
                            + ", constructing single-item list");
@@ -131,12 +136,19 @@ public class AddressedMediaPlayer {
            items = new ArrayList<MediaSession.QueueItem>();
            items.add(current);
        }

        mNowPlayingList = items;
        // TODO (jamuraa): test to see if the single-item queue is the same and don't send
        if (mMediaInterface != null) {
            mMediaInterface.nowPlayingChangedRsp(AvrcpConstants.NOTIFICATION_TYPE_CHANGED);

        if (mNowPlayingListUpdated) sendNowPlayingListChanged();

        return mNowPlayingList;
    }
        return items;

    private void sendNowPlayingListChanged() {
        if (mMediaInterface == null) return;
        mMediaInterface.uidsChangedRsp(AvrcpConstants.NOTIFICATION_TYPE_CHANGED);
        mMediaInterface.nowPlayingChangedRsp(AvrcpConstants.NOTIFICATION_TYPE_CHANGED);
        mNowPlayingListUpdated = false;
    }

    /* Constructs a queue item representing the current playing metadata from an
@@ -196,6 +208,7 @@ public class AddressedMediaPlayer {
    }

    void updateNowPlayingList(@Nullable MediaController mediaController) {
        mNowPlayingListUpdated = true;
        getNowPlayingList(mediaController);
    }

@@ -239,14 +252,13 @@ public class AddressedMediaPlayer {
    }

    void sendTrackChangeWithId(int type, @Nullable MediaController mediaController) {
        if (DEBUG)
        Log.d(TAG, "sendTrackChangeWithId (" + type + "): controller " + mediaController);
        long qid = getActiveQueueItemId(mediaController);
        byte[] track = ByteBuffer.allocate(AvrcpConstants.UID_SIZE).putLong(qid).array();
        // The nowPlayingList changed: the new list has the full data for the current item
        if (type == AvrcpConstants.NOTIFICATION_TYPE_CHANGED) sendNowPlayingListChanged();
        mMediaInterface.trackChangedRsp(type, track);
        mLastTrackIdSent = qid;
        // The nowPlaying might have changed.
        updateNowPlayingList(mediaController);
    }

    /*
+149 −160

File changed.

Preview size limit exceeded, changes collapsed.

+21 −7
Original line number Diff line number Diff line
@@ -16,6 +16,8 @@

package com.android.bluetooth.avrcp;

import android.annotation.NonNull;
import android.annotation.Nullable;
import android.media.session.MediaSession;

import com.android.bluetooth.Utils;
@@ -200,17 +202,19 @@ class MediaPlayerInfo {
    private int subType;
    private byte playStatus;
    private short[] featureBitMask;
    private String packageName;
    private String displayableName;
    private MediaController mediaController;
    private @NonNull String packageName;
    private @NonNull String displayableName;
    private @Nullable MediaController mediaController;

    MediaPlayerInfo(MediaController controller, byte majorType, int subType, byte playStatus,
            short[] featureBitMask, String packageName, String displayableName) {
    MediaPlayerInfo(@Nullable MediaController controller, byte majorType, int subType,
            byte playStatus, short[] featureBitMask, @NonNull String packageName,
            @Nullable String displayableName) {
        this.setMajorType(majorType);
        this.setSubType(subType);
        this.playStatus = playStatus;
        // store a copy the FeatureBitMask array
        this.featureBitMask = Arrays.copyOf(featureBitMask, featureBitMask.length);
        Arrays.sort(this.featureBitMask);
        this.setPackageName(packageName);
        this.setDisplayableName(displayableName);
        this.setMediaController(controller);
@@ -236,7 +240,7 @@ class MediaPlayerInfo {
        this.mediaController = mediaController;
    }

    void setPackageName(String name) {
    void setPackageName(@NonNull String name) {
        // Controller determines package name when it is set.
        if (mediaController != null) return;
        this.packageName = name;
@@ -271,7 +275,8 @@ class MediaPlayerInfo {
        return displayableName;
    }

    void setDisplayableName(String displayableName) {
    void setDisplayableName(@Nullable String displayableName) {
        if (displayableName == null) displayableName = "";
        this.displayableName = displayableName;
    }

@@ -282,6 +287,7 @@ class MediaPlayerInfo {
    void setFeatureBitMask(short[] featureBitMask) {
        synchronized (this) {
            this.featureBitMask = Arrays.copyOf(featureBitMask, featureBitMask.length);
            Arrays.sort(this.featureBitMask);
        }
    }

@@ -295,6 +301,14 @@ class MediaPlayerInfo {
        return false;
    }

    /** Tests if the view of this player presented to the controller is different enough to
     *  justify sending an Available Players Changed update */
    public boolean equalView(MediaPlayerInfo other) {
        return (this.majorType == other.getMajorType()) && (this.subType == other.getSubType())
                && Arrays.equals(this.featureBitMask, other.getFeatureBitMask())
                && this.displayableName.equals(other.getDisplayableName());
    }

    @Override
    public String toString() {
        StringBuilder sb = new StringBuilder();
+1 −1
Original line number Diff line number Diff line
@@ -45,7 +45,7 @@ public interface AvrcpMediaRspInterface {

    public void avalPlayerChangedRsp(byte[] address, int type);

    public void uidsChangedRsp(byte[] address, int type, int uidCounter);
    public void uidsChangedRsp(int type);

    public void nowPlayingChangedRsp(int type);