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

Commit 46d72dbc authored by Marie Janssen's avatar Marie Janssen
Browse files

AVRCP: don't remove inactive media controllers

Some players change their controllers to inactive when they are
buffering, paused, or changing songs which causes us to lose track of
the controller in these states when it makes sense to keep track still.

In the case where we actually have no controller, simplify the logic
around tracking play state using A2DP feedback.

Test: Pause / Play with troublesome headphones
Bug: 38497029
Change-Id: I8e1258b85007c070fc083d9522f9fa8caa13e6f2
parent e1c09d19
Loading
Loading
Loading
Loading
+9 −23
Original line number Diff line number Diff line
@@ -946,23 +946,20 @@ public final class Avrcp {

    private void updateCurrentMediaState() {
        MediaAttributes currentAttributes = mMediaAttributes;
        PlaybackState newState = mCurrentPlayState;
        PlaybackState newState = null;
        if (mMediaController == null) {
            // Use A2DP state if we don't have a MediaControlller
            boolean isPlaying =
                    (mA2dpState == BluetoothA2dp.STATE_PLAYING) && mAudioManager.isMusicActive();
            if (isPlaying != isPlayingState(mCurrentPlayState)) {
                /* if a2dp is streaming, check to make sure music is active */
            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);
        } else {
            newState = mMediaController.getPlaybackState();
@@ -1570,17 +1567,6 @@ public final class Avrcp {
                        playersChanged = true;
                    }

                    List<android.media.session.MediaController> currentControllers =
                            getMediaControllers();
                    for (android.media.session.MediaController controller : currentControllers) {
                        if (!newControllers.contains(controller)) {
                            if (DEBUG)
                                Log.v(TAG, "Removing gone controller for "
                                                + controller.getPackageName());
                            removeMediaController(controller);
                        }
                    }

                    if (playersChanged) {
                        mHandler.sendEmptyMessage(MSG_AVAILABLE_PLAYERS_CHANGED_RSP);
                        if (newControllers.size() > 0 && getAddressedPlayerInfo() == null) {