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

Commit f9cf5659 authored by Joseph Pirozzo's avatar Joseph Pirozzo
Browse files

AVRCP Controller onSkipToQueueItem invalid

Prevent exceptions where skip to queue item results in an invalid song.

Bug: 138803592
Test: atest com.android.bluetooth.avrcpcontroller.AvrcpControllerStateMachineTest#testSkipToQueueInvalid
Change-Id: Icb9b0e85188335299fb62f0b30ada0a005ad20a3
parent 5dfcb838
Loading
Loading
Loading
Loading
+8 −1
Original line number Diff line number Diff line
@@ -100,7 +100,7 @@ public class BrowseTree {
    }

    BrowseNode getTrackFromNowPlayingList(int trackNumber) {
        return mNowPlayingNode.mChildren.get(trackNumber);
        return mNowPlayingNode.getChild(trackNumber);
    }

    // Each node of the tree is represented by Folder ID, Folder Name and the children.
@@ -218,6 +218,13 @@ public class BrowseTree {
            return mChildren;
        }

        synchronized BrowseNode getChild(int index) {
            if (index < 0 || index >= mChildren.size()) {
                return null;
            }
            return mChildren.get(index);
        }

        synchronized BrowseNode getParent() {
            return mParent;
        }
+25 −0
Original line number Diff line number Diff line
@@ -364,6 +364,31 @@ public class AvrcpControllerStateMachineTest {
                eq(mTestAddress), eq(AvrcpControllerService.PASS_THRU_CMD_ID_REWIND), eq(KEY_UP));
    }

    /**
     * Test media browser skip to queue item
     */
    @Test
    public void testSkipToQueueInvalid() throws Exception {
        byte scope = 1;
        int minSize = 0;
        int maxSize = 255;
        setUpConnectedState(true, true);
        MediaControllerCompat.TransportControls transportControls =
                BluetoothMediaBrowserService.getTransportControls();

        //Play an invalid item below start
        transportControls.skipToQueueItem(minSize - 1);
        verify(mAvrcpControllerService,
                timeout(ASYNC_CALL_TIMEOUT_MILLIS).times(0)).playItemNative(
                eq(mTestAddress), eq(scope), anyLong(), anyInt());

        //Play an invalid item beyond end
        transportControls.skipToQueueItem(maxSize + 1);
        verify(mAvrcpControllerService,
                timeout(ASYNC_CALL_TIMEOUT_MILLIS).times(0)).playItemNative(
                eq(mTestAddress), eq(scope), anyLong(), anyInt());
    }

    /**
     * Test media browser shuffle command
     */