diff options
| author | 2019-11-01 15:38:47 -0400 | |
|---|---|---|
| committer | 2019-11-05 17:33:00 +0000 | |
| commit | d1eb0a8c37b1dfa76674d53270e6e64bc71f7a5d (patch) | |
| tree | c2908c7ed8cc08391dbe1c95f9b7bf29d871b9d4 | |
| parent | 90ebd2b8096c9bfca62cc8b1d8d1968b7f77f818 (diff) | |
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
| -rw-r--r-- | packages/SystemUI/src/com/android/systemui/statusbar/notification/row/wrapper/NotificationMediaTemplateViewWrapper.java | 22 |
1 files changed, 13 insertions, 9 deletions
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/wrapper/NotificationMediaTemplateViewWrapper.java b/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/wrapper/NotificationMediaTemplateViewWrapper.java index d0122c2b59b2..266f487d0aaf 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/wrapper/NotificationMediaTemplateViewWrapper.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/wrapper/NotificationMediaTemplateViewWrapper.java @@ -167,12 +167,6 @@ public class NotificationMediaTemplateViewWrapper extends NotificationTemplateVi mContext = ctx; mMediaManager = Dependency.get(NotificationMediaManager.class); mMetricsLogger = Dependency.get(MetricsLogger.class); - - if (mView instanceof MediaNotificationView) { - MediaNotificationView mediaView = (MediaNotificationView) mView; - mediaView.addVisibilityListener(mVisibilityListener); - mView.addOnAttachStateChangeListener(mAttachStateListener); - } } private void resolveViews() { @@ -210,13 +204,13 @@ public class NotificationMediaTemplateViewWrapper extends NotificationTemplateVi } // 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.unregisterCallback(mMediaCallback); } mMediaController = new MediaController(mContext, token); - controllerUpdated = true; + shouldUpdateListeners = true; } mMediaMetadata = mMediaController.getMetadata(); @@ -228,7 +222,7 @@ public class NotificationMediaTemplateViewWrapper extends NotificationTemplateVi mSeekBarView.setVisibility(View.GONE); mMetricsLogger.write(newLog(MetricsEvent.TYPE_CLOSE)); clearTimer(); - } else if (mSeekBarView == null && controllerUpdated) { + } else if (mSeekBarView == null && shouldUpdateListeners) { // Only log if the controller changed, otherwise we would log multiple times for // the same notification when user pauses/resumes mMetricsLogger.write(newLog(MetricsEvent.TYPE_CLOSE)); @@ -258,6 +252,16 @@ public class NotificationMediaTemplateViewWrapper extends NotificationTemplateVi mSeekBarElapsedTime = mSeekBarView.findViewById(R.id.notification_media_elapsed_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 (mMediaController != null && canSeekMedia(mMediaController.getPlaybackState())) { // Log initial state, since it will not be updated |