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

Commit 28ee736f authored by Sal Savage's avatar Sal Savage
Browse files

Migrate the rest of AVRCP Controller to use MediaCompat

There are still a few chunks of code in AVRCP Controller that do not use
the MediaCompat library objects. This change gets all AVRCP code to
agree on the compay library, providing a solid base for the cover art
feature.

Bug: b/132812696
Test: Build, Flash, Interopt test with other devices + atest
Change-Id: I62f3acb15ec9ba0ce8c6a6f2fc8a89d193964498
parent 9eb36944
Loading
Loading
Loading
Loading
+4 −4
Original line number Diff line number Diff line
@@ -805,7 +805,7 @@ static void classInitNative(JNIEnv* env, jclass clazz) {

  method_handleGetFolderItemsRsp =
      env->GetMethodID(clazz, "handleGetFolderItemsRsp",
                       "([BI[Landroid/media/browse/MediaBrowser$MediaItem;)V");
                       "([BI[Landroid/support/v4/media/MediaBrowserCompat$MediaItem;)V");
  method_handleGetPlayerItemsRsp = env->GetMethodID(
      clazz, "handleGetPlayerItemsRsp",
      "([B[Lcom/android/bluetooth/avrcpcontroller/AvrcpPlayer;)V");
@@ -813,10 +813,10 @@ static void classInitNative(JNIEnv* env, jclass clazz) {
  method_createFromNativeMediaItem =
      env->GetMethodID(clazz, "createFromNativeMediaItem",
                       "(JILjava/lang/String;[I[Ljava/lang/String;)Landroid/"
                       "media/browse/MediaBrowser$MediaItem;");
                       "support/v4/media/MediaBrowserCompat$MediaItem;");
  method_createFromNativeFolderItem = env->GetMethodID(
      clazz, "createFromNativeFolderItem",
      "(JILjava/lang/String;I)Landroid/media/browse/MediaBrowser$MediaItem;");
      "(JILjava/lang/String;I)Landroid/support/v4/media/MediaBrowserCompat$MediaItem;");
  method_createFromNativePlayerItem =
      env->GetMethodID(clazz, "createFromNativePlayerItem",
                       "(ILjava/lang/String;[BII)Lcom/android/bluetooth/"
@@ -841,7 +841,7 @@ static void initNative(JNIEnv* env, jobject object) {
  std::unique_lock<std::shared_timed_mutex> lock(sCallbacks_mutex);

  jclass tmpMediaItem =
      env->FindClass("android/media/browse/MediaBrowser$MediaItem");
      env->FindClass("android/support/v4/media/MediaBrowserCompat$MediaItem");
  class_MediaBrowser_MediaItem = (jclass)env->NewGlobalRef(tmpMediaItem);

  jclass tmpBtPlayer =
+12 −12
Original line number Diff line number Diff line
@@ -22,10 +22,10 @@ import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothProfile;
import android.bluetooth.IBluetoothAvrcpController;
import android.content.Intent;
import android.media.MediaDescription;
import android.media.browse.MediaBrowser.MediaItem;
import android.media.session.PlaybackState;
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;

import com.android.bluetooth.Utils;
@@ -392,25 +392,25 @@ public class AvrcpControllerService extends ProfileService {
        if (DBG) {
            Log.d(TAG, "onPlayStatusChanged " + playStatus);
        }
        int playbackState = PlaybackState.STATE_NONE;
        int playbackState = PlaybackStateCompat.STATE_NONE;
        switch (playStatus) {
            case JNI_PLAY_STATUS_STOPPED:
                playbackState = PlaybackState.STATE_STOPPED;
                playbackState = PlaybackStateCompat.STATE_STOPPED;
                break;
            case JNI_PLAY_STATUS_PLAYING:
                playbackState = PlaybackState.STATE_PLAYING;
                playbackState = PlaybackStateCompat.STATE_PLAYING;
                break;
            case JNI_PLAY_STATUS_PAUSED:
                playbackState = PlaybackState.STATE_PAUSED;
                playbackState = PlaybackStateCompat.STATE_PAUSED;
                break;
            case JNI_PLAY_STATUS_FWD_SEEK:
                playbackState = PlaybackState.STATE_FAST_FORWARDING;
                playbackState = PlaybackStateCompat.STATE_FAST_FORWARDING;
                break;
            case JNI_PLAY_STATUS_REV_SEEK:
                playbackState = PlaybackState.STATE_REWINDING;
                playbackState = PlaybackStateCompat.STATE_REWINDING;
                break;
            default:
                playbackState = PlaybackState.STATE_NONE;
                playbackState = PlaybackStateCompat.STATE_NONE;
        }
        BluetoothDevice device = BluetoothAdapter.getDefaultAdapter().getRemoteDevice(address);
        AvrcpControllerStateMachine stateMachine = getStateMachine(device);
@@ -524,7 +524,7 @@ public class AvrcpControllerService extends ProfileService {
            Log.d(TAG, "createFromNativeMediaItem uid: " + uid + " type " + type + " name "
                    + name + " attrids " + attrIds + " attrVals " + attrVals);
        }
        MediaDescription.Builder mdb = new MediaDescription.Builder();
        MediaDescriptionCompat.Builder mdb = new MediaDescriptionCompat.Builder();

        Bundle mdExtra = new Bundle();
        mdExtra.putLong(MEDIA_ITEM_UID_KEY, uid);
@@ -548,7 +548,7 @@ public class AvrcpControllerService extends ProfileService {
            Log.d(TAG, "createFromNativeFolderItem uid: " + uid + " type " + type + " name "
                    + name + " playable " + playable);
        }
        MediaDescription.Builder mdb = new MediaDescription.Builder();
        MediaDescriptionCompat.Builder mdb = new MediaDescriptionCompat.Builder();

        Bundle mdExtra = new Bundle();
        mdExtra.putLong(MEDIA_ITEM_UID_KEY, uid);
+4 −4
Original line number Diff line number Diff line
@@ -22,10 +22,10 @@ import android.bluetooth.BluetoothProfile;
import android.content.Context;
import android.content.Intent;
import android.media.AudioManager;
import android.media.MediaMetadata;
import android.media.browse.MediaBrowser.MediaItem;
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 +397,9 @@ class AvrcpControllerStateMachine extends StateMachine {
                    return true;

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

+5 −5
Original line number Diff line number Diff line
@@ -16,8 +16,8 @@

package com.android.bluetooth.avrcpcontroller;

import android.media.MediaMetadata;
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;
@@ -51,7 +51,7 @@ class AvrcpPlayer {
    private int mPlayerType;
    private byte[] mPlayerFeatures = new byte[16];
    private long mAvailableActions = PlaybackStateCompat.ACTION_PREPARE;
    private MediaMetadata mCurrentTrack;
    private MediaMetadataCompat mCurrentTrack;
    private PlaybackStateCompat mPlaybackStateCompat;
    private PlayerApplicationSettings mSupportedPlayerApplicationSettings =
            new PlayerApplicationSettings();
@@ -166,9 +166,9 @@ class AvrcpPlayer {
        return mPlaybackStateCompat;
    }

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

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

+6 −11
Original line number Diff line number Diff line
@@ -18,11 +18,8 @@ package com.android.bluetooth.avrcpcontroller;

import android.app.PendingIntent;
import android.content.Intent;
import android.media.MediaMetadata;
import android.media.browse.MediaBrowser.MediaItem;
import android.os.Bundle;
import android.support.v4.media.MediaBrowserCompat;
import android.support.v4.media.MediaDescriptionCompat;
import android.support.v4.media.MediaBrowserCompat.MediaItem;
import android.support.v4.media.MediaMetadataCompat;
import android.support.v4.media.session.MediaControllerCompat;
import android.support.v4.media.session.MediaSessionCompat;
@@ -137,10 +134,9 @@ public class BluetoothMediaBrowserService extends MediaBrowserServiceCompat {

    @Override
    public synchronized void onLoadChildren(final String parentMediaId,
            final Result<List<MediaBrowserCompat.MediaItem>> result) {
            final Result<List<MediaItem>> result) {
        if (DBG) Log.d(TAG, "onLoadChildren parentMediaId=" + parentMediaId);
        List<MediaBrowserCompat.MediaItem> contents =
                MediaBrowserCompat.MediaItem.fromMediaItemList(getContents(parentMediaId));
        List<MediaItem> contents = getContents(parentMediaId);
        if (contents == null) {
            result.detach();
        } else {
@@ -161,7 +157,7 @@ public class BluetoothMediaBrowserService extends MediaBrowserServiceCompat {
        if (songList != null) {
            for (MediaItem song : songList) {
                mMediaQueue.add(new MediaSessionCompat.QueueItem(
                        MediaDescriptionCompat.fromMediaDescription(song.getDescription()),
                        song.getDescription(),
                        mMediaQueue.size()));
            }
        }
@@ -189,10 +185,9 @@ public class BluetoothMediaBrowserService extends MediaBrowserServiceCompat {
        }
    }

    static synchronized void trackChanged(MediaMetadata mediaMetadata) {
    static synchronized void trackChanged(MediaMetadataCompat mediaMetadata) {
        if (sBluetoothMediaBrowserService != null) {
            sBluetoothMediaBrowserService.mSession.setMetadata(
                    MediaMetadataCompat.fromMediaMetadata(mediaMetadata));
            sBluetoothMediaBrowserService.mSession.setMetadata(mediaMetadata);
        } else {
            Log.w(TAG, "trackChanged Unavailable");
        }
Loading