GPMWrapper.java revision 99a82a9d6d6b7d86a2bd0aabeef7b193cfe623db
1/*
2 * Copyright 2018 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.bluetooth.avrcp;
18
19import android.media.session.MediaSession;
20import android.util.Log;
21
22/**
23 * Google Play Music hides some of the metadata behind a specific key in the Extras of the
24 * MediaDescription in the MediaSession.QueueItem. This class exists to provide alternate
25 * methods to allow Google Play Music to match the default behaviour of MediaPlayerWrapper.
26 */
27class GPMWrapper extends MediaPlayerWrapper {
28    private static final String TAG = "NewAvrcpGPMWrapper";
29    private static final boolean DEBUG = true;
30
31    @Override
32    boolean isMetadataSynced() {
33        // Check if currentPlayingQueueId is in the queue
34        MediaSession.QueueItem currItem = null;
35        for (MediaSession.QueueItem item : getQueue()) {
36            // The item exists in the current queue
37            if (item.getQueueId() == getActiveQueueID()) {
38                currItem = item;
39                break;
40            }
41        }
42
43        // Check if current playing song in Queue matches current Metadata
44        Metadata qitem = Util.toMetadata(currItem);
45        Metadata mdata = Util.toMetadata(getMetadata());
46        if (currItem == null || !qitem.equals(mdata)) {
47            if (DEBUG) {
48                Log.d(TAG, "Metadata currently out of sync for Google Play Music");
49                Log.d(TAG, "  └ Current queueItem: " + currItem);
50                Log.d(TAG, "  └ Current metadata : " + getMetadata().getDescription());
51            }
52            return false;
53        }
54
55        return true;
56    }
57}
58