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

Commit 3ca98b83 authored by Beth Thibodeau's avatar Beth Thibodeau Committed by Automerger Merge Worker
Browse files

Merge "Add check for null token when updating state" into tm-dev am: 0e29401d am: 9854e5d1

parents 446e32ea 9854e5d1
Loading
Loading
Loading
Loading
+2 −1
Original line number Original line Diff line number Diff line
@@ -16,6 +16,7 @@


package com.android.systemui.media;
package com.android.systemui.media;


import android.annotation.NonNull;
import android.content.Context;
import android.content.Context;
import android.media.session.MediaController;
import android.media.session.MediaController;
import android.media.session.MediaSession;
import android.media.session.MediaSession;
@@ -39,7 +40,7 @@ public class MediaControllerFactory {
     *
     *
     * @param token The token for the session. This value must never be null.
     * @param token The token for the session. This value must never be null.
     */
     */
    public MediaController create(MediaSession.Token token) {
    public MediaController create(@NonNull MediaSession.Token token) {
        return new MediaController(mContext, token);
        return new MediaController(mContext, token);
    }
    }
}
}
+5 −0
Original line number Original line Diff line number Diff line
@@ -509,6 +509,11 @@ class MediaDataManager(
     */
     */
    private fun updateState(key: String, state: PlaybackState) {
    private fun updateState(key: String, state: PlaybackState) {
        mediaEntries.get(key)?.let {
        mediaEntries.get(key)?.let {
            val token = it.token
            if (token == null) {
                if (DEBUG) Log.d(TAG, "State updated, but token was null")
                return
            }
            val actions = createActionsFromState(it.packageName,
            val actions = createActionsFromState(it.packageName,
                    mediaControllerFactory.create(it.token), UserHandle(it.userId))
                    mediaControllerFactory.create(it.token), UserHandle(it.userId))
            val data = it.copy(
            val data = it.copy(
+3 −2
Original line number Original line Diff line number Diff line
@@ -161,8 +161,9 @@ class MediaTimeoutListener @Inject constructor(
                destroyed = false
                destroyed = false
                mediaController?.unregisterCallback(this)
                mediaController?.unregisterCallback(this)
                field = value
                field = value
                mediaController = if (field.token != null) {
                val token = field.token
                    mediaControllerFactory.create(field.token)
                mediaController = if (token != null) {
                    mediaControllerFactory.create(token)
                } else {
                } else {
                    null
                    null
                }
                }
+20 −0
Original line number Original line Diff line number Diff line
@@ -978,6 +978,26 @@ class MediaDataManagerTest : SysuiTestCase() {
                anyBoolean())
                anyBoolean())
    }
    }


    @Test
    fun testPlaybackStateChange_keyHasNullToken_doesNothing() {
        // When we get an update that sets the data's token to null
        whenever(controller.metadata).thenReturn(metadataBuilder.build())
        addNotificationAndLoad()
        val data = mediaDataCaptor.value
        assertThat(data.resumption).isFalse()
        mediaDataManager.onMediaDataLoaded(KEY, null, data.copy(token = null))

        // And then get a state update
        val state = PlaybackState.Builder().build()
        val callbackCaptor = argumentCaptor<(String, PlaybackState) -> Unit>()
        verify(mediaTimeoutListener).stateCallback = capture(callbackCaptor)

        // Then no changes are made
        callbackCaptor.value.invoke(KEY, state)
        verify(listener, never()).onMediaDataLoaded(eq(KEY), any(), any(), anyBoolean(), anyInt(),
            anyBoolean())
    }

    /**
    /**
     * Helper function to add a media notification and capture the resulting MediaData
     * Helper function to add a media notification and capture the resulting MediaData
     */
     */