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

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

release-request-c5216b17-dc50-4b24-831c-dc696ed657cc-for-git_oc-dr1-release-41...

release-request-c5216b17-dc50-4b24-831c-dc696ed657cc-for-git_oc-dr1-release-4133426 snap-temp-L83500000077479774

Change-Id: I62104d536ac3656445aa3c1b7c4ffd96e456ae15
parents fe7dbbb1 4170b0f1
Loading
Loading
Loading
Loading
+8 −0
Original line number Diff line number Diff line
@@ -175,6 +175,14 @@ final public class Utils {
        }
    }

    public static String ellipsize(String s) {
        // Only ellipsize release builds
        if (!Build.TYPE.equals("user")) return s;
        if (s == null) return null;
        if (s.length() < 3) return s;
        return s.charAt(0) + "⋯" + s.charAt(s.length() - 1);
    }

    public static void copyStream(InputStream is, OutputStream os, int bufferSize)
            throws IOException {
        if (is != null && os != null) {
+46 −12
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);
    }

    /*
@@ -507,6 +519,27 @@ public class AddressedMediaPlayer {
        return MediaSession.QueueItem.UNKNOWN_ID;
    }

    String displayMediaItem(MediaSession.QueueItem item) {
        StringBuilder sb = new StringBuilder();
        sb.append("#");
        sb.append(item.getQueueId());
        sb.append(": ");
        sb.append(Utils.ellipsize(getAttrValue(AvrcpConstants.ATTRID_TITLE, item, null)));
        sb.append(" - ");
        sb.append(Utils.ellipsize(getAttrValue(AvrcpConstants.ATTRID_ALBUM, item, null)));
        sb.append(" by ");
        sb.append(Utils.ellipsize(getAttrValue(AvrcpConstants.ATTRID_ARTIST, item, null)));
        sb.append(" (");
        sb.append(getAttrValue(AvrcpConstants.ATTRID_PLAY_TIME, item, null));
        sb.append(" ");
        sb.append(getAttrValue(AvrcpConstants.ATTRID_TRACK_NUM, item, null));
        sb.append("/");
        sb.append(getAttrValue(AvrcpConstants.ATTRID_NUM_TRACKS, item, null));
        sb.append(") ");
        sb.append(getAttrValue(AvrcpConstants.ATTRID_GENRE, item, null));
        return sb.toString();
    }

    public void dump(StringBuilder sb, @Nullable MediaController mediaController) {
        ProfileService.println(sb, "AddressedPlayer info:");
        ProfileService.println(sb, "mLastTrackIdSent: " + mLastTrackIdSent);
@@ -514,7 +547,8 @@ public class AddressedMediaPlayer {
        long currentQueueId = getActiveQueueItemId(mediaController);
        for (MediaSession.QueueItem item : mNowPlayingList) {
            long itemId = item.getQueueId();
            ProfileService.println(sb, (itemId == currentQueueId ? "*" : " ") + item.toString());
            ProfileService.println(
                    sb, (itemId == currentQueueId ? "*" : " ") + displayMediaItem(item));
        }
    }
}
+170 −163

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);

Loading