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

Commit 75c7717c authored by Ajay Panicker's avatar Ajay Panicker
Browse files

Return cached data for the Now Playing Queue

Similar to the need to cache the folder items, we need to cache the now
playing list since carkits will poll for the data in chunks. If we have
to go through the framework for the data every time this can be
incredibly slow causing lots of jenk.

Bug: 77879544
Test: "runtest bluetooth -c com.android.bluetooth.avrcp.MediaPlayerWrapperTest"
      Also test with BMW with a playlist of over 300 songs.

Change-Id: Ib2c8af797d3d87b79bbf386775506bcc06715a33
(cherry picked from commit 359b7b5d31933c19751fab5644966e11776c81da)
parent cc4feca4
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -133,7 +133,7 @@ class MediaPlayerWrapper {
    }

    List<Metadata> getCurrentQueue() {
        return Util.toMetadataList(getQueue());
        return mCurrentData.queue;
    }

    // We don't return the cached info here in order to always provide the freshest data.
+22 −0
Original line number Diff line number Diff line
@@ -311,6 +311,28 @@ public class MediaPlayerWrapperTest {
        verify(mFailHandler, never()).onTerribleFailure(any(), any(), anyBoolean());
    }

    /*
     * This test checks to see if the now playing queue data is cached.
     */
    @Test
    public void testQueueCached() {
        // Create the wrapper object and register the looper with the timeout handler
        TestLooperManager looperManager = new TestLooperManager(mThread.getLooper());
        MediaPlayerWrapper wrapper =
                MediaPlayerWrapper.wrap(mMockController, mThread.getLooper());
        wrapper.registerCallback(mTestCbs);

        // Call getCurrentQueue() multiple times.
        for (int i = 0; i < 3; i++) {
            Assert.assertEquals(wrapper.getCurrentQueue(),
                    Util.toMetadataList(getQueueFromDescriptions(mTestQueue)));
        }

        // Verify that getQueue() was only called twice. Once on creation and once during
        // registration
        verify(mMockController, times(2)).getQueue();
    }

    /*
     * This test sends repeated Playback State updates that only have a short
     * position update change to see if they get debounced.