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

Commit a9edfd45 authored by Ajay Panicker's avatar Ajay Panicker
Browse files

Use custom metadata object for all logging

The metadata object in AVRCP handles null checks and fields properly
helping prevent crashes caused by poorly behaving media apps. Also add
the duration and track number and total number of tracks fields to the
metadata string.

Bug: 78562371
Test: Compile and "adb shell dumpsys bluetooth_manager"
Change-Id: Iaa9739f429795cbbb64b24eddfbf90beb8f090ba
Merged-In: Iaa9739f429795cbbb64b24eddfbf90beb8f090ba
parent eb8026da
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -46,8 +46,8 @@ class GPMWrapper extends MediaPlayerWrapper {
        if (currItem == null || !qitem.equals(mdata)) {
            if (DEBUG) {
                Log.d(TAG, "Metadata currently out of sync for Google Play Music");
                Log.d(TAG, "  └ Current queueItem: " + currItem);
                Log.d(TAG, "  └ Current metadata : " + getMetadata().getDescription());
                Log.d(TAG, "  └ Current queueItem: " + qitem);
                Log.d(TAG, "  └ Current metadata : " + mdata);
            }
            return false;
        }
+8 −7
Original line number Diff line number Diff line
@@ -198,8 +198,8 @@ class MediaPlayerWrapper {
            if (currItem == null || !qitem.equals(mdata)) {
                if (DEBUG) {
                    Log.d(TAG, "Metadata currently out of sync for " + mPackageName);
                    Log.d(TAG, "  └ Current queueItem: " + currItem);
                    Log.d(TAG, "  └ Current metadata : " + getMetadata().getDescription());
                    Log.d(TAG, "  └ Current queueItem: " + qitem);
                    Log.d(TAG, "  └ Current metadata : " + mdata);
                }
                return false;
            }
@@ -284,10 +284,11 @@ class MediaPlayerWrapper {
            }

            Log.e(TAG, "Timeout while waiting for metadata to sync for " + mPackageName);
            Log.e(TAG, "  └ Current Metadata: " + getMetadata().getDescription());
            Log.e(TAG, "  └ Current Metadata: " +  Util.toMetadata(getMetadata()));
            Log.e(TAG, "  └ Current Playstate: " + getPlaybackState());
            for (int i = 0; getQueue() != null && i < getQueue().size(); i++) {
                Log.e(TAG, "  └ QueueItem(" + i + "): " + getQueue().get(i));
            List<Metadata> current_queue = Util.toMetadataList(getQueue());
            for (int i = 0; i < current_queue.size(); i++) {
                Log.e(TAG, "  └ QueueItem(" + i + "): " + current_queue.get(i));
            }

            // TODO(apanicke): Add metric collection here.
@@ -364,7 +365,7 @@ class MediaPlayerWrapper {
                return;
            }

            Log.v(TAG, "onMetadataChanged(): " + mPackageName + " : " + metadata.getDescription());
            Log.v(TAG, "onMetadataChanged(): " + mPackageName + " : " + Util.toMetadata(metadata));

            if (!metadata.equals(getMetadata())) {
                e("The callback metadata doesn't match controller metadata");
@@ -437,7 +438,7 @@ class MediaPlayerWrapper {

            if (DEBUG) {
                for (int i = 0; i < current_queue.size(); i++) {
                    Log.d(TAG, "  └ QueueItem(" + i + "): " + queue.get(i));
                    Log.d(TAG, "  └ QueueItem(" + i + "): " + current_queue.get(i));
                }
            }

+3 −1
Original line number Diff line number Diff line
@@ -57,6 +57,8 @@ class Metadata implements Cloneable {
    @Override
    public String toString() {
        return "{ mediaId=\"" + mediaId + "\" title=\"" + title + "\" artist=\"" + artist
                + "\" album=\"" + album + "\" }";
                + "\" album=\"" + album + "\" duration=" + duration
                + " trackPosition=" + trackNum + "/" + numTracks + " }";

    }
}