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

Commit 483e1e64 authored by Marie Janssen's avatar Marie Janssen Committed by android-build-merger
Browse files

Merge "AVRCP: synchronize around mMediaController"

am: a3273598

Change-Id: Ia833281da8820a7b8ee6f16402dc65d165858a2c
parents aaba74f8 a3273598
Loading
Loading
Loading
Loading
+32 −25
Original line number Diff line number Diff line
@@ -334,7 +334,9 @@ public final class Avrcp {

    public void doQuit() {
        if (DEBUG) Log.d(TAG, "doQuit");
        synchronized (this) {
            if (mMediaController != null) mMediaController.unregisterCallback(mMediaControllerCb);
        }
        if (mMediaSessionManager != null) {
            mMediaSessionManager.setCallback(null, null);
            mMediaSessionManager.removeOnActiveSessionsChangedListener(mActiveSessionListener);
@@ -377,7 +379,8 @@ public final class Avrcp {
        @Override
        public void onSessionDestroyed() {
            Log.v(TAG, "MediaController session destroyed");
            if (mMediaController != null) {
            synchronized (Avrcp.this) {
                if (mMediaController != null)
                    removeMediaController(mMediaController.getWrappedInstance());
            }
        }
@@ -947,17 +950,18 @@ public final class Avrcp {
    private void updateCurrentMediaState() {
        MediaAttributes currentAttributes = mMediaAttributes;
        PlaybackState newState = null;
        synchronized (this) {
            if (mMediaController == null) {
                // Use A2DP state if we don't have a MediaControlller
            boolean isPlaying =
                    (mA2dpState == BluetoothA2dp.STATE_PLAYING) && mAudioManager.isMusicActive();
                boolean isPlaying = (mA2dpState == BluetoothA2dp.STATE_PLAYING)
                        && mAudioManager.isMusicActive();
                PlaybackState.Builder builder = new PlaybackState.Builder();
                if (isPlaying) {
                builder.setState(
                        PlaybackState.STATE_PLAYING, PlaybackState.PLAYBACK_POSITION_UNKNOWN, 1.0f);
                    builder.setState(PlaybackState.STATE_PLAYING,
                            PlaybackState.PLAYBACK_POSITION_UNKNOWN, 1.0f);
                } else {
                builder.setState(
                        PlaybackState.STATE_PAUSED, PlaybackState.PLAYBACK_POSITION_UNKNOWN, 0.0f);
                    builder.setState(PlaybackState.STATE_PAUSED,
                            PlaybackState.PLAYBACK_POSITION_UNKNOWN, 0.0f);
                }
                newState = builder.build();
                mMediaAttributes = new MediaAttributes(null);
@@ -965,6 +969,7 @@ public final class Avrcp {
                newState = mMediaController.getPlaybackState();
                mMediaAttributes = new MediaAttributes(mMediaController.getMetadata());
            }
        }

        long oldQueueId = mCurrentPlayState.getActiveQueueItemId();
        long newQueueId = MediaSession.QueueItem.UNKNOWN_ID;
@@ -2101,8 +2106,8 @@ public final class Avrcp {

        if (DEBUG)
            Log.d(TAG, "updateCurrentController: " + mMediaController + " to " + newController);
        if (mMediaController == null || (!mMediaController.equals(newController))) {
        synchronized (this) {
            if (mMediaController == null || (!mMediaController.equals(newController))) {
                if (mMediaController != null) {
                    mMediaController.unregisterCallback(mMediaControllerCb);
                }
@@ -2115,8 +2120,8 @@ public final class Avrcp {
                    registerRsp = false;
                }
            }
            updateCurrentMediaState();
        }
        updateCurrentMediaState();
        return registerRsp;
    }

@@ -2288,10 +2293,12 @@ public final class Avrcp {
        ProfileService.println(sb, "mVolCmdSetInProgress: " + mVolCmdSetInProgress);
        ProfileService.println(sb, "mAbsVolRetryTimes: " + mAbsVolRetryTimes);
        ProfileService.println(sb, "mVolumeMapping: " + mVolumeMapping.toString());
        synchronized (this) {
            if (mMediaController != null)
            ProfileService.println(sb, "mMediaController: " + mMediaController.getWrappedInstance()
                            + " pkg " + mMediaController.getPackageName());

                ProfileService.println(sb, "mMediaController: "
                                + mMediaController.getWrappedInstance() + " pkg "
                                + mMediaController.getPackageName());
        }
        ProfileService.println(sb, "");
        ProfileService.println(sb, "Media Players:");
        synchronized (mMediaPlayerInfoList) {