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

Commit 05ed1bda authored by Ajay Panicker's avatar Ajay Panicker
Browse files

Add utility objects to unify all media metadata types.

Right now there are four types of metadata in the media framework.
MediaMetadata, MediaDescripion, MediaSession.QueueItem, and
MediaBrowser.MediaItem. This patch provides utility functions to merge
all of these into the Metadata class to be used throughout AVRCP.

Bug: 68854188
Test: runtest bluetooth -c com.android.bluetooth.avrcp.MediaPlayerWrapperTest
Change-Id: I0213473b7a6e54e8a1ca7a3d651bf12ad6139f8e
(cherry picked from commit dbed4ea9ddc73fb248feb2e2f513752696ce4536)
Merged-In: I24b3816db2410dd7428f443036cbf869da1fb89e
parent e4a32b72
Loading
Loading
Loading
Loading
+0 −14
Original line number Original line Diff line number Diff line
@@ -16,7 +16,6 @@


package com.android.bluetooth.avrcp;
package com.android.bluetooth.avrcp;


import android.media.MediaMetadata;
import android.media.session.MediaSession;
import android.media.session.MediaSession;
import android.util.Log;
import android.util.Log;


@@ -29,8 +28,6 @@ class GPMWrapper extends MediaPlayerWrapper {
    private static final String TAG = "NewAvrcpGPMWrapper";
    private static final String TAG = "NewAvrcpGPMWrapper";
    private static final boolean DEBUG = true;
    private static final boolean DEBUG = true;


    private static final String GPM_KEY = "com.google.android.music.mediasession.music_metadata";

    @Override
    @Override
    boolean isMetadataSynced() {
    boolean isMetadataSynced() {
        // Check if currentPlayingQueueId is in the queue
        // Check if currentPlayingQueueId is in the queue
@@ -57,15 +54,4 @@ class GPMWrapper extends MediaPlayerWrapper {


        return true;
        return true;
    }
    }

    @Override
    MediaMetadata queueItemToMetadata(MediaSession.QueueItem item) {
        MediaMetadata gpmdata = (MediaMetadata) item.getDescription().getExtras().get(GPM_KEY);

        MediaMetadata.Builder newMetadata = new MediaMetadata.Builder(gpmdata);
        newMetadata.putString(MediaMetadata.METADATA_KEY_TITLE,
                item.getDescription().getTitle().toString());

        return newMetadata.build();
    }
}
}
+12 −8
Original line number Original line Diff line number Diff line
@@ -96,8 +96,8 @@ class MediaPlayerWrapper {
        newWrapper.mPackageName = controller.getPackageName();
        newWrapper.mPackageName = controller.getPackageName();
        newWrapper.mLooper = looper;
        newWrapper.mLooper = looper;


        newWrapper.mCurrentData.queue = newWrapper.getQueue();
        newWrapper.mCurrentData.queue = Util.toMetadataList(newWrapper.getQueue());
        newWrapper.mCurrentData.metadata = newWrapper.getMetadata();
        newWrapper.mCurrentData.metadata = Util.toMetadata(newWrapper.getMetadata());
        newWrapper.mCurrentData.state = newWrapper.getPlaybackState();
        newWrapper.mCurrentData.state = newWrapper.getPlaybackState();
        return newWrapper;
        return newWrapper;
    }
    }
@@ -113,22 +113,23 @@ class MediaPlayerWrapper {
        return mPackageName;
        return mPackageName;
    }
    }


    List<MediaSession.QueueItem> getQueue() {
    protected List<MediaSession.QueueItem> getQueue() {
        return mMediaController.getQueue();
        return mMediaController.getQueue();
    }
    }


    MediaMetadata getMetadata() {
    protected MediaMetadata getMetadata() {
        return mMediaController.getMetadata();
        return mMediaController.getMetadata();
    }
    }


    protected PlaybackState getPlaybackState() {
        return mMediaController.getPlaybackState();
    }

    long getActiveQueueID() {
    long getActiveQueueID() {
        if (mMediaController.getPlaybackState() == null) return -1;
        if (mMediaController.getPlaybackState() == null) return -1;
        return mMediaController.getPlaybackState().getActiveQueueItemId();
        return mMediaController.getPlaybackState().getActiveQueueItemId();
    }
    }


    PlaybackState getPlaybackState() {
        return mMediaController.getPlaybackState();
    }


    MediaData getCurrentMediaData() {
    MediaData getCurrentMediaData() {
        return mCurrentData;
        return mCurrentData;
@@ -303,7 +304,10 @@ class MediaPlayerWrapper {
                }
                }
            }
            }


            MediaData newData = new MediaData(getMetadata(), getPlaybackState(), getQueue());
            MediaData newData = new MediaData(
                    Util.toMetadata(getMetadata()),
                    getPlaybackState(),
                    Util.toMetadataList(getQueue()));


            if (newData.equals(mCurrentData)) {
            if (newData.equals(mCurrentData)) {
                // This may happen if the controller is fully synced by the time the
                // This may happen if the controller is fully synced by the time the
+34 −0
Original line number Original line Diff line number Diff line
/*
 * Copyright (C) 2018 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.bluetooth.avrcp;

class Folder implements Cloneable {
    public String mediaId;
    public boolean isPlayable;
    public String title;

    Folder(String i, boolean p, String t) {
        mediaId = i;
        isPlayable = p;
        title = t;
    }

    @Override
    public Folder clone() {
        return new Folder(mediaId, isPlayable, title);
    }
}
+42 −0
Original line number Original line Diff line number Diff line
/*
 * Copyright (C) 2018 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.bluetooth.avrcp;

class ListItem implements Cloneable {
    public boolean isFolder = false;
    public Folder folder;
    public Metadata song;

    ListItem(Folder f) {
        isFolder = true;
        folder = f;
    }

    ListItem(Metadata s) {
        isFolder = false;
        song = s;
    }

    @Override
    public ListItem clone() {
        if (isFolder) {
            return new ListItem(folder.clone());
        } else {
            return new ListItem(song.clone());
        }
    }
}
+3 −5
Original line number Original line Diff line number Diff line
@@ -16,8 +16,6 @@


package com.android.bluetooth.avrcp;
package com.android.bluetooth.avrcp;


import android.media.MediaMetadata;
import android.media.session.MediaSession;
import android.media.session.PlaybackState;
import android.media.session.PlaybackState;


import java.util.List;
import java.util.List;
@@ -27,11 +25,11 @@ import java.util.Objects;
 * Helper class to transport metadata around AVRCP
 * Helper class to transport metadata around AVRCP
 */
 */
class MediaData {
class MediaData {
    public List<MediaSession.QueueItem> queue;
    public List<Metadata> queue;
    public PlaybackState state;
    public PlaybackState state;
    public MediaMetadata metadata;
    public Metadata metadata;


    MediaData(MediaMetadata m, PlaybackState s, List<MediaSession.QueueItem> q) {
    MediaData(Metadata m, PlaybackState s, List<Metadata> q) {
        metadata = m;
        metadata = m;
        state = s;
        state = s;
        queue = q;
        queue = q;
Loading