Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 5594c9d9 authored by Ajay Panicker's avatar Ajay Panicker Committed by Myles Watson
Browse files

Fix IndexOutOfBounds exception due to incorrect media player start index

Before, if there were no addressed players there would be an index
out of bounds exception due to accessing past the end of the array
as position zero would be skipped. Now set start index to 0 if there
is no addressed player.

Bug: 64440498
Test: Connect to carkit with only one player
Change-Id: I76bf4a872e9722ca7cc6b1ca90f88200a72c8c27
(cherry picked from commit b50a7964)
parent 119a5314
Loading
Loading
Loading
Loading
+4 −4
Original line number Diff line number Diff line
@@ -2053,12 +2053,12 @@ public final class Avrcp {
            short[] featureBitMaskValues =
                    new short[numPlayers * AvrcpConstants.AVRC_FEATURE_MASK_SIZE];

            // Reserve the first spot for the currently addressed player
            int players = 1;
            // Reserve the first spot for the currently addressed player if
            // we have one
            int players = mMediaPlayerInfoList.containsKey(mCurrAddrPlayerID) ? 1 : 0;
            for (Map.Entry<Integer, MediaPlayerInfo> entry : mMediaPlayerInfoList.entrySet()) {
                int idx = players;
                if (entry.getKey() == mCurrAddrPlayerID || mMediaPlayerInfoList.size() == 1)
                    idx = 0;
                if (entry.getKey() == mCurrAddrPlayerID) idx = 0;
                MediaPlayerInfo info = entry.getValue();
                playerIds[idx] = entry.getKey();
                playerTypes[idx] = info.getMajorType();