Skip to content

Commit 4dd3fb3

Browse files
committed
Fix audio focus evaluation order for display update
Change 1f9196a introduced an issue when trying to ignore audio focus entries in the stack that don't use the music stream, or are for transient audio focus gain, for remote control display updates. The bug was that the audio focus stack traversal was not starting from the top, as it should. It was using the iterator order, which, in the case of a stack, starts with the bottom-most entry. The fix consists in traversing the stack from the top, i.e. from the last element of the vector used to hold the stack entries. Bug 7311023 Change-Id: I0c1900dbf98599a621a420ab55531a3eee838fe5
1 parent 02053d1 commit 4dd3fb3

File tree

1 file changed

+14
-8
lines changed

1 file changed

+14
-8
lines changed

media/java/android/media/AudioService.java

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5088,18 +5088,23 @@ private void checkUpdateRemoteControlDisplay_syncAfRcs(int infoChangedFlags) {
50885088
// top of the stack for the media button event receivers : simply using the top of the
50895089
// stack would make the entry disappear from the RemoteControlDisplay in conditions such as
50905090
// notifications playing during music playback.
5091-
// crawl the AudioFocus stack until an entry is found with the following characteristics:
5091+
// Crawl the AudioFocus stack from the top until an entry is found with the following
5092+
// characteristics:
50925093
// - focus gain on STREAM_MUSIC stream
50935094
// - non-transient focus gain on a stream other than music
50945095
FocusStackEntry af = null;
5095-
Iterator<FocusStackEntry> stackIterator = mFocusStack.iterator();
5096-
while(stackIterator.hasNext()) {
5097-
FocusStackEntry fse = (FocusStackEntry)stackIterator.next();
5098-
if ((fse.mStreamType == AudioManager.STREAM_MUSIC)
5099-
|| (fse.mFocusChangeType == AudioManager.AUDIOFOCUS_GAIN)) {
5100-
af = fse;
5101-
break;
5096+
try {
5097+
for (int index = mFocusStack.size()-1; index >= 0; index--) {
5098+
FocusStackEntry fse = mFocusStack.elementAt(index);
5099+
if ((fse.mStreamType == AudioManager.STREAM_MUSIC)
5100+
|| (fse.mFocusChangeType == AudioManager.AUDIOFOCUS_GAIN)) {
5101+
af = fse;
5102+
break;
5103+
}
51025104
}
5105+
} catch (ArrayIndexOutOfBoundsException e) {
5106+
Log.e(TAG, "Wrong index accessing audio focus stack when updating RCD: " + e);
5107+
af = null;
51035108
}
51045109
if (af == null) {
51055110
clearRemoteControlDisplay_syncAfRcs();
@@ -5120,6 +5125,7 @@ private void checkUpdateRemoteControlDisplay_syncAfRcs(int infoChangedFlags) {
51205125
clearRemoteControlDisplay_syncAfRcs();
51215126
return;
51225127
}
5128+
51235129
// refresh conditions were verified: update the remote controls
51245130
// ok to call: synchronized mAudioFocusLock then on mRCStack, mRCStack is not empty
51255131
updateRemoteControlDisplay_syncAfRcs(infoChangedFlags);

0 commit comments

Comments
 (0)