Merge "Match players based on notification key" into rvc-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
0fcd767d5f
@@ -82,6 +82,7 @@ public class MediaControlPanel {
|
|||||||
protected ComponentName mRecvComponent;
|
protected ComponentName mRecvComponent;
|
||||||
private MediaDevice mDevice;
|
private MediaDevice mDevice;
|
||||||
private boolean mIsRegistered = false;
|
private boolean mIsRegistered = false;
|
||||||
|
private String mKey;
|
||||||
|
|
||||||
private final int[] mActionIds;
|
private final int[] mActionIds;
|
||||||
|
|
||||||
@@ -203,14 +204,15 @@ public class MediaControlPanel {
|
|||||||
* @param bgColor
|
* @param bgColor
|
||||||
* @param contentIntent
|
* @param contentIntent
|
||||||
* @param appNameString
|
* @param appNameString
|
||||||
* @param device
|
* @param key
|
||||||
*/
|
*/
|
||||||
public void setMediaSession(MediaSession.Token token, Icon icon, int iconColor,
|
public void setMediaSession(MediaSession.Token token, Icon icon, int iconColor,
|
||||||
int bgColor, PendingIntent contentIntent, String appNameString) {
|
int bgColor, PendingIntent contentIntent, String appNameString, String key) {
|
||||||
mToken = token;
|
mToken = token;
|
||||||
mForegroundColor = iconColor;
|
mForegroundColor = iconColor;
|
||||||
mBackgroundColor = bgColor;
|
mBackgroundColor = bgColor;
|
||||||
mController = new MediaController(mContext, mToken);
|
mController = new MediaController(mContext, mToken);
|
||||||
|
mKey = key;
|
||||||
|
|
||||||
MediaMetadata mediaMetadata = mController.getMetadata();
|
MediaMetadata mediaMetadata = mController.getMetadata();
|
||||||
|
|
||||||
@@ -325,6 +327,14 @@ public class MediaControlPanel {
|
|||||||
return mController.getPackageName();
|
return mController.getPackageName();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the original notification's key
|
||||||
|
* @return The notification key
|
||||||
|
*/
|
||||||
|
public String getKey() {
|
||||||
|
return mKey;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check whether this player has an attached media session.
|
* Check whether this player has an attached media session.
|
||||||
* @return whether there is a controller with a current media session.
|
* @return whether there is a controller with a current media session.
|
||||||
|
|||||||
@@ -99,15 +99,14 @@ public class QSMediaPlayer extends MediaControlPanel {
|
|||||||
* @param bgColor background color
|
* @param bgColor background color
|
||||||
* @param actionsContainer a LinearLayout containing the media action buttons
|
* @param actionsContainer a LinearLayout containing the media action buttons
|
||||||
* @param notif reference to original notification
|
* @param notif reference to original notification
|
||||||
* @param device current playback device
|
* @param key original notification's key
|
||||||
*/
|
*/
|
||||||
public void setMediaSession(MediaSession.Token token, Icon icon, int iconColor,
|
public void setMediaSession(MediaSession.Token token, Icon icon, int iconColor,
|
||||||
int bgColor, View actionsContainer, Notification notif) {
|
int bgColor, View actionsContainer, Notification notif, String key) {
|
||||||
|
|
||||||
String appName = Notification.Builder.recoverBuilder(getContext(), notif)
|
String appName = Notification.Builder.recoverBuilder(getContext(), notif)
|
||||||
.loadHeaderAppName();
|
.loadHeaderAppName();
|
||||||
super.setMediaSession(token, icon, iconColor, bgColor, notif.contentIntent,
|
super.setMediaSession(token, icon, iconColor, bgColor, notif.contentIntent, appName, key);
|
||||||
appName);
|
|
||||||
|
|
||||||
// Media controls
|
// Media controls
|
||||||
LinearLayout parentActionsLayout = (LinearLayout) actionsContainer;
|
LinearLayout parentActionsLayout = (LinearLayout) actionsContainer;
|
||||||
|
|||||||
@@ -208,9 +208,10 @@ public class QSPanel extends LinearLayout implements Tunable, Callback, Brightne
|
|||||||
* @param bgColor
|
* @param bgColor
|
||||||
* @param actionsContainer
|
* @param actionsContainer
|
||||||
* @param notif
|
* @param notif
|
||||||
|
* @param key
|
||||||
*/
|
*/
|
||||||
public void addMediaSession(MediaSession.Token token, Icon icon, int iconColor, int bgColor,
|
public void addMediaSession(MediaSession.Token token, Icon icon, int iconColor, int bgColor,
|
||||||
View actionsContainer, StatusBarNotification notif) {
|
View actionsContainer, StatusBarNotification notif, String key) {
|
||||||
if (!useQsMediaPlayer(mContext)) {
|
if (!useQsMediaPlayer(mContext)) {
|
||||||
// Shouldn't happen, but just in case
|
// Shouldn't happen, but just in case
|
||||||
Log.e(TAG, "Tried to add media session without player!");
|
Log.e(TAG, "Tried to add media session without player!");
|
||||||
@@ -225,13 +226,12 @@ public class QSPanel extends LinearLayout implements Tunable, Callback, Brightne
|
|||||||
String packageName = notif.getPackageName();
|
String packageName = notif.getPackageName();
|
||||||
for (QSMediaPlayer p : mMediaPlayers) {
|
for (QSMediaPlayer p : mMediaPlayers) {
|
||||||
if (p.getMediaSessionToken().equals(token)) {
|
if (p.getMediaSessionToken().equals(token)) {
|
||||||
Log.d(TAG, "a player for this session already exists");
|
Log.d(TAG, "Found matching player by token " + packageName);
|
||||||
player = p;
|
player = p;
|
||||||
break;
|
break;
|
||||||
}
|
} else if (packageName.equals(p.getMediaPlayerPackage()) && key.equals(p.getKey())) {
|
||||||
|
// Also match if it's the same package and notification key
|
||||||
if (packageName.equals(p.getMediaPlayerPackage())) {
|
Log.d(TAG, "Found matching player by package " + packageName + ", " + key);
|
||||||
Log.d(TAG, "found an old session for this app");
|
|
||||||
player = p;
|
player = p;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -267,7 +267,7 @@ public class QSPanel extends LinearLayout implements Tunable, Callback, Brightne
|
|||||||
|
|
||||||
Log.d(TAG, "setting player session");
|
Log.d(TAG, "setting player session");
|
||||||
player.setMediaSession(token, icon, iconColor, bgColor, actionsContainer,
|
player.setMediaSession(token, icon, iconColor, bgColor, actionsContainer,
|
||||||
notif.getNotification());
|
notif.getNotification(), key);
|
||||||
|
|
||||||
if (mMediaPlayers.size() > 0) {
|
if (mMediaPlayers.size() > 0) {
|
||||||
((View) mMediaCarousel.getParent()).setVisibility(View.VISIBLE);
|
((View) mMediaCarousel.getParent()).setVisibility(View.VISIBLE);
|
||||||
|
|||||||
@@ -67,9 +67,10 @@ public class QuickQSMediaPlayer extends MediaControlPanel {
|
|||||||
* @param actionsToShow indices of which actions to display in the mini player
|
* @param actionsToShow indices of which actions to display in the mini player
|
||||||
* (max 3: Notification.MediaStyle.MAX_MEDIA_BUTTONS_IN_COMPACT)
|
* (max 3: Notification.MediaStyle.MAX_MEDIA_BUTTONS_IN_COMPACT)
|
||||||
* @param contentIntent Intent to send when user taps on the view
|
* @param contentIntent Intent to send when user taps on the view
|
||||||
|
* @param key original notification's key
|
||||||
*/
|
*/
|
||||||
public void setMediaSession(MediaSession.Token token, Icon icon, int iconColor, int bgColor,
|
public void setMediaSession(MediaSession.Token token, Icon icon, int iconColor, int bgColor,
|
||||||
View actionsContainer, int[] actionsToShow, PendingIntent contentIntent) {
|
View actionsContainer, int[] actionsToShow, PendingIntent contentIntent, String key) {
|
||||||
// Only update if this is a different session and currently playing
|
// Only update if this is a different session and currently playing
|
||||||
String oldPackage = "";
|
String oldPackage = "";
|
||||||
if (getController() != null) {
|
if (getController() != null) {
|
||||||
@@ -84,7 +85,7 @@ public class QuickQSMediaPlayer extends MediaControlPanel {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
super.setMediaSession(token, icon, iconColor, bgColor, contentIntent, null);
|
super.setMediaSession(token, icon, iconColor, bgColor, contentIntent, null, key);
|
||||||
|
|
||||||
LinearLayout parentActionsLayout = (LinearLayout) actionsContainer;
|
LinearLayout parentActionsLayout = (LinearLayout) actionsContainer;
|
||||||
int i = 0;
|
int i = 0;
|
||||||
|
|||||||
@@ -193,7 +193,8 @@ public class NotificationMediaTemplateViewWrapper extends NotificationTemplateVi
|
|||||||
mBackgroundColor,
|
mBackgroundColor,
|
||||||
mActions,
|
mActions,
|
||||||
compactActions,
|
compactActions,
|
||||||
notif.contentIntent);
|
notif.contentIntent,
|
||||||
|
sbn.getKey());
|
||||||
QSPanel bigPanel = ctrl.getNotificationShadeView().findViewById(
|
QSPanel bigPanel = ctrl.getNotificationShadeView().findViewById(
|
||||||
com.android.systemui.R.id.quick_settings_panel);
|
com.android.systemui.R.id.quick_settings_panel);
|
||||||
bigPanel.addMediaSession(token,
|
bigPanel.addMediaSession(token,
|
||||||
@@ -201,7 +202,8 @@ public class NotificationMediaTemplateViewWrapper extends NotificationTemplateVi
|
|||||||
tintColor,
|
tintColor,
|
||||||
mBackgroundColor,
|
mBackgroundColor,
|
||||||
mActions,
|
mActions,
|
||||||
sbn);
|
sbn,
|
||||||
|
sbn.getKey());
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean showCompactSeekbar = mMediaManager.getShowCompactMediaSeekbar();
|
boolean showCompactSeekbar = mMediaManager.getShowCompactMediaSeekbar();
|
||||||
|
|||||||
Reference in New Issue
Block a user