Loading android/app/jni/com_android_bluetooth_avrcp_target.cpp +15 −13 Original line number Diff line number Diff line Loading @@ -74,7 +74,7 @@ static std::vector<SongInfo> getNowPlayingList(); static uint16_t getCurrentPlayerId(); static std::vector<MediaPlayerInfo> getMediaPlayerList(); using SetBrowsedPlayerCb = MediaInterface::SetBrowsedPlayerCallback; static void setBrowsedPlayer(uint16_t player_id, SetBrowsedPlayerCb); static void setBrowsedPlayer(uint16_t player_id, std::string current_path, SetBrowsedPlayerCb); static uint16_t setAddressedPlayer(uint16_t player_id); using GetFolderItemsCb = MediaInterface::FolderItemsCallback; static void getFolderItems(uint16_t player_id, std::string media_id, GetFolderItemsCb cb); Loading Loading @@ -165,8 +165,9 @@ public: cb.Run(current_player); } void SetBrowsedPlayer(uint16_t player_id, SetBrowsedPlayerCallback browse_cb) override { setBrowsedPlayer(player_id, browse_cb); void SetBrowsedPlayer(uint16_t player_id, std::string current_path, SetBrowsedPlayerCallback browse_cb) override { setBrowsedPlayer(player_id, current_path, browse_cb); } void SetAddressedPlayer(uint16_t player_id, SetAddressedPlayerCallback addressed_cb) override { Loading Loading @@ -693,7 +694,7 @@ static std::vector<MediaPlayerInfo> getMediaPlayerList() { return ret_list; } static void setBrowsedPlayer(uint16_t player_id, SetBrowsedPlayerCb cb) { static void setBrowsedPlayer(uint16_t player_id, std::string current_path, SetBrowsedPlayerCb cb) { log::debug(""); std::shared_lock<std::shared_timed_mutex> lock(callbacks_mutex); CallbackEnv sCallbackEnv(__func__); Loading @@ -702,21 +703,22 @@ static void setBrowsedPlayer(uint16_t player_id, SetBrowsedPlayerCb cb) { } set_browsed_player_cb = cb; sCallbackEnv->CallVoidMethod(mJavaInterface, method_setBrowsedPlayer, player_id); jstring j_current_path = sCallbackEnv->NewStringUTF(current_path.c_str()); sCallbackEnv->CallVoidMethod(mJavaInterface, method_setBrowsedPlayer, player_id, j_current_path); } static void setBrowsedPlayerResponseNative(JNIEnv* env, jobject /* object */, jint /* player_id */, jboolean success, jstring root_id, jint num_items) { jboolean success, jstring current_path, jint num_items) { log::debug(""); std::string root; if (root_id != nullptr) { const char* value = env->GetStringUTFChars(root_id, nullptr); root = std::string(value); env->ReleaseStringUTFChars(root_id, value); std::string path; if (current_path != nullptr) { const char* value = env->GetStringUTFChars(current_path, nullptr); path = std::string(value); env->ReleaseStringUTFChars(current_path, value); } set_browsed_player_cb.Run(success == JNI_TRUE, root, num_items); set_browsed_player_cb.Run(success == JNI_TRUE, path, num_items); } static uint16_t setAddressedPlayer(uint16_t player_id) { Loading Loading @@ -1101,7 +1103,7 @@ int register_com_android_bluetooth_avrcp_target(JNIEnv* env) { {"getNowPlayingList", "()Ljava/util/List;", &method_getNowPlayingList}, {"getCurrentPlayerId", "()I", &method_getCurrentPlayerId}, {"getMediaPlayerList", "()Ljava/util/List;", &method_getMediaPlayerList}, {"setBrowsedPlayer", "(I)V", &method_setBrowsedPlayer}, {"setBrowsedPlayer", "(ILjava/lang/String;)V", &method_setBrowsedPlayer}, {"setAddressedPlayer", "(I)I", &method_setAddressedPlayer}, {"getFolderItemsRequest", "(ILjava/lang/String;)V", &method_getFolderItemsRequest}, {"playItem", "(IZLjava/lang/String;)V", &method_playItem}, Loading android/app/src/com/android/bluetooth/audio_util/MediaPlayerList.java +21 −11 Original line number Diff line number Diff line Loading @@ -117,7 +117,7 @@ public class MediaPlayerList { void run(boolean availablePlayers, boolean addressedPlayers, boolean uids); } public interface GetPlayerRootCallback { public interface SetBrowsedPlayerCallback { void run(int playerId, boolean success, String rootId, int numItems); } Loading Loading @@ -371,14 +371,16 @@ public class MediaPlayerList { mMediaSessionManager.dispatchMediaKeyEvent(event, false); } public void getPlayerRoot(int playerId, GetPlayerRootCallback cb) { /** Sets the {@link #mBrowsingPlayerId} and returns the number of items in current path */ public void setBrowsedPlayer(int playerId, String currentPath, SetBrowsedPlayerCallback cb) { if (Flags.browsingRefactor()) { if (!haveMediaBrowser(playerId)) { cb.run(playerId, false, "", 0); return; } mBrowsingPlayerId = playerId; MediaBrowserWrapper wrapper = mMediaBrowserWrappers.get(playerId); // If player is different than actual or if the given path is wrong, process rootId if (playerId != mBrowsingPlayerId || currentPath.equals("")) { wrapper.getRootId( (rootId) -> { wrapper.getFolderItems( Loading @@ -387,6 +389,14 @@ public class MediaPlayerList { cb.run(playerId, true, rootId, itemList.size()); }); }); } else { wrapper.getFolderItems( currentPath, (parentId, itemList) -> { cb.run(playerId, true, currentPath, itemList.size()); }); } mBrowsingPlayerId = playerId; } else { // Fix PTS AVRCP/TG/MCN/CB/BI-02-C if (Utils.isPtsTestMode()) { Loading android/app/src/com/android/bluetooth/avrcp/AvrcpNativeInterface.java +8 −9 Original line number Diff line number Diff line Loading @@ -172,24 +172,23 @@ public class AvrcpNativeInterface { return mAvrcpService.getMediaPlayerList(); } // TODO(apanicke): This shouldn't be named setBrowsedPlayer as it doesn't actually connect // anything internally. It just returns the number of items in the root folder. void setBrowsedPlayer(int playerId) { d("setBrowsedPlayer: playerId=" + playerId); mAvrcpService.getPlayerRoot(playerId, (a, b, c, d) -> setBrowsedPlayerResponse(a, b, c, d)); void setBrowsedPlayer(int playerId, String currentPath) { d("setBrowsedPlayer: playerId=" + playerId + ", currentPath= " + currentPath); mAvrcpService.setBrowsedPlayer( playerId, currentPath, (a, b, c, d) -> setBrowsedPlayerResponse(a, b, c, d)); } void setBrowsedPlayerResponse(int playerId, boolean success, String rootId, int numItems) { void setBrowsedPlayerResponse(int playerId, boolean success, String currentPath, int numItems) { d( "setBrowsedPlayerResponse: playerId=" + playerId + " success=" + success + " rootId=" + rootId + " currentPath=" + currentPath + " numItems=" + numItems); setBrowsedPlayerResponseNative(playerId, success, rootId, numItems); setBrowsedPlayerResponseNative(playerId, success, currentPath, numItems); } int setAddressedPlayer(int playerId) { Loading android/app/src/com/android/bluetooth/avrcp/AvrcpTargetService.java +4 −3 Original line number Diff line number Diff line Loading @@ -478,9 +478,10 @@ public class AvrcpTargetService extends ProfileService { return mMediaPlayerList.getMediaPlayerList(); } /** See {@link MediaPlayerList#getPlayerRoot}. */ void getPlayerRoot(int playerId, MediaPlayerList.GetPlayerRootCallback cb) { mMediaPlayerList.getPlayerRoot(playerId, cb); /** See {@link MediaPlayerList#setBrowsedPlayer}. */ void setBrowsedPlayer( int playerId, String currentPath, MediaPlayerList.SetBrowsedPlayerCallback cb) { mMediaPlayerList.setBrowsedPlayer(playerId, currentPath, cb); } /** See {@link MediaPlayerList#setAddressedPlayer}. */ Loading system/btif/avrcp/avrcp_service.cc +3 −2 Original line number Diff line number Diff line Loading @@ -244,7 +244,8 @@ public: base::Bind(&MediaInterface::GetAddressedPlayer, base::Unretained(wrapped_), bound_cb)); } void SetBrowsedPlayer(uint16_t player_id, SetBrowsedPlayerCallback browse_cb) override { void SetBrowsedPlayer(uint16_t player_id, std::string current_path, SetBrowsedPlayerCallback browse_cb) override { auto cb_lambda = [](SetBrowsedPlayerCallback cb, bool success, std::string root_id, uint32_t num_items) { do_in_main_thread(base::BindOnce(cb, success, root_id, num_items)); Loading @@ -253,7 +254,7 @@ public: auto bound_cb = base::Bind(cb_lambda, browse_cb); do_in_jni_thread(base::Bind(&MediaInterface::SetBrowsedPlayer, base::Unretained(wrapped_), player_id, bound_cb)); player_id, current_path, bound_cb)); } void SetAddressedPlayer(uint16_t player_id, SetAddressedPlayerCallback addressed_cb) override { Loading Loading
android/app/jni/com_android_bluetooth_avrcp_target.cpp +15 −13 Original line number Diff line number Diff line Loading @@ -74,7 +74,7 @@ static std::vector<SongInfo> getNowPlayingList(); static uint16_t getCurrentPlayerId(); static std::vector<MediaPlayerInfo> getMediaPlayerList(); using SetBrowsedPlayerCb = MediaInterface::SetBrowsedPlayerCallback; static void setBrowsedPlayer(uint16_t player_id, SetBrowsedPlayerCb); static void setBrowsedPlayer(uint16_t player_id, std::string current_path, SetBrowsedPlayerCb); static uint16_t setAddressedPlayer(uint16_t player_id); using GetFolderItemsCb = MediaInterface::FolderItemsCallback; static void getFolderItems(uint16_t player_id, std::string media_id, GetFolderItemsCb cb); Loading Loading @@ -165,8 +165,9 @@ public: cb.Run(current_player); } void SetBrowsedPlayer(uint16_t player_id, SetBrowsedPlayerCallback browse_cb) override { setBrowsedPlayer(player_id, browse_cb); void SetBrowsedPlayer(uint16_t player_id, std::string current_path, SetBrowsedPlayerCallback browse_cb) override { setBrowsedPlayer(player_id, current_path, browse_cb); } void SetAddressedPlayer(uint16_t player_id, SetAddressedPlayerCallback addressed_cb) override { Loading Loading @@ -693,7 +694,7 @@ static std::vector<MediaPlayerInfo> getMediaPlayerList() { return ret_list; } static void setBrowsedPlayer(uint16_t player_id, SetBrowsedPlayerCb cb) { static void setBrowsedPlayer(uint16_t player_id, std::string current_path, SetBrowsedPlayerCb cb) { log::debug(""); std::shared_lock<std::shared_timed_mutex> lock(callbacks_mutex); CallbackEnv sCallbackEnv(__func__); Loading @@ -702,21 +703,22 @@ static void setBrowsedPlayer(uint16_t player_id, SetBrowsedPlayerCb cb) { } set_browsed_player_cb = cb; sCallbackEnv->CallVoidMethod(mJavaInterface, method_setBrowsedPlayer, player_id); jstring j_current_path = sCallbackEnv->NewStringUTF(current_path.c_str()); sCallbackEnv->CallVoidMethod(mJavaInterface, method_setBrowsedPlayer, player_id, j_current_path); } static void setBrowsedPlayerResponseNative(JNIEnv* env, jobject /* object */, jint /* player_id */, jboolean success, jstring root_id, jint num_items) { jboolean success, jstring current_path, jint num_items) { log::debug(""); std::string root; if (root_id != nullptr) { const char* value = env->GetStringUTFChars(root_id, nullptr); root = std::string(value); env->ReleaseStringUTFChars(root_id, value); std::string path; if (current_path != nullptr) { const char* value = env->GetStringUTFChars(current_path, nullptr); path = std::string(value); env->ReleaseStringUTFChars(current_path, value); } set_browsed_player_cb.Run(success == JNI_TRUE, root, num_items); set_browsed_player_cb.Run(success == JNI_TRUE, path, num_items); } static uint16_t setAddressedPlayer(uint16_t player_id) { Loading Loading @@ -1101,7 +1103,7 @@ int register_com_android_bluetooth_avrcp_target(JNIEnv* env) { {"getNowPlayingList", "()Ljava/util/List;", &method_getNowPlayingList}, {"getCurrentPlayerId", "()I", &method_getCurrentPlayerId}, {"getMediaPlayerList", "()Ljava/util/List;", &method_getMediaPlayerList}, {"setBrowsedPlayer", "(I)V", &method_setBrowsedPlayer}, {"setBrowsedPlayer", "(ILjava/lang/String;)V", &method_setBrowsedPlayer}, {"setAddressedPlayer", "(I)I", &method_setAddressedPlayer}, {"getFolderItemsRequest", "(ILjava/lang/String;)V", &method_getFolderItemsRequest}, {"playItem", "(IZLjava/lang/String;)V", &method_playItem}, Loading
android/app/src/com/android/bluetooth/audio_util/MediaPlayerList.java +21 −11 Original line number Diff line number Diff line Loading @@ -117,7 +117,7 @@ public class MediaPlayerList { void run(boolean availablePlayers, boolean addressedPlayers, boolean uids); } public interface GetPlayerRootCallback { public interface SetBrowsedPlayerCallback { void run(int playerId, boolean success, String rootId, int numItems); } Loading Loading @@ -371,14 +371,16 @@ public class MediaPlayerList { mMediaSessionManager.dispatchMediaKeyEvent(event, false); } public void getPlayerRoot(int playerId, GetPlayerRootCallback cb) { /** Sets the {@link #mBrowsingPlayerId} and returns the number of items in current path */ public void setBrowsedPlayer(int playerId, String currentPath, SetBrowsedPlayerCallback cb) { if (Flags.browsingRefactor()) { if (!haveMediaBrowser(playerId)) { cb.run(playerId, false, "", 0); return; } mBrowsingPlayerId = playerId; MediaBrowserWrapper wrapper = mMediaBrowserWrappers.get(playerId); // If player is different than actual or if the given path is wrong, process rootId if (playerId != mBrowsingPlayerId || currentPath.equals("")) { wrapper.getRootId( (rootId) -> { wrapper.getFolderItems( Loading @@ -387,6 +389,14 @@ public class MediaPlayerList { cb.run(playerId, true, rootId, itemList.size()); }); }); } else { wrapper.getFolderItems( currentPath, (parentId, itemList) -> { cb.run(playerId, true, currentPath, itemList.size()); }); } mBrowsingPlayerId = playerId; } else { // Fix PTS AVRCP/TG/MCN/CB/BI-02-C if (Utils.isPtsTestMode()) { Loading
android/app/src/com/android/bluetooth/avrcp/AvrcpNativeInterface.java +8 −9 Original line number Diff line number Diff line Loading @@ -172,24 +172,23 @@ public class AvrcpNativeInterface { return mAvrcpService.getMediaPlayerList(); } // TODO(apanicke): This shouldn't be named setBrowsedPlayer as it doesn't actually connect // anything internally. It just returns the number of items in the root folder. void setBrowsedPlayer(int playerId) { d("setBrowsedPlayer: playerId=" + playerId); mAvrcpService.getPlayerRoot(playerId, (a, b, c, d) -> setBrowsedPlayerResponse(a, b, c, d)); void setBrowsedPlayer(int playerId, String currentPath) { d("setBrowsedPlayer: playerId=" + playerId + ", currentPath= " + currentPath); mAvrcpService.setBrowsedPlayer( playerId, currentPath, (a, b, c, d) -> setBrowsedPlayerResponse(a, b, c, d)); } void setBrowsedPlayerResponse(int playerId, boolean success, String rootId, int numItems) { void setBrowsedPlayerResponse(int playerId, boolean success, String currentPath, int numItems) { d( "setBrowsedPlayerResponse: playerId=" + playerId + " success=" + success + " rootId=" + rootId + " currentPath=" + currentPath + " numItems=" + numItems); setBrowsedPlayerResponseNative(playerId, success, rootId, numItems); setBrowsedPlayerResponseNative(playerId, success, currentPath, numItems); } int setAddressedPlayer(int playerId) { Loading
android/app/src/com/android/bluetooth/avrcp/AvrcpTargetService.java +4 −3 Original line number Diff line number Diff line Loading @@ -478,9 +478,10 @@ public class AvrcpTargetService extends ProfileService { return mMediaPlayerList.getMediaPlayerList(); } /** See {@link MediaPlayerList#getPlayerRoot}. */ void getPlayerRoot(int playerId, MediaPlayerList.GetPlayerRootCallback cb) { mMediaPlayerList.getPlayerRoot(playerId, cb); /** See {@link MediaPlayerList#setBrowsedPlayer}. */ void setBrowsedPlayer( int playerId, String currentPath, MediaPlayerList.SetBrowsedPlayerCallback cb) { mMediaPlayerList.setBrowsedPlayer(playerId, currentPath, cb); } /** See {@link MediaPlayerList#setAddressedPlayer}. */ Loading
system/btif/avrcp/avrcp_service.cc +3 −2 Original line number Diff line number Diff line Loading @@ -244,7 +244,8 @@ public: base::Bind(&MediaInterface::GetAddressedPlayer, base::Unretained(wrapped_), bound_cb)); } void SetBrowsedPlayer(uint16_t player_id, SetBrowsedPlayerCallback browse_cb) override { void SetBrowsedPlayer(uint16_t player_id, std::string current_path, SetBrowsedPlayerCallback browse_cb) override { auto cb_lambda = [](SetBrowsedPlayerCallback cb, bool success, std::string root_id, uint32_t num_items) { do_in_main_thread(base::BindOnce(cb, success, root_id, num_items)); Loading @@ -253,7 +254,7 @@ public: auto bound_cb = base::Bind(cb_lambda, browse_cb); do_in_jni_thread(base::Bind(&MediaInterface::SetBrowsedPlayer, base::Unretained(wrapped_), player_id, bound_cb)); player_id, current_path, bound_cb)); } void SetAddressedPlayer(uint16_t player_id, SetAddressedPlayerCallback addressed_cb) override { Loading