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

Commit a8c7ddb9 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Don't reject notifications and wait until new addressed player is ready...

Merge "Don't reject notifications and wait until new addressed player is ready (1/2)" into oc-dr1-dev
parents 218ebecc 5764518b
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -149,7 +149,7 @@ public class AddressedMediaPlayer {

    private void sendNowPlayingListChanged() {
        if (mMediaInterface == null) return;
        mMediaInterface.uidsChangedRsp(AvrcpConstants.NOTIFICATION_TYPE_CHANGED);
        if (DEBUG) Log.d(TAG, "sendNowPlayingListChanged()");
        mMediaInterface.nowPlayingChangedRsp(AvrcpConstants.NOTIFICATION_TYPE_CHANGED);
        mNowPlayingListUpdated = false;
    }
+46 −45
Original line number Diff line number Diff line
@@ -371,13 +371,13 @@ public final class Avrcp {
        @Override
        public void onMetadataChanged(MediaMetadata metadata) {
            if (DEBUG) Log.v(TAG, "onMetadataChanged");
            updateCurrentMediaState(false);
            updateCurrentMediaState();
        }
        @Override
        public synchronized void onPlaybackStateChanged(PlaybackState state) {
            if (DEBUG) Log.v(TAG, "onPlaybackStateChanged: state " + state.toString());

            updateCurrentMediaState(false);
            updateCurrentMediaState();
        }

        @Override
@@ -477,7 +477,7 @@ public final class Avrcp {
            case MSG_NOW_PLAYING_CHANGED_RSP:
                if (DEBUG) Log.v(TAG, "MSG_NOW_PLAYING_CHANGED_RSP");
                removeMessages(MSG_NOW_PLAYING_CHANGED_RSP);
                updateCurrentMediaState(false);
                updateCurrentMediaState();
                break;

            case MSG_PLAY_INTERVAL_TIMEOUT:
@@ -691,7 +691,7 @@ public final class Avrcp {
            case MSG_SET_A2DP_AUDIO_STATE:
                if (DEBUG) Log.v(TAG, "MSG_SET_A2DP_AUDIO_STATE:" + msg.arg1);
                mA2dpState = msg.arg1;
                updateCurrentMediaState(false);
                updateCurrentMediaState();
                break;

            case MSG_NATIVE_REQ_GET_FOLDER_ITEMS: {
@@ -962,36 +962,8 @@ public final class Avrcp {
        }
    }

    private void updateCurrentMediaState(boolean registering) {
    private void updateCurrentMediaState() {
        // Only do player updates when we aren't registering for track changes.
        if (!registering) {
            if (mAvailablePlayerViewChanged) {
                registerNotificationRspAvalPlayerChangedNative(
                        AvrcpConstants.NOTIFICATION_TYPE_CHANGED);
                mAvailablePlayerViewChanged = false;
                return;
            }
            if (mAddrPlayerChangedNT == AvrcpConstants.NOTIFICATION_TYPE_INTERIM
                    && mReportedPlayerID != mCurrAddrPlayerID) {
                registerNotificationRspAvalPlayerChangedNative(
                        AvrcpConstants.NOTIFICATION_TYPE_CHANGED);
                mAvailablePlayerViewChanged = false;
                registerNotificationRspAddrPlayerChangedNative(
                        AvrcpConstants.NOTIFICATION_TYPE_CHANGED, mCurrAddrPlayerID, sUIDCounter);
                mAddrPlayerChangedNT = AvrcpConstants.NOTIFICATION_TYPE_CHANGED;
                // Changing player sends reject to anything else we would notify...
                mReportedPlayerID = mCurrAddrPlayerID;
                mPlayStatusChangedNT = AvrcpConstants.NOTIFICATION_TYPE_CHANGED;
                mTrackChangedNT = AvrcpConstants.NOTIFICATION_TYPE_CHANGED;
                mPlayPosChangedNT = AvrcpConstants.NOTIFICATION_TYPE_CHANGED;
                mNowPlayingListChangedNT = AvrcpConstants.NOTIFICATION_TYPE_CHANGED;
                mAddressedMediaPlayer.updateNowPlayingList(mMediaController);
                // If the player changed, they need to re-request anything here again
                // so we can skip the rest of the update.
                return;
            }
        }

        MediaAttributes currentAttributes;
        PlaybackState newState = updatePlaybackState();

@@ -1013,6 +985,30 @@ public final class Avrcp {
                            + currentAttributes.toRedactedString() + " : "
                            + mMediaAttributes.toRedactedString());

            if (mAvailablePlayerViewChanged) {
                registerNotificationRspAvalPlayerChangedNative(
                        AvrcpConstants.NOTIFICATION_TYPE_CHANGED);
                mAvailablePlayerViewChanged = false;
                return;
            }

            if (mAddrPlayerChangedNT == AvrcpConstants.NOTIFICATION_TYPE_INTERIM
                    && mReportedPlayerID != mCurrAddrPlayerID) {
                registerNotificationRspAvalPlayerChangedNative(
                        AvrcpConstants.NOTIFICATION_TYPE_CHANGED);
                registerNotificationRspAddrPlayerChangedNative(
                        AvrcpConstants.NOTIFICATION_TYPE_CHANGED, mCurrAddrPlayerID, sUIDCounter);

                mAvailablePlayerViewChanged = false;
                mAddrPlayerChangedNT = AvrcpConstants.NOTIFICATION_TYPE_CHANGED;
                mReportedPlayerID = mCurrAddrPlayerID;

                // Update the now playing list without sending the notification
                mNowPlayingListChangedNT = AvrcpConstants.NOTIFICATION_TYPE_CHANGED;
                mAddressedMediaPlayer.updateNowPlayingList(mMediaController);
                mNowPlayingListChangedNT = AvrcpConstants.NOTIFICATION_TYPE_INTERIM;
            }

            // Dont send now playing list changed if the player doesn't support browsing
            MediaPlayerInfo info = getAddressedPlayerInfo();
            if (info != null && info.isBrowseSupported()) {
@@ -1029,21 +1025,25 @@ public final class Avrcp {
                // to update their metadata. Hold of on sending the playback state
                // update until after we know the current metadata is up to date
                // and track changed has been sent. This was seen on BMW carkits
                Log.i(TAG, "Waiting for metadata update to send track changed");
                Log.i(TAG,
                        "Waiting for metadata update to send track changed: " + newQueueId + " : "
                                + currentAttributes + " : " + mMediaAttributes);

                return;
            }

            // Notify track changed if:
            //  - The CT is registering for the notification
            //  - The CT is registered for the notification
            //  - Queue ID is UNKNOWN and MediaMetadata is different
            //  - Queue ID is valid and different and MediaMetadata is different
            if (registering || ((newQueueId == -1 || newQueueId != mLastQueueId)
                                       && !currentAttributes.equals(mMediaAttributes))) {
            //  - Queue ID is valid and different from last Queue ID sent
            if ((newQueueId == -1 || newQueueId != mLastQueueId)
                    && mTrackChangedNT == AvrcpConstants.NOTIFICATION_TYPE_INTERIM
                    && !currentAttributes.equals(mMediaAttributes)
                    && newPlayStatus == PLAYSTATUS_PLAYING) {
                Log.v(TAG, "Send track changed");
                mMediaAttributes = currentAttributes;
                mLastQueueId = newQueueId;
                sendTrackChangedRsp(registering);
                sendTrackChangedRsp(false);
            }
        } else {
            Log.i(TAG, "Skipping update due to invalid playback state");
@@ -1631,7 +1631,7 @@ public final class Avrcp {
                            Log.v(TAG, "No addressed player but active sessions, taking first.");
                        setAddressedMediaSessionPackage(newControllers.get(0).getPackageName());
                    }
                    updateCurrentMediaState(false);
                    updateCurrentMediaState();
                }
            };

@@ -1651,7 +1651,7 @@ public final class Avrcp {
        // If the player doesn't exist, we need to add it.
        if (getMediaPlayerInfo(packageName) == null) {
            addMediaPlayerPackage(packageName);
            updateCurrentMediaState(false);
            updateCurrentMediaState();
        }
        synchronized (mMediaPlayerInfoList) {
            for (Map.Entry<Integer, MediaPlayerInfo> entry : mMediaPlayerInfoList.entrySet()) {
@@ -1659,7 +1659,7 @@ public final class Avrcp {
                    int newAddrID = entry.getKey();
                    if (DEBUG) Log.v(TAG, "Set addressed #" + newAddrID + " " + entry.getValue());
                    updateCurrentController(newAddrID, mCurrBrowsePlayerID);
                    updateCurrentMediaState(false);
                    updateCurrentMediaState();
                    return;
                }
            }
@@ -1740,7 +1740,7 @@ public final class Avrcp {
                    addMediaPlayerPackage(packageName);
                }
            }
            updateCurrentMediaState(false);
            updateCurrentMediaState();
        }
    }

@@ -1764,7 +1764,7 @@ public final class Avrcp {
                addMediaPlayerController(controller);
            }

            updateCurrentMediaState(false);
            updateCurrentMediaState();

            if (mMediaPlayerInfoList.size() > 0) {
                // Set the first one as the Addressed Player
@@ -2153,7 +2153,7 @@ public final class Avrcp {
                }
            }
        }
        updateCurrentMediaState(false);
        updateCurrentMediaState();
        return registerRsp;
    }

@@ -2567,6 +2567,7 @@ public final class Avrcp {
        if (!KeyEvent.isMediaKey(code)) {
            Log.w(TAG, "Passthrough non-media key " + op + " (code " + code + ") state " + state);
        }

        mMediaSessionManager.dispatchMediaKeyEvent(event);
        addKeyPending(event);
    }