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

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

Merge "AVRCP: Fix concurrency issues with MediaController"

am: b4d4e110

Change-Id: Id38297009fd00b74c13b700342b172e97820c4b2
parents f4cb4577 b4d4e110
Loading
Loading
Loading
Loading
+22 −18
Original line number Diff line number Diff line
@@ -381,8 +381,6 @@ public final class Avrcp {
            Log.v(TAG, "MediaController session destroyed");
            if (mMediaController != null) {
                removeMediaController(mMediaController.getWrappedInstance());
                mMediaController.unregisterCallback(mMediaControllerCb);
                mMediaController = null;
            }
        }

@@ -1586,11 +1584,6 @@ public final class Avrcp {
                    for (android.media.session.MediaController controller : currentControllers) {
                        if (!newControllers.contains(controller)) {
                            removeMediaController(controller);
                            if (mMediaController != null && mMediaController.equals(controller)) {
                                if (DEBUG) Log.v(TAG, "Active Controller is gone!");
                                mMediaController.unregisterCallback(mMediaControllerCb);
                                mMediaController = null;
                            }
                        }
                    }

@@ -1858,11 +1851,18 @@ public final class Avrcp {
    }

    /** Remove the controller referenced by |controller| from any player in the list */
    private void removeMediaController(android.media.session.MediaController controller) {
    private void removeMediaController(@Nullable android.media.session.MediaController controller) {
        if (controller == null) return;
        synchronized (mMediaPlayerInfoList) {
            for (MediaPlayerInfo info : mMediaPlayerInfoList.values()) {
            for (Map.Entry<Integer, MediaPlayerInfo> entry : mMediaPlayerInfoList.entrySet()) {
                MediaPlayerInfo info = entry.getValue();
                MediaController c = info.getMediaController();
                if (c != null && c.equals(controller)) info.setMediaController(null);
                if (c != null && c.equals(controller)) {
                    info.setMediaController(null);
                    if (entry.getKey() == mCurrAddrPlayerID) {
                        updateCurrentController(mCurrAddrPlayerID, mCurrBrowsePlayerID);
                    }
                }
            }
        }
    }
@@ -2122,7 +2122,10 @@ public final class Avrcp {
        if (DEBUG)
            Log.d(TAG, "updateCurrentController: " + mMediaController + " to " + newController);
        if (mMediaController == null || (!mMediaController.equals(newController))) {
            if (mMediaController != null) mMediaController.unregisterCallback(mMediaControllerCb);
            synchronized (this) {
                if (mMediaController != null) {
                    mMediaController.unregisterCallback(mMediaControllerCb);
                }
                mMediaController = newController;
                if (mMediaController != null) {
                    mMediaController.registerCallback(mMediaControllerCb, mHandler);
@@ -2131,6 +2134,7 @@ public final class Avrcp {
                    mAddressedMediaPlayer.updateNowPlayingList(null);
                    registerRsp = false;
                }
            }
            updateCurrentMediaState();
        }
        return registerRsp;