diff options
author | Julia Reynolds <juliacr@google.com> | 2015-07-20 17:02:14 -0400 |
---|---|---|
committer | Julia Reynolds <juliacr@google.com> | 2015-07-22 12:26:53 -0400 |
commit | d30e42da053f8f79a094a19d5f143a57a89f70c9 (patch) | |
tree | d7e758850461e27076d8799bae7c49a665acdf40 /packages/SystemUI/src/com/android/systemui/statusbar | |
parent | 091f0e5c6c7f9e72a6e661c4849a2e232823075b (diff) | |
download | frameworks_base-d30e42da053f8f79a094a19d5f143a57a89f70c9.zip frameworks_base-d30e42da053f8f79a094a19d5f143a57a89f70c9.tar.gz frameworks_base-d30e42da053f8f79a094a19d5f143a57a89f70c9.tar.bz2 |
Set 'the' media notification to the notification actually playing.
Bug: 21554784
Change-Id: Ie6d4e48506805b1d5d45e7e942a259e8268916c1
Diffstat (limited to 'packages/SystemUI/src/com/android/systemui/statusbar')
-rw-r--r-- | packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBar.java | 147 |
1 files changed, 85 insertions, 62 deletions
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBar.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBar.java index 46beed7..1ca9900 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBar.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBar.java @@ -434,6 +434,12 @@ public class PhoneStatusBar extends BaseStatusBar implements DemoMode, public void onPlaybackStateChanged(PlaybackState state) { super.onPlaybackStateChanged(state); if (DEBUG_MEDIA) Log.v(TAG, "DEBUG_MEDIA: onPlaybackStateChanged: " + state); + if (state != null) { + if (!isPlaybackActive(state.getState())) { + clearCurrentMediaNotification(); + updateMediaMetaData(true); + } + } } @Override @@ -1193,6 +1199,10 @@ public class PhoneStatusBar extends BaseStatusBar implements DemoMode, if (mHeadsUpManager.isHeadsUp(key)) { deferRemoval = !mHeadsUpManager.removeNotification(key); } + if (key.equals(mMediaNotificationKey)) { + clearCurrentMediaNotification(); + updateMediaMetaData(true); + } if (deferRemoval) { mLatestRankingMap = ranking; mHeadsUpEntriesToRemoveOnSwitch.add(mHeadsUpManager.getEntry(key)); @@ -1486,23 +1496,31 @@ public class PhoneStatusBar extends BaseStatusBar implements DemoMode, synchronized (mNotificationData) { ArrayList<Entry> activeNotifications = mNotificationData.getActiveNotifications(); final int N = activeNotifications.size(); + + // Promote the media notification with a controller in 'playing' state, if any. Entry mediaNotification = null; MediaController controller = null; for (int i = 0; i < N; i++) { final Entry entry = activeNotifications.get(i); if (isMediaNotification(entry)) { - final MediaSession.Token token = entry.notification.getNotification().extras + final MediaSession.Token token = + entry.notification.getNotification().extras .getParcelable(Notification.EXTRA_MEDIA_SESSION); if (token != null) { - controller = new MediaController(mContext, token); - if (controller != null) { - // we've got a live one, here + MediaController aController = new MediaController(mContext, token); + if (PlaybackState.STATE_PLAYING == + getMediaControllerPlaybackState(aController)) { + if (DEBUG_MEDIA) { + Log.v(TAG, "DEBUG_MEDIA: found mediastyle controller matching " + + entry.notification.getKey()); + } mediaNotification = entry; + controller = aController; + break; } } } } - if (mediaNotification == null) { // Still nothing? OK, let's just look for live media sessions and see if they match // one of our notifications. This will catch apps that aren't (yet!) using media @@ -1515,83 +1533,88 @@ public class PhoneStatusBar extends BaseStatusBar implements DemoMode, UserHandle.USER_ALL); for (MediaController aController : sessions) { - if (aController == null) continue; - final PlaybackState state = aController.getPlaybackState(); - if (state == null) continue; - switch (state.getState()) { - case PlaybackState.STATE_STOPPED: - case PlaybackState.STATE_ERROR: - continue; - default: - // now to see if we have one like this - final String pkg = aController.getPackageName(); - - for (int i = 0; i < N; i++) { - final Entry entry = activeNotifications.get(i); - if (entry.notification.getPackageName().equals(pkg)) { - if (DEBUG_MEDIA) { - Log.v(TAG, "DEBUG_MEDIA: found controller matching " - + entry.notification.getKey()); - } - controller = aController; - mediaNotification = entry; - break; + if (PlaybackState.STATE_PLAYING == + getMediaControllerPlaybackState(aController)) { + // now to see if we have one like this + final String pkg = aController.getPackageName(); + + for (int i = 0; i < N; i++) { + final Entry entry = activeNotifications.get(i); + if (entry.notification.getPackageName().equals(pkg)) { + if (DEBUG_MEDIA) { + Log.v(TAG, "DEBUG_MEDIA: found controller matching " + + entry.notification.getKey()); } + controller = aController; + mediaNotification = entry; + break; } + } } } } } - if (!sameSessions(mMediaController, controller)) { + if (controller != null && !sameSessions(mMediaController, controller)) { // We have a new media session - - if (mMediaController != null) { - // something old was playing - Log.v(TAG, "DEBUG_MEDIA: Disconnecting from old controller: " - + mMediaController); - mMediaController.unregisterCallback(mMediaListener); - } + clearCurrentMediaNotification(); mMediaController = controller; + mMediaController.registerCallback(mMediaListener); + mMediaMetadata = mMediaController.getMetadata(); + if (DEBUG_MEDIA) { + Log.v(TAG, "DEBUG_MEDIA: insert listener, receive metadata: " + + mMediaMetadata); + } - if (mMediaController != null) { - mMediaController.registerCallback(mMediaListener); - mMediaMetadata = mMediaController.getMetadata(); + if (mediaNotification != null) { + mMediaNotificationKey = mediaNotification.notification.getKey(); if (DEBUG_MEDIA) { - Log.v(TAG, "DEBUG_MEDIA: insert listener, receive metadata: " - + mMediaMetadata); - } - - final String notificationKey = mediaNotification == null - ? null - : mediaNotification.notification.getKey(); - - if (notificationKey == null || !notificationKey.equals(mMediaNotificationKey)) { - // we have a new notification! - if (DEBUG_MEDIA) { - Log.v(TAG, "DEBUG_MEDIA: Found new media notification: key=" - + notificationKey + " controller=" + controller); - } - mMediaNotificationKey = notificationKey; + Log.v(TAG, "DEBUG_MEDIA: Found new media notification: key=" + + mMediaNotificationKey + " controller=" + mMediaController); } - } else { - mMediaMetadata = null; - mMediaNotificationKey = null; } - metaDataChanged = true; - } else { - // Media session unchanged - - if (DEBUG_MEDIA) { - Log.v(TAG, "DEBUG_MEDIA: Continuing media notification: key=" + mMediaNotificationKey); - } } } + if (metaDataChanged) { + updateNotifications(); + } updateMediaMetaData(metaDataChanged); } + private int getMediaControllerPlaybackState(MediaController controller) { + if (controller != null) { + final PlaybackState playbackState = controller.getPlaybackState(); + if (playbackState != null) { + return playbackState.getState(); + } + } + return PlaybackState.STATE_NONE; + } + + private boolean isPlaybackActive(int state) { + if (state != PlaybackState.STATE_STOPPED + && state != PlaybackState.STATE_ERROR + && state != PlaybackState.STATE_NONE) { + return true; + } + return false; + } + + private void clearCurrentMediaNotification() { + mMediaNotificationKey = null; + mMediaMetadata = null; + if (mMediaController != null) { + if (DEBUG_MEDIA) { + Log.v(TAG, "DEBUG_MEDIA: Disconnecting from old controller: " + + mMediaController.getPackageName()); + } + mMediaController.unregisterCallback(mMediaListener); + } + mMediaController = null; + } + private boolean sameSessions(MediaController a, MediaController b) { if (a == b) return true; if (a == null) return false; |