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

Commit d1eb0a8c authored by Beth Thibodeau's avatar Beth Thibodeau
Browse files

Update callbacks when media session has changed

In some cases it is possible to destroy the media session but still have
a notification in the shade. An app can then make a new session and
update the same notification with it.

Since we remove the callback/listener when a session is destroyed, we also
need to add them again if the session has changed.

Fixes: 142909875
Test: manual; atest
com.android.systemui.statusbar.notification.row.wrapper.NotificationMediaTemplateViewWrapperTest

Change-Id: Iefaf28b931f5438be005455af1e0fbb40fed2d60
parent 90ebd2b8
Loading
Loading
Loading
Loading
+13 −9
Original line number Original line Diff line number Diff line
@@ -167,12 +167,6 @@ public class NotificationMediaTemplateViewWrapper extends NotificationTemplateVi
        mContext = ctx;
        mContext = ctx;
        mMediaManager = Dependency.get(NotificationMediaManager.class);
        mMediaManager = Dependency.get(NotificationMediaManager.class);
        mMetricsLogger = Dependency.get(MetricsLogger.class);
        mMetricsLogger = Dependency.get(MetricsLogger.class);

        if (mView instanceof MediaNotificationView) {
            MediaNotificationView mediaView = (MediaNotificationView) mView;
            mediaView.addVisibilityListener(mVisibilityListener);
            mView.addOnAttachStateChangeListener(mAttachStateListener);
        }
    }
    }


    private void resolveViews() {
    private void resolveViews() {
@@ -210,13 +204,13 @@ public class NotificationMediaTemplateViewWrapper extends NotificationTemplateVi
        }
        }


        // Check for existing media controller and clean up / create as necessary
        // Check for existing media controller and clean up / create as necessary
        boolean controllerUpdated = false;
        boolean shouldUpdateListeners = false;
        if (mMediaController == null || !mMediaController.getSessionToken().equals(token)) {
        if (mMediaController == null || !mMediaController.getSessionToken().equals(token)) {
            if (mMediaController != null) {
            if (mMediaController != null) {
                mMediaController.unregisterCallback(mMediaCallback);
                mMediaController.unregisterCallback(mMediaCallback);
            }
            }
            mMediaController = new MediaController(mContext, token);
            mMediaController = new MediaController(mContext, token);
            controllerUpdated = true;
            shouldUpdateListeners = true;
        }
        }


        mMediaMetadata = mMediaController.getMetadata();
        mMediaMetadata = mMediaController.getMetadata();
@@ -228,7 +222,7 @@ public class NotificationMediaTemplateViewWrapper extends NotificationTemplateVi
                    mSeekBarView.setVisibility(View.GONE);
                    mSeekBarView.setVisibility(View.GONE);
                    mMetricsLogger.write(newLog(MetricsEvent.TYPE_CLOSE));
                    mMetricsLogger.write(newLog(MetricsEvent.TYPE_CLOSE));
                    clearTimer();
                    clearTimer();
                } else if (mSeekBarView == null && controllerUpdated) {
                } else if (mSeekBarView == null && shouldUpdateListeners) {
                    // Only log if the controller changed, otherwise we would log multiple times for
                    // Only log if the controller changed, otherwise we would log multiple times for
                    // the same notification when user pauses/resumes
                    // the same notification when user pauses/resumes
                    mMetricsLogger.write(newLog(MetricsEvent.TYPE_CLOSE));
                    mMetricsLogger.write(newLog(MetricsEvent.TYPE_CLOSE));
@@ -258,6 +252,16 @@ public class NotificationMediaTemplateViewWrapper extends NotificationTemplateVi
            mSeekBarElapsedTime = mSeekBarView.findViewById(R.id.notification_media_elapsed_time);
            mSeekBarElapsedTime = mSeekBarView.findViewById(R.id.notification_media_elapsed_time);
            mSeekBarTotalTime = mSeekBarView.findViewById(R.id.notification_media_total_time);
            mSeekBarTotalTime = mSeekBarView.findViewById(R.id.notification_media_total_time);


            shouldUpdateListeners = true;
        }

        if (shouldUpdateListeners) {
            if (mView instanceof MediaNotificationView) {
                MediaNotificationView mediaView = (MediaNotificationView) mView;
                mediaView.addVisibilityListener(mVisibilityListener);
                mView.addOnAttachStateChangeListener(mAttachStateListener);
            }

            if (mSeekBarTimer == null) {
            if (mSeekBarTimer == null) {
                if (mMediaController != null && canSeekMedia(mMediaController.getPlaybackState())) {
                if (mMediaController != null && canSeekMedia(mMediaController.getPlaybackState())) {
                    // Log initial state, since it will not be updated
                    // Log initial state, since it will not be updated