Android-x86
Fork
Donation

  • R/O
  • HTTP
  • SSH
  • HTTPS

packages-apps-Bluetooth: 提交

packages/apps/Bluetooth


Commit MetaInfo

修订版3e25adee90d4594ff622bf5f5174333556b7c136 (tree)
时间2017-06-24 10:25:10
作者Ajay Panicker <apanicke@goog...>
Commiterandroid-build-team Robot

Log Message

AVRCP: Fix NowPlayingList looping

When a controller requested GetFolderItems, we would sometimes send a
NowPlayingListChanged before responding to GetFolderItems, prompting a
new GetFolderItems request. This put us in an infinite loop.

Test: connect to BMW and note it actually works
Bug: 62775732

Change-Id: Idc669a03f71ed9ec6b211bb5c33fc98548cc9f85
(cherry picked from commit d65422f9b47bff59b12162fc51032eb633f0722f)

更改概述

差异

--- a/src/com/android/bluetooth/avrcp/AddressedMediaPlayer.java
+++ b/src/com/android/bluetooth/avrcp/AddressedMediaPlayer.java
@@ -54,12 +54,14 @@ public class AddressedMediaPlayer {
5454 private final List<MediaSession.QueueItem> mEmptyNowPlayingList;
5555
5656 private long mLastTrackIdSent;
57+ private boolean mNowPlayingListUpdated;
5758
5859 public AddressedMediaPlayer(AvrcpMediaRspInterface mediaInterface) {
5960 mEmptyNowPlayingList = new ArrayList<MediaSession.QueueItem>();
6061 mNowPlayingList = mEmptyNowPlayingList;
6162 mMediaInterface = mediaInterface;
6263 mLastTrackIdSent = MediaSession.QueueItem.UNKNOWN_ID;
64+ mNowPlayingListUpdated = false;
6365 }
6466
6567 void cleanup() {
@@ -67,12 +69,12 @@ public class AddressedMediaPlayer {
6769 mNowPlayingList = mEmptyNowPlayingList;
6870 mMediaInterface = null;
6971 mLastTrackIdSent = MediaSession.QueueItem.UNKNOWN_ID;
72+ mNowPlayingListUpdated = false;
7073 }
7174
7275 /* get now playing list from addressed player */
7376 void getFolderItemsNowPlaying(byte[] bdaddr, AvrcpCmd.FolderItemsCmd reqObj,
7477 @Nullable MediaController mediaController) {
75- if (DEBUG) Log.v(TAG, "getFolderItemsNowPlaying");
7678 if (mediaController == null) {
7779 // No players (if a player exists, we would have selected it)
7880 Log.e(TAG, "mediaController = null, sending no available players response");
@@ -120,7 +122,10 @@ public class AddressedMediaPlayer {
120122 @Nullable MediaController mediaController) {
121123 if (mediaController == null) return mEmptyNowPlayingList;
122124 List<MediaSession.QueueItem> items = mediaController.getQueue();
123- if (items == mNowPlayingList) return mNowPlayingList;
125+ if (items != null && !mNowPlayingListUpdated) {
126+ mNowPlayingList = items;
127+ return mNowPlayingList;
128+ }
124129 if (items == null) {
125130 Log.i(TAG, "null queue from " + mediaController.getPackageName()
126131 + ", constructing single-item list");
@@ -131,12 +136,19 @@ public class AddressedMediaPlayer {
131136 items = new ArrayList<MediaSession.QueueItem>();
132137 items.add(current);
133138 }
139+
134140 mNowPlayingList = items;
135- // TODO (jamuraa): test to see if the single-item queue is the same and don't send
136- if (mMediaInterface != null) {
137- mMediaInterface.nowPlayingChangedRsp(AvrcpConstants.NOTIFICATION_TYPE_CHANGED);
138- }
139- return items;
141+
142+ if (mNowPlayingListUpdated) sendNowPlayingListChanged();
143+
144+ return mNowPlayingList;
145+ }
146+
147+ private void sendNowPlayingListChanged() {
148+ if (mMediaInterface == null) return;
149+ mMediaInterface.uidsChangedRsp(AvrcpConstants.NOTIFICATION_TYPE_CHANGED);
150+ mMediaInterface.nowPlayingChangedRsp(AvrcpConstants.NOTIFICATION_TYPE_CHANGED);
151+ mNowPlayingListUpdated = false;
140152 }
141153
142154 /* Constructs a queue item representing the current playing metadata from an
@@ -196,6 +208,7 @@ public class AddressedMediaPlayer {
196208 }
197209
198210 void updateNowPlayingList(@Nullable MediaController mediaController) {
211+ mNowPlayingListUpdated = true;
199212 getNowPlayingList(mediaController);
200213 }
201214
@@ -239,14 +252,13 @@ public class AddressedMediaPlayer {
239252 }
240253
241254 void sendTrackChangeWithId(int type, @Nullable MediaController mediaController) {
242- if (DEBUG)
243- Log.d(TAG, "sendTrackChangeWithId (" + type + "): controller " + mediaController);
255+ Log.d(TAG, "sendTrackChangeWithId (" + type + "): controller " + mediaController);
244256 long qid = getActiveQueueItemId(mediaController);
245257 byte[] track = ByteBuffer.allocate(AvrcpConstants.UID_SIZE).putLong(qid).array();
258+ // The nowPlayingList changed: the new list has the full data for the current item
259+ if (type == AvrcpConstants.NOTIFICATION_TYPE_CHANGED) sendNowPlayingListChanged();
246260 mMediaInterface.trackChangedRsp(type, track);
247261 mLastTrackIdSent = qid;
248- // The nowPlaying might have changed.
249- updateNowPlayingList(mediaController);
250262 }
251263
252264 /*
--- a/src/com/android/bluetooth/avrcp/Avrcp.java
+++ b/src/com/android/bluetooth/avrcp/Avrcp.java
@@ -2496,7 +2496,7 @@ public final class Avrcp {
24962496 }
24972497 }
24982498
2499- public void uidsChangedRsp(byte[] address, int type, int uidCounter) {
2499+ public void uidsChangedRsp(int type) {
25002500 if (!registerNotificationRspUIDsChangedNative(type, sUIDCounter)) {
25012501 Log.e(TAG, "registerNotificationRspUIDsChangedNative failed!");
25022502 }
--- a/src/com/android/bluetooth/avrcp/AvrcpMediaRspInterface.java
+++ b/src/com/android/bluetooth/avrcp/AvrcpMediaRspInterface.java
@@ -45,7 +45,7 @@ public interface AvrcpMediaRspInterface {
4545
4646 public void avalPlayerChangedRsp(byte[] address, int type);
4747
48- public void uidsChangedRsp(byte[] address, int type, int uidCounter);
48+ public void uidsChangedRsp(int type);
4949
5050 public void nowPlayingChangedRsp(int type);
5151
Show on old repository browser