@@ -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