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 17 package com.android.bluetooth.audio_util; 18 19 import android.content.Context; 20 import android.media.session.MediaSession; 21 import android.os.Looper; 22 import android.util.Log; 23 24 /** 25 * Google Play Music hides some of the metadata behind a specific key in the Extras of the 26 * MediaDescription in the MediaSession.QueueItem. This class exists to provide alternate 27 * methods to allow Google Play Music to match the default behaviour of MediaPlayerWrapper. 28 */ 29 class GPMWrapper extends MediaPlayerWrapper { 30 private static final String TAG = "AvrcpGPMWrapper"; 31 private static final boolean DEBUG = true; 32 GPMWrapper(Context context, MediaController controller, Looper looper)33 GPMWrapper(Context context, MediaController controller, Looper looper) { 34 super(context, controller, looper); 35 } 36 37 @Override isMetadataSynced()38 boolean isMetadataSynced() { 39 if (getQueue() == null) { 40 return false; 41 } 42 43 // Check if currentPlayingQueueId is in the queue 44 MediaSession.QueueItem currItem = null; 45 for (MediaSession.QueueItem item : getQueue()) { 46 // The item exists in the current queue 47 if (item.getQueueId() == getActiveQueueID()) { 48 currItem = item; 49 break; 50 } 51 } 52 53 // Check if current playing song in Queue matches current Metadata 54 Metadata qitem = Util.toMetadata(mContext, currItem); 55 Metadata mdata = Util.toMetadata(mContext, getMetadata()); 56 if (currItem == null || !qitem.equals(mdata)) { 57 if (DEBUG) { 58 Log.d(TAG, "Metadata currently out of sync for Google Play Music"); 59 Log.d(TAG, " └ Current queueItem: " + qitem); 60 Log.d(TAG, " └ Current metadata : " + mdata); 61 } 62 return false; 63 } 64 65 return true; 66 } 67 } 68