AVRCP: Browse support checks for Track & NowPlaying
- Refine Browse supported logic checks while we
are sending Track & Now Playing Change where we
disallow sending Now Playing content Change rsp
& sending Track ID 0 for all non-browsable players.
- Restrict MBS connection retry for active device
switch and player switch to once.
Change-Id: I5ac2f3c7a2595431ce317a45328f0a525c1cc302
diff --git a/packages_apps_bluetooth_ext/src/avrcp/Avrcp_ext.java b/packages_apps_bluetooth_ext/src/avrcp/Avrcp_ext.java
index f4412cc..e515824 100644
--- a/packages_apps_bluetooth_ext/src/avrcp/Avrcp_ext.java
+++ b/packages_apps_bluetooth_ext/src/avrcp/Avrcp_ext.java
@@ -269,6 +269,9 @@
private SortedMap<Integer, MediaPlayerInfo_ext> mMediaPlayerInfoList;
private boolean mAvailablePlayerViewChanged;
+ private boolean mPlayerSwitching;
+ private List<String> mPkgRequestedMBSConnect;
+
/* List of media players which supports browse */
private List<BrowsePlayerInfo_ext> mBrowsePlayerInfoList;
@@ -553,6 +556,8 @@
mAvrcpPlayerAppSettingsRsp = new AvrcpPlayerAppSettingsRsp();
mMediaPlayerInfoList = new TreeMap<Integer, MediaPlayerInfo_ext>();
mAvailablePlayerViewChanged = false;
+ mPlayerSwitching = false;
+ mPkgRequestedMBSConnect = new ArrayList<String>();
mBrowsePlayerInfoList = Collections.synchronizedList(new ArrayList<BrowsePlayerInfo_ext>());
mPassthroughDispatched = 0;
mPassthroughLogs = new EvictingQueue_ext<MediaKeyLog>(PASSTHROUGH_LOG_MAX_SIZE);
@@ -675,6 +680,7 @@
mContext.unregisterReceiver(mAvrcpReceiver);
mContext.unregisterReceiver(mBootReceiver);
+ mPkgRequestedMBSConnect.clear();
mAddressedMediaPlayer.cleanup();
mAvrcpBrowseManager.cleanup();
mCurrentBrowsingDevice = null;
@@ -2340,6 +2346,7 @@
deviceFeatures[index].mReportedPlayerID != mCurrAddrPlayerID) {
Log.v(TAG, "Update player id: " + deviceFeatures[index].mReportedPlayerID +
"-> " + mCurrAddrPlayerID);
+ mPlayerSwitching = true;
if (deviceFeatures[index].mAvailablePlayersChangedNT ==
AvrcpConstants_ext.NOTIFICATION_TYPE_INTERIM) {
registerNotificationRspAvalPlayerChangedNative(
@@ -2666,10 +2673,9 @@
if (registering)
deviceFeatures[deviceIndex].mTrackChangedNT = AvrcpConstants_ext.NOTIFICATION_TYPE_INTERIM;
- MediaPlayerInfo_ext info = getAddressedPlayerInfo();
byte[] byteAddr = getByteAddress(deviceFeatures[deviceIndex].mCurrentDevice);
// for non-browsable players or no player
- if ((info != null && !info.isBrowseSupported()) ||
+ if (!isPlayerInBrowseList() ||
(deviceFeatures[deviceIndex].mFeatures & BTRC_FEAT_BROWSE) == 0) {
byte[] track = AvrcpConstants_ext.TRACK_IS_SELECTED;
if (!mMediaAttributes.exists) track = AvrcpConstants_ext.NO_TRACK_SELECTED;
@@ -2792,6 +2798,23 @@
return playStatus;
}
+ private boolean isPlayerInBrowseList() {
+ MediaPlayerInfo_ext info = getAddressedPlayerInfo();
+ String pkgName = (info != null) ? info.getPackageName():"";
+ if (pkgName == null || pkgName.isEmpty())
+ return false;
+
+ BrowsedMediaPlayer_ext player =
+ mAvrcpBrowseManager.getBrowsedMediaPlayer(dummyaddr);
+ String browseService = (pkgName != null)?getBrowseServiceName(pkgName):null;
+ if (player == null || browseService == null || browseService.isEmpty())
+ return false;
+
+ boolean isBrowseSupported = player.isPackageInMBSList(pkgName);
+ Log.d(TAG, "Browse supported for pkg " + pkgName + " is " + isBrowseSupported);
+ return isBrowseSupported;
+ }
+
private boolean isPlayingState(@Nullable PlaybackState state) {
if (state == null) return false;
return (state != null) && (state.getState() == PlaybackState.STATE_PLAYING);
@@ -3284,12 +3307,14 @@
byte[] addr = getByteAddress(active_device);
if (mAvrcpBrowseManager.getBrowsedMediaPlayer(addr) != null) {
mCurrentBrowsingDevice = active_device;
- Log.w(TAG, "Addr Player update to Browse " + PackageName);
+ Log.w(TAG, "Addr Player update to Browse " + PackageName +
+ " already req MBS list " + mPkgRequestedMBSConnect);
mAvrcpBrowseManager.getBrowsedMediaPlayer(addr).
setCurrentPackage(PackageName, browseService);
- if (player != null) {
+ if (player != null && !mPkgRequestedMBSConnect.contains(PackageName)) {
Log.w(TAG,"checkMBSConnection try connect");
player.CheckMBSConnection(PackageName, browseService);
+ mPkgRequestedMBSConnect.add(PackageName);
}
}
} else {
@@ -5135,9 +5160,15 @@
return;
}
+ if (!isPlayerInBrowseList() && !mPlayerSwitching) {
+ Log.e(TAG,"Disallow sending changed response to non Browsable Players");
+ return;
+ }
+
if (!registerNotificationRspNowPlayingChangedNative(type, addr)) {
Log.e(TAG, "registerNotificationRspNowPlayingChangedNative failed!");
}
+ mPlayerSwitching = false;
mNowPlayingListChangedNT = AvrcpConstants_ext.NOTIFICATION_TYPE_CHANGED;
}