AVRCP_Browse: Serialize SetBrowse & GetFolderItem rsp
Some remote devices blindly sends SetBrowsePlayer and
GetFolderItems VFS cmds back to back without awaiting
SetBrowsePlayer rsp. And later never ask GetFolderitem
leading no browsing. This fix lets await GetFolderItem
rsp until DUT respond SetBrowsePlayer command first.
CRs-Fixed: 2558410
Change-Id: Iad6bdf370b971175224acf43c59ec2b72da83d18
diff --git a/packages_apps_bluetooth_ext/src/avrcp/BrowsedMediaPlayer_ext.java b/packages_apps_bluetooth_ext/src/avrcp/BrowsedMediaPlayer_ext.java
index 9699379..0bd00b5 100644
--- a/packages_apps_bluetooth_ext/src/avrcp/BrowsedMediaPlayer_ext.java
+++ b/packages_apps_bluetooth_ext/src/avrcp/BrowsedMediaPlayer_ext.java
@@ -61,6 +61,10 @@
private static final int BROWSED_FOLDER_ID_INDEX = 4;
private static final String[] ROOT_FOLDER = {"root"};
private static boolean mPlayerRoot = false;
+
+ private boolean mNeedToSendGetFolderItem = false;
+ private MediaBrowser mTempMediaBrowser = null;
+
/* package and service name of target Media Player which is set for browsing */
private String mPackageName;
private String mConnectingPackageName;
@@ -188,6 +192,7 @@
return;
}
mConnState = DISCONNECTED;
+ mTempMediaBrowser = null;
// Remove what could be a circular dependency causing GC to never happen on this object
mBrowser = null;
Log.e(TAG, "mediaBrowser Connection failed with " + mPackageName
@@ -206,6 +211,7 @@
return;
}
mBrowser = null;
+ mTempMediaBrowser = null;
mConnState = SUSPENDED;
Log.e(TAG, "mediaBrowser SUSPENDED connection with " + mPackageName);
}
@@ -222,18 +228,16 @@
Log.d(TAG, "OnChildren Loaded folder items: childrens= " + children.size());
}
- /*
- * cache current folder items and send as rsp when remote requests
- * get_folder_items (scope = vfs)
- */
+ /*
+ * cache current folder items and send as rsp when remote requests
+ * get_folder_items (scope = vfs)
+ */
if (mFolderItems == null) {
- if (DEBUG) {
- Log.d(TAG, "sending setbrowsed player rsp");
- }
Log.w(TAG, "sending setbrowsed player rsp");
mFolderItems = children;
mMediaInterface.setBrowsedPlayerRsp(mBDAddr, AvrcpConstants_ext.RSP_NO_ERROR,
(byte) 0x00, children.size(), ROOT_FOLDER);
+ RespondPendingGetFolderItemsVFS();
} else {
mFolderItems = children;
mCurrFolderNumItems = mFolderItems.size();
@@ -247,6 +251,7 @@
/* UID is invalid */
@Override
public void onError(String id) {
+ RespondPendingGetFolderItemsVFS();
Log.e(TAG, "set browsed player rsp. Could not get root folder items");
mMediaInterface.setBrowsedPlayerRsp(mBDAddr, AvrcpConstants_ext.RSP_INTERNAL_ERR,
(byte) 0x00, 0, null);
@@ -371,6 +376,7 @@
"we aren't connecting to " + connectedPackage);
mMediaInterface.setBrowsedPlayerRsp(
mBDAddr, AvrcpConstants_ext.RSP_INTERNAL_ERR, (byte) 0x00, 0, null);
+ RespondPendingGetFolderItemsVFS();
return;
}
mConnectingPackageName = null;
@@ -379,6 +385,7 @@
Log.e(TAG, "onBrowseConnect: received a null browser for " + connectedPackage);
mMediaInterface.setBrowsedPlayerRsp(mBDAddr, AvrcpConstants_ext.RSP_INTERNAL_ERR,
(byte) 0x00, 0, null);
+ RespondPendingGetFolderItemsVFS();
return;
}
@@ -405,6 +412,7 @@
Log.e(TAG, "onBrowseConnect: root value is empty or null");
mMediaInterface.setBrowsedPlayerRsp(
mBDAddr, AvrcpConstants_ext.RSP_INTERNAL_ERR, (byte) 0x00, 0, null);
+ RespondPendingGetFolderItemsVFS();
return;
}
@@ -440,6 +448,7 @@
ex.printStackTrace();
}
+ RespondPendingGetFolderItemsVFS();
mMediaInterface.setBrowsedPlayerRsp(mBDAddr, AvrcpConstants_ext.RSP_INTERNAL_ERR, (byte) 0x00,
0, null);
}
@@ -468,6 +477,7 @@
MediaConnectionCallback callback = new MediaConnectionCallback(packageName);
MediaBrowser tempBrowser = new MediaBrowser(
mContext, new ComponentName(packageName, mClassName), callback, null);
+ mTempMediaBrowser = tempBrowser;
callback.setBrowser(tempBrowser);
tempBrowser.connect();
} else if (mFolderItems != null) {
@@ -811,17 +821,22 @@
TryReconnectBrowse(mCurrentBrowsePackage, mCurrentBrowseClass);
}
- if (mFolderItems == null) {
+ if (mFolderItems == null && mTempMediaBrowser == null) {
/* Failed to fetch folder items from media player. Send error to remote device */
Log.e(TAG, "Failed to fetch folder items during getFolderItemsVFS");
mMediaInterface.folderItemsRsp(mBDAddr, AvrcpConstants_ext.RSP_INTERNAL_ERR, null);
return;
}
- /* Filter attributes based on the request and send response to remote device */
- getFolderItemsFilterAttr(mBDAddr, reqObj, mFolderItems,
- AvrcpConstants_ext.BTRC_SCOPE_FILE_SYSTEM, mFolderItemsReqObj.mStartItem,
- mFolderItemsReqObj.mEndItem);
+ if (mFolderItems != null) {
+ /* Filter attributes based on the request and send response to remote device */
+ getFolderItemsFilterAttr(mBDAddr, reqObj, mFolderItems,
+ AvrcpConstants_ext.BTRC_SCOPE_FILE_SYSTEM, mFolderItemsReqObj.mStartItem,
+ mFolderItemsReqObj.mEndItem);
+ } else {
+ mNeedToSendGetFolderItem = true;
+ Log.w(TAG, "Need to send getFolderItemsVFS after obtaing VFS");
+ }
}
/* Instructs media player to play particular media item */
@@ -1077,6 +1092,17 @@
/* Helper methods */
+ private void RespondPendingGetFolderItemsVFS() {
+ if (mNeedToSendGetFolderItem) {
+ Log.w(TAG, "send pending get foler item rsp");
+ mNeedToSendGetFolderItem = false;
+ getFolderItemsFilterAttr(mBDAddr, mFolderItemsReqObj, mFolderItems,
+ AvrcpConstants_ext.BTRC_SCOPE_FILE_SYSTEM,
+ mFolderItemsReqObj.mStartItem, mFolderItemsReqObj.mEndItem);
+ }
+ mTempMediaBrowser = null;
+ }
+
/* check if item is browsable Down*/
private boolean isBrowsableFolderDn(String uid) {
for (MediaBrowser.MediaItem item : mFolderItems) {