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

Commit 6a80f25b authored by Treehugger Robot's avatar Treehugger Robot Committed by Gerrit Code Review
Browse files

Merge "Avrcp: redact media info"

parents 80211f93 da2b2bd7
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) {
+23 −1
Original line number Diff line number Diff line
@@ -507,6 +507,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 +535,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));
        }
    }
}
+21 −3
Original line number Diff line number Diff line
@@ -449,7 +449,14 @@ public final class Avrcp {
                responseDebug.append("getElementAttr response: ");
                for (int i = 0; i < numAttr; ++i) {
                    textArray[i] = mMediaAttributes.getString(attrIds[i]);
                    responseDebug.append("[" + attrIds[i] + "=" + textArray[i] + "] ");
                    responseDebug.append("[" + attrIds[i] + "=");
                    if (attrIds[i] == AvrcpConstants.ATTRID_TITLE
                            || attrIds[i] == AvrcpConstants.ATTRID_ARTIST
                            || attrIds[i] == AvrcpConstants.ATTRID_ALBUM) {
                        responseDebug.append(Utils.ellipsize(textArray[i]) + "] ");
                    } else {
                        responseDebug.append(textArray[i] + "] ");
                    }
                }
                Log.v(TAG, responseDebug.toString());
                byte[] bdaddr = elem.mAddress;
@@ -942,6 +949,17 @@ public final class Avrcp {
                    + playingTimeMs + " " + mediaNumber + "/" + mediaTotalNumber + ") " + genre
                    + "]";
        }

        public String toRedactedString() {
            if (!exists) {
                return "[MediaAttributes: none]";
            }

            return "[MediaAttributes: " + Utils.ellipsize(title) + " - "
                    + Utils.ellipsize(albumName) + " by " + Utils.ellipsize(artistName) + " ("
                    + playingTimeMs + " " + mediaNumber + "/" + mediaTotalNumber + ") " + genre
                    + "]";
        }
    }

    private void updateCurrentMediaState(boolean registering) {
@@ -971,7 +989,7 @@ public final class Avrcp {
        long newQueueId = MediaSession.QueueItem.UNKNOWN_ID;
        if (newState != null) newQueueId = newState.getActiveQueueItemId();
        Log.v(TAG, "Media update: id " + mLastQueueId + "➡" + newQueueId + "? "
                        + currentAttributes.toString());
                        + currentAttributes.toRedactedString());
        // Notify track changed if:
        //  - The CT is registering for the notification
        //  - Queue ID is UNKNOWN and MediaMetadata is different
@@ -2278,7 +2296,7 @@ public final class Avrcp {

    public void dump(StringBuilder sb) {
        sb.append("AVRCP:\n");
        ProfileService.println(sb, "mMediaAttributes: " + mMediaAttributes);
        ProfileService.println(sb, "mMediaAttributes: " + mMediaAttributes.toRedactedString());
        ProfileService.println(sb, "mTransportControlFlags: " + mTransportControlFlags);
        ProfileService.println(sb, "mCurrentPlayState: " + mCurrentPlayState);
        ProfileService.println(sb, "mPlayStatusChangedNT: " + mPlayStatusChangedNT);