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

Commit c712df08 authored by Sal Savage's avatar Sal Savage
Browse files

House all AVRCP metadata in custom objects instead of MediaMetadata

Lots of metadata comes over AVRCP and we're only saving a subset of it
into Media Framework objects (mostly because the framework objects don't
have anything in them that relates well to the AVRCP metadata). This
change migrates us to an AvrcpItem that can hold any extra metadata we
need and knows how to convert itself into the correct framework objects
such that we can still share the data with our MediaBrowserService.

Bug: b/132812696
Test: Build, Flash, interopt tests with devices, atest
Change-Id: I86f78de60bbe95229f63c5d282494453f920c6a6
parent 28ee736f
Loading
Loading
Loading
Loading
+21 −19
Original line number Diff line number Diff line
@@ -50,7 +50,7 @@ static jmethodID method_handleAddressedPlayerChanged;
static jmethodID method_handleNowPlayingContentChanged;
static jmethodID method_onAvailablePlayerChanged;

static jclass class_MediaBrowser_MediaItem;
static jclass class_AvrcpItem;
static jclass class_AvrcpPlayer;

static const btrc_ctrl_interface_t* sBluetoothAvrcpInterface = NULL;
@@ -458,7 +458,7 @@ static void btavrcp_get_folder_items_callback(
        sCallbackEnv->NewObjectArray((jint)count, class_AvrcpPlayer, 0));
  } else {
    itemArray.reset(sCallbackEnv->NewObjectArray(
        (jint)count, class_MediaBrowser_MediaItem, 0));
        (jint)count, class_AvrcpItem, 0));
  }
  if (!itemArray.get()) {
    ALOGE("%s itemArray allocation failed.", __func__);
@@ -511,11 +511,11 @@ static void btavrcp_get_folder_items_callback(
        ScopedLocalRef<jobject> mediaObj(
            sCallbackEnv.get(),
            (jobject)sCallbackEnv->CallObjectMethod(
                sCallbacksObj, method_createFromNativeMediaItem, uid,
                (jint)item->media.type, mediaName.get(), attrIdArray.get(),
                attrValArray.get()));
                sCallbacksObj, method_createFromNativeMediaItem, addr.get(),
                uid, (jint)item->media.type, mediaName.get(),
                attrIdArray.get(), attrValArray.get()));
        if (!mediaObj.get()) {
          ALOGE("%s failed to creae MediaItem for type ITEM_MEDIA", __func__);
          ALOGE("%s failed to create AvrcpItem for type ITEM_MEDIA", __func__);
          return;
        }
        sCallbackEnv->SetObjectArrayElement(itemArray.get(), i, mediaObj.get());
@@ -536,11 +536,11 @@ static void btavrcp_get_folder_items_callback(
        ScopedLocalRef<jobject> folderObj(
            sCallbackEnv.get(),
            (jobject)sCallbackEnv->CallObjectMethod(
                sCallbacksObj, method_createFromNativeFolderItem, uid,
                (jint)item->folder.type, folderName.get(),
                sCallbacksObj, method_createFromNativeFolderItem, addr.get(),
                uid, (jint)item->folder.type, folderName.get(),
                (jint)item->folder.playable));
        if (!folderObj.get()) {
          ALOGE("%s failed to create MediaItem for type ITEM_FOLDER", __func__);
          ALOGE("%s failed to create AvrcpItem for type ITEM_FOLDER", __func__);
          return;
        }
        sCallbackEnv->SetObjectArrayElement(itemArray.get(), i,
@@ -576,8 +576,8 @@ static void btavrcp_get_folder_items_callback(
        ScopedLocalRef<jobject> playerObj(
            sCallbackEnv.get(),
            (jobject)sCallbackEnv->CallObjectMethod(
                sCallbacksObj, method_createFromNativePlayerItem, id,
                playerName.get(), featureBitArray.get(), playStatus,
                sCallbacksObj, method_createFromNativePlayerItem, addr.get(),
                id, playerName.get(), featureBitArray.get(), playStatus,
                playerType));
        if (!playerObj.get()) {
          ALOGE("%s failed to create AvrcpPlayer from ITEM_PLAYER", __func__);
@@ -805,21 +805,23 @@ static void classInitNative(JNIEnv* env, jclass clazz) {

  method_handleGetFolderItemsRsp =
      env->GetMethodID(clazz, "handleGetFolderItemsRsp",
                       "([BI[Landroid/support/v4/media/MediaBrowserCompat$MediaItem;)V");
                       "([BI[Lcom/android/bluetooth/avrcpcontroller/"
                       "AvrcpItem;)V");
  method_handleGetPlayerItemsRsp = env->GetMethodID(
      clazz, "handleGetPlayerItemsRsp",
      "([B[Lcom/android/bluetooth/avrcpcontroller/AvrcpPlayer;)V");

  method_createFromNativeMediaItem =
      env->GetMethodID(clazz, "createFromNativeMediaItem",
                       "(JILjava/lang/String;[I[Ljava/lang/String;)Landroid/"
                       "support/v4/media/MediaBrowserCompat$MediaItem;");
                       "([BJILjava/lang/String;[I[Ljava/lang/String;)Lcom/"
                       "android/bluetooth/avrcpcontroller/AvrcpItem;");
  method_createFromNativeFolderItem = env->GetMethodID(
      clazz, "createFromNativeFolderItem",
      "(JILjava/lang/String;I)Landroid/support/v4/media/MediaBrowserCompat$MediaItem;");
      "([BJILjava/lang/String;I)Lcom/android/bluetooth/avrcpcontroller/"
      "AvrcpItem;");
  method_createFromNativePlayerItem =
      env->GetMethodID(clazz, "createFromNativePlayerItem",
                       "(ILjava/lang/String;[BII)Lcom/android/bluetooth/"
                       "([BILjava/lang/String;[BII)Lcom/android/bluetooth/"
                       "avrcpcontroller/AvrcpPlayer;");
  method_handleChangeFolderRsp =
      env->GetMethodID(clazz, "handleChangeFolderRsp", "([BI)V");
@@ -840,9 +842,9 @@ static void classInitNative(JNIEnv* env, jclass clazz) {
static void initNative(JNIEnv* env, jobject object) {
  std::unique_lock<std::shared_timed_mutex> lock(sCallbacks_mutex);

  jclass tmpMediaItem =
      env->FindClass("android/support/v4/media/MediaBrowserCompat$MediaItem");
  class_MediaBrowser_MediaItem = (jclass)env->NewGlobalRef(tmpMediaItem);
  jclass tmpAvrcpItem =
      env->FindClass("com/android/bluetooth/avrcpcontroller/AvrcpItem");
  class_AvrcpItem = (jclass)env->NewGlobalRef(tmpAvrcpItem);

  jclass tmpBtPlayer =
      env->FindClass("com/android/bluetooth/avrcpcontroller/AvrcpPlayer");
+66 −74
Original line number Diff line number Diff line
@@ -22,9 +22,7 @@ import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothProfile;
import android.bluetooth.IBluetoothAvrcpController;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.media.MediaBrowserCompat.MediaItem;
import android.support.v4.media.MediaDescriptionCompat;
import android.support.v4.media.session.PlaybackStateCompat;
import android.util.Log;

@@ -48,7 +46,6 @@ public class AvrcpControllerService extends ProfileService {
    static final boolean DBG = Log.isLoggable(TAG, Log.DEBUG);
    static final boolean VDBG = Log.isLoggable(TAG, Log.VERBOSE);

    public static final String MEDIA_ITEM_UID_KEY = "media-item-uid-key";
    /*
     *  Play State Values from JNI
     */
@@ -140,10 +137,11 @@ public class AvrcpControllerService extends ProfileService {
    }

    private void refreshContents(BrowseTree.BrowseNode node) {
        if (node.mDevice == null) {
        BluetoothDevice device = node.getDevice();
        if (device == null) {
            return;
        }
        AvrcpControllerStateMachine stateMachine = getStateMachine(node.mDevice);
        AvrcpControllerStateMachine stateMachine = getStateMachine(device);
        if (stateMachine != null) {
            stateMachine.requestContents(node);
        }
@@ -301,7 +299,7 @@ public class AvrcpControllerService extends ProfileService {
    // Called by JNI when a device has connected or disconnected.
    private synchronized void onConnectionStateChanged(boolean remoteControlConnected,
            boolean browsingConnected, byte[] address) {
        BluetoothDevice device = BluetoothAdapter.getDefaultAdapter().getRemoteDevice(address);
        BluetoothDevice device = mAdapter.getRemoteDevice(address);
        if (DBG) {
            Log.d(TAG, "onConnectionStateChanged " + remoteControlConnected + " "
                    + browsingConnected + device);
@@ -336,7 +334,7 @@ public class AvrcpControllerService extends ProfileService {
        if (DBG) {
            Log.d(TAG, "handleRegisterNotificationAbsVol");
        }
        BluetoothDevice device = BluetoothAdapter.getDefaultAdapter().getRemoteDevice(address);
        BluetoothDevice device = mAdapter.getRemoteDevice(address);
        AvrcpControllerStateMachine stateMachine = getStateMachine(device);
        if (stateMachine != null) {
            stateMachine.sendMessage(
@@ -349,7 +347,7 @@ public class AvrcpControllerService extends ProfileService {
        if (DBG) {
            Log.d(TAG, "handleSetAbsVolume ");
        }
        BluetoothDevice device = BluetoothAdapter.getDefaultAdapter().getRemoteDevice(address);
        BluetoothDevice device = mAdapter.getRemoteDevice(address);
        AvrcpControllerStateMachine stateMachine = getStateMachine(device);
        if (stateMachine != null) {
            stateMachine.sendMessage(AvrcpControllerStateMachine.MESSAGE_PROCESS_SET_ABS_VOL_CMD,
@@ -364,11 +362,18 @@ public class AvrcpControllerService extends ProfileService {
            Log.d(TAG, "onTrackChanged");
        }

        BluetoothDevice device = BluetoothAdapter.getDefaultAdapter().getRemoteDevice(address);
        BluetoothDevice device = mAdapter.getRemoteDevice(address);
        AvrcpControllerStateMachine stateMachine = getStateMachine(device);
        if (stateMachine != null) {
            AvrcpItem.Builder aib = new AvrcpItem.Builder();
            aib.fromAvrcpAttributeArray(attributes, attribVals);
            aib.setDevice(device);
            aib.setItemType(AvrcpItem.TYPE_MEDIA);
            aib.setUuid(UUID.randomUUID().toString());
            AvrcpItem item = aib.build();

            stateMachine.sendMessage(AvrcpControllerStateMachine.MESSAGE_PROCESS_TRACK_CHANGED,
                    TrackInfo.getMetadata(attributes, attribVals));
                    item);
        }
    }

@@ -378,7 +383,7 @@ public class AvrcpControllerService extends ProfileService {
        if (DBG) {
            Log.d(TAG, "onPlayPositionChanged pos " + currSongPosition);
        }
        BluetoothDevice device = BluetoothAdapter.getDefaultAdapter().getRemoteDevice(address);
        BluetoothDevice device = mAdapter.getRemoteDevice(address);
        AvrcpControllerStateMachine stateMachine = getStateMachine(device);
        if (stateMachine != null) {
            stateMachine.sendMessage(
@@ -412,7 +417,7 @@ public class AvrcpControllerService extends ProfileService {
            default:
                playbackState = PlaybackStateCompat.STATE_NONE;
        }
        BluetoothDevice device = BluetoothAdapter.getDefaultAdapter().getRemoteDevice(address);
        BluetoothDevice device = mAdapter.getRemoteDevice(address);
        AvrcpControllerStateMachine stateMachine = getStateMachine(device);
        if (stateMachine != null) {
            stateMachine.sendMessage(
@@ -426,7 +431,7 @@ public class AvrcpControllerService extends ProfileService {
        if (DBG) {
            Log.d(TAG, "handlePlayerAppSetting rspLen = " + rspLen);
        }
        BluetoothDevice device = BluetoothAdapter.getDefaultAdapter().getRemoteDevice(address);
        BluetoothDevice device = mAdapter.getRemoteDevice(address);
        AvrcpControllerStateMachine stateMachine = getStateMachine(device);
        if (stateMachine != null) {
            PlayerApplicationSettings supportedSettings =
@@ -442,7 +447,7 @@ public class AvrcpControllerService extends ProfileService {
        if (DBG) {
            Log.d(TAG, "onPlayerAppSettingChanged ");
        }
        BluetoothDevice device = BluetoothAdapter.getDefaultAdapter().getRemoteDevice(address);
        BluetoothDevice device = mAdapter.getRemoteDevice(address);
        AvrcpControllerStateMachine stateMachine = getStateMachine(device);
        if (stateMachine != null) {

@@ -467,27 +472,21 @@ public class AvrcpControllerService extends ProfileService {
    }

    // Browsing related JNI callbacks.
    void handleGetFolderItemsRsp(byte[] address, int status, MediaItem[] items) {
    void handleGetFolderItemsRsp(byte[] address, int status, AvrcpItem[] items) {
        if (DBG) {
            Log.d(TAG, "handleGetFolderItemsRsp called with status " + status + " items "
                    + items.length + " items.");
        }
        for (MediaItem item : items) {
            if (VDBG) {
                Log.d(TAG, "media item: " + item + " uid: "
                        + item.getDescription().getMediaId());
            }
        }
        ArrayList<MediaItem> itemsList = new ArrayList<>();
        for (MediaItem item : items) {

        List<AvrcpItem> itemsList = new ArrayList<>();
        for (AvrcpItem item : items) {
            if (VDBG) Log.d(TAG, item.toString());
            itemsList.add(item);
        }

        BluetoothDevice device = BluetoothAdapter.getDefaultAdapter().getRemoteDevice(address);

        BluetoothDevice device = mAdapter.getRemoteDevice(address);
        AvrcpControllerStateMachine stateMachine = getStateMachine(device);
        if (stateMachine != null) {

            stateMachine.sendMessage(AvrcpControllerStateMachine.MESSAGE_PROCESS_GET_FOLDER_ITEMS,
                    itemsList);
        }
@@ -499,17 +498,13 @@ public class AvrcpControllerService extends ProfileService {
            Log.d(TAG, "handleGetFolderItemsRsp called with " + items.length + " items.");
        }

        for (AvrcpPlayer item : items) {
            if (VDBG) {
                Log.d(TAG, "bt player item: " + item);
            }
        }
        List<AvrcpPlayer> itemsList = new ArrayList<>();
        for (AvrcpPlayer p : items) {
            itemsList.add(p);
        for (AvrcpPlayer item : items) {
            if (VDBG) Log.d(TAG, "bt player item: " + item);
            itemsList.add(item);
        }

        BluetoothDevice device = BluetoothAdapter.getDefaultAdapter().getRemoteDevice(address);
        BluetoothDevice device = mAdapter.getRemoteDevice(address);
        AvrcpControllerStateMachine stateMachine = getStateMachine(device);
        if (stateMachine != null) {
            stateMachine.sendMessage(AvrcpControllerStateMachine.MESSAGE_PROCESS_GET_PLAYER_ITEMS,
@@ -518,60 +513,57 @@ public class AvrcpControllerService extends ProfileService {
    }

    // JNI Helper functions to convert native objects to java.
    MediaItem createFromNativeMediaItem(long uid, int type, String name, int[] attrIds,
            String[] attrVals) {
    AvrcpItem createFromNativeMediaItem(byte[] address, long uid, int type, String name,
            int[] attrIds, String[] attrVals) {
        if (VDBG) {
            Log.d(TAG, "createFromNativeMediaItem uid: " + uid + " type " + type + " name "
                    + name + " attrids " + attrIds + " attrVals " + attrVals);
            Log.d(TAG, "createFromNativeMediaItem uid: " + uid + " type: " + type + " name: " + name
                    + " attrids: " + attrIds + " attrVals: " + attrVals);
        }
        MediaDescriptionCompat.Builder mdb = new MediaDescriptionCompat.Builder();

        Bundle mdExtra = new Bundle();
        mdExtra.putLong(MEDIA_ITEM_UID_KEY, uid);
        mdb.setExtras(mdExtra);

        BluetoothDevice device = mAdapter.getRemoteDevice(address);
        AvrcpItem.Builder aib = new AvrcpItem.Builder().fromAvrcpAttributeArray(attrIds, attrVals);
        aib.setDevice(device);
        aib.setItemType(AvrcpItem.TYPE_MEDIA);
        aib.setType(type);
        aib.setUid(uid);
        aib.setUuid(UUID.randomUUID().toString());
        aib.setPlayable(true);
        AvrcpItem item = aib.build();

        // Generate a random UUID. We do this since database unaware TGs can send multiple
        // items with same MEDIA_ITEM_UID_KEY.
        mdb.setMediaId(UUID.randomUUID().toString());
        // Concise readable name.
        mdb.setTitle(name);

        // We skip the attributes since we can query them using UID for the item above
        // Also MediaDescription does not give an easy way to provide this unless we pass
        // it as an MediaMetadata which is put inside the extras.
        return new MediaItem(mdb.build(), MediaItem.FLAG_PLAYABLE);
        return item;
    }

    MediaItem createFromNativeFolderItem(long uid, int type, String name, int playable) {
    AvrcpItem createFromNativeFolderItem(byte[] address, long uid, int type, String name,
            int playable) {
        if (VDBG) {
            Log.d(TAG, "createFromNativeFolderItem uid: " + uid + " type " + type + " name "
                    + name + " playable " + playable);
        }
        MediaDescriptionCompat.Builder mdb = new MediaDescriptionCompat.Builder();

        Bundle mdExtra = new Bundle();
        mdExtra.putLong(MEDIA_ITEM_UID_KEY, uid);
        mdb.setExtras(mdExtra);

        // Generate a random UUID. We do this since database unaware TGs can send multiple
        // items with same MEDIA_ITEM_UID_KEY.
        mdb.setMediaId(UUID.randomUUID().toString());
        // Concise readable name.
        mdb.setTitle(name);

        return new MediaItem(mdb.build(), MediaItem.FLAG_BROWSABLE);
        BluetoothDevice device = mAdapter.getRemoteDevice(address);
        AvrcpItem.Builder aib = new AvrcpItem.Builder();
        aib.setDevice(device);
        aib.setItemType(AvrcpItem.TYPE_FOLDER);
        aib.setType(type);
        aib.setUid(uid);
        aib.setUuid(UUID.randomUUID().toString());
        aib.setDisplayableName(name);
        aib.setPlayable(playable == 0x01);
        aib.setBrowsable(true);
        return aib.build();
    }

    AvrcpPlayer createFromNativePlayerItem(int id, String name, byte[] transportFlags,
            int playStatus, int playerType) {
    AvrcpPlayer createFromNativePlayerItem(byte[] address, int id, String name,
            byte[] transportFlags, int playStatus, int playerType) {
        if (VDBG) {
            Log.d(TAG,
                    "createFromNativePlayerItem name: " + name + " transportFlags "
                            + transportFlags + " play status " + playStatus + " player type "
                            + playerType);
        }
        AvrcpPlayer player = new AvrcpPlayer(id, name, transportFlags, playStatus, playerType);
        BluetoothDevice device = mAdapter.getRemoteDevice(address);
        AvrcpPlayer player = new AvrcpPlayer(device, id, name, transportFlags, playStatus,
                playerType);
        return player;
    }

@@ -579,7 +571,7 @@ public class AvrcpControllerService extends ProfileService {
        if (DBG) {
            Log.d(TAG, "handleChangeFolderRsp count: " + count);
        }
        BluetoothDevice device = BluetoothAdapter.getDefaultAdapter().getRemoteDevice(address);
        BluetoothDevice device = mAdapter.getRemoteDevice(address);
        AvrcpControllerStateMachine stateMachine = getStateMachine(device);
        if (stateMachine != null) {
            stateMachine.sendMessage(AvrcpControllerStateMachine.MESSAGE_PROCESS_FOLDER_PATH,
@@ -591,7 +583,7 @@ public class AvrcpControllerService extends ProfileService {
        if (DBG) {
            Log.d(TAG, "handleSetBrowsedPlayerRsp depth: " + depth);
        }
        BluetoothDevice device = BluetoothAdapter.getDefaultAdapter().getRemoteDevice(address);
        BluetoothDevice device = mAdapter.getRemoteDevice(address);

        AvrcpControllerStateMachine stateMachine = getStateMachine(device);
        if (stateMachine != null) {
@@ -604,7 +596,7 @@ public class AvrcpControllerService extends ProfileService {
        if (DBG) {
            Log.d(TAG, "handleSetAddressedPlayerRsp status: " + status);
        }
        BluetoothDevice device = BluetoothAdapter.getDefaultAdapter().getRemoteDevice(address);
        BluetoothDevice device = mAdapter.getRemoteDevice(address);

        AvrcpControllerStateMachine stateMachine = getStateMachine(device);
        if (stateMachine != null) {
@@ -617,7 +609,7 @@ public class AvrcpControllerService extends ProfileService {
        if (DBG) {
            Log.d(TAG, "handleAddressedPlayerChanged id: " + id);
        }
        BluetoothDevice device = BluetoothAdapter.getDefaultAdapter().getRemoteDevice(address);
        BluetoothDevice device = mAdapter.getRemoteDevice(address);

        AvrcpControllerStateMachine stateMachine = getStateMachine(device);
        if (stateMachine != null) {
@@ -630,7 +622,7 @@ public class AvrcpControllerService extends ProfileService {
        if (DBG) {
            Log.d(TAG, "handleNowPlayingContentChanged");
        }
        BluetoothDevice device = BluetoothAdapter.getDefaultAdapter().getRemoteDevice(address);
        BluetoothDevice device = mAdapter.getRemoteDevice(address);

        AvrcpControllerStateMachine stateMachine = getStateMachine(device);
        if (stateMachine != null) {
+10 −7
Original line number Diff line number Diff line
@@ -24,8 +24,6 @@ import android.content.Intent;
import android.media.AudioManager;
import android.os.Bundle;
import android.os.Message;
import android.support.v4.media.MediaBrowserCompat.MediaItem;
import android.support.v4.media.MediaMetadataCompat;
import android.support.v4.media.session.MediaSessionCompat;
import android.support.v4.media.session.PlaybackStateCompat;
import android.util.Log;
@@ -397,9 +395,10 @@ class AvrcpControllerStateMachine extends StateMachine {
                    return true;

                case MESSAGE_PROCESS_TRACK_CHANGED:
                    mAddressedPlayer.updateCurrentTrack((MediaMetadataCompat) msg.obj);
                    AvrcpItem track = (AvrcpItem) msg.obj;
                    mAddressedPlayer.updateCurrentTrack(track);
                    if (isActive()) {
                        BluetoothMediaBrowserService.trackChanged((MediaMetadataCompat) msg.obj);
                        BluetoothMediaBrowserService.trackChanged(track);
                    }
                    return true;

@@ -577,14 +576,15 @@ class AvrcpControllerStateMachine extends StateMachine {
            logD(STATE_TAG + " processMessage " + msg.what);
            switch (msg.what) {
                case MESSAGE_PROCESS_GET_FOLDER_ITEMS:
                    ArrayList<MediaItem> folderList = (ArrayList<MediaItem>) msg.obj;
                    ArrayList<AvrcpItem> folderList = (ArrayList<AvrcpItem>) msg.obj;
                    int endIndicator = mBrowseNode.getExpectedChildren() - 1;
                    logD("GetFolderItems: End " + endIndicator
                            + " received " + folderList.size());

                    // Always update the node so that the user does not wait forever
                    // for the list to populate.
                    mBrowseNode.addChildren(folderList);
                    int newSize = mBrowseNode.addChildren(folderList);
                    logD("Added " + newSize + " items to the browse tree");
                    notifyChanged(mBrowseNode);

                    if (mBrowseNode.getChildrenCount() >= endIndicator || folderList.size() == 0
@@ -695,6 +695,9 @@ class AvrcpControllerStateMachine extends StateMachine {
            int start = target.getChildrenCount();
            int end = Math.min(target.getExpectedChildren(), target.getChildrenCount()
                    + ITEM_PAGE_SIZE) - 1;
            logD("fetchContents(title=" + target.getID() + ", scope=" + target.getScope()
                    + ", start=" + start + ", end=" + end + ", expected="
                    + target.getExpectedChildren() + ")");
            switch (target.getScope()) {
                case AvrcpControllerService.BROWSE_SCOPE_PLAYER_LIST:
                    mService.getPlayerListNative(mDeviceAddress,
@@ -873,7 +876,7 @@ class AvrcpControllerStateMachine extends StateMachine {

        @Override
        public void onSkipToQueueItem(long id) {
            logD("onSkipToQueueItem" + id);
            logD("onSkipToQueueItem id=" + id);
            onPrepare();
            BrowseTree.BrowseNode node = mBrowseTree.getTrackFromNowPlayingList((int) id);
            if (node != null) {
+485 −0

File added.

Preview size limit exceeded, changes collapsed.

+14 −6
Original line number Diff line number Diff line
@@ -16,8 +16,8 @@

package com.android.bluetooth.avrcpcontroller;

import android.bluetooth.BluetoothDevice;
import android.os.SystemClock;
import android.support.v4.media.MediaMetadataCompat;
import android.support.v4.media.session.MediaSessionCompat;
import android.support.v4.media.session.PlaybackStateCompat;
import android.util.Log;
@@ -42,6 +42,7 @@ class AvrcpPlayer {
    public static final int FEATURE_PREVIOUS = 48;
    public static final int FEATURE_BROWSING = 59;

    private BluetoothDevice mDevice;
    private int mPlayStatus = PlaybackStateCompat.STATE_NONE;
    private long mPlayTime = PlaybackStateCompat.PLAYBACK_POSITION_UNKNOWN;
    private long mPlayTimeUpdate = 0;
@@ -51,13 +52,14 @@ class AvrcpPlayer {
    private int mPlayerType;
    private byte[] mPlayerFeatures = new byte[16];
    private long mAvailableActions = PlaybackStateCompat.ACTION_PREPARE;
    private MediaMetadataCompat mCurrentTrack;
    private AvrcpItem mCurrentTrack;
    private PlaybackStateCompat mPlaybackStateCompat;
    private PlayerApplicationSettings mSupportedPlayerApplicationSettings =
            new PlayerApplicationSettings();
    private PlayerApplicationSettings mCurrentPlayerApplicationSettings;

    AvrcpPlayer() {
        mDevice = null;
        mId = INVALID_ID;
        //Set Default Actions in case Player data isn't available.
        mAvailableActions = PlaybackStateCompat.ACTION_PAUSE | PlaybackStateCompat.ACTION_PLAY
@@ -69,7 +71,9 @@ class AvrcpPlayer {
        mPlaybackStateCompat = playbackStateBuilder.build();
    }

    AvrcpPlayer(int id, String name, byte[] playerFeatures, int playStatus, int playerType) {
    AvrcpPlayer(BluetoothDevice device, int id, String name, byte[] playerFeatures, int playStatus,
            int playerType) {
        mDevice = device;
        mId = id;
        mName = name;
        mPlayStatus = playStatus;
@@ -81,6 +85,10 @@ class AvrcpPlayer {
        updateAvailableActions();
    }

    public BluetoothDevice getDevice() {
        return mDevice;
    }

    public int getId() {
        return mId;
    }
@@ -166,9 +174,9 @@ class AvrcpPlayer {
        return mPlaybackStateCompat;
    }

    public synchronized void updateCurrentTrack(MediaMetadataCompat update) {
    public synchronized void updateCurrentTrack(AvrcpItem update) {
        if (update != null) {
            long trackNumber = update.getLong(MediaMetadataCompat.METADATA_KEY_TRACK_NUMBER);
            long trackNumber = update.getTrackNumber();
            mPlaybackStateCompat = new PlaybackStateCompat.Builder(
                    mPlaybackStateCompat).setActiveQueueItemId(
                    trackNumber - 1).build();
@@ -176,7 +184,7 @@ class AvrcpPlayer {
        mCurrentTrack = update;
    }

    public synchronized MediaMetadataCompat getCurrentTrack() {
    public synchronized AvrcpItem getCurrentTrack() {
        return mCurrentTrack;
    }

Loading