Loading packages/SystemUI/src/com/android/systemui/media/MediaControllerFactory.java +2 −1 Original line number Diff line number Diff line Loading @@ -16,6 +16,7 @@ package com.android.systemui.media; import android.annotation.NonNull; import android.content.Context; import android.media.session.MediaController; import android.media.session.MediaSession; Loading @@ -39,7 +40,7 @@ public class MediaControllerFactory { * * @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); } } packages/SystemUI/src/com/android/systemui/media/MediaDataManager.kt +5 −0 Original line number Diff line number Diff line Loading @@ -509,6 +509,11 @@ class MediaDataManager( */ private fun updateState(key: String, state: PlaybackState) { 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, mediaControllerFactory.create(it.token), UserHandle(it.userId)) val data = it.copy( Loading packages/SystemUI/src/com/android/systemui/media/MediaTimeoutListener.kt +3 −2 Original line number Diff line number Diff line Loading @@ -161,8 +161,9 @@ class MediaTimeoutListener @Inject constructor( destroyed = false mediaController?.unregisterCallback(this) field = value mediaController = if (field.token != null) { mediaControllerFactory.create(field.token) val token = field.token mediaController = if (token != null) { mediaControllerFactory.create(token) } else { null } Loading packages/SystemUI/tests/src/com/android/systemui/media/MediaDataManagerTest.kt +20 −0 Original line number Diff line number Diff line Loading @@ -978,6 +978,26 @@ class MediaDataManagerTest : SysuiTestCase() { 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 */ Loading Loading
packages/SystemUI/src/com/android/systemui/media/MediaControllerFactory.java +2 −1 Original line number Diff line number Diff line Loading @@ -16,6 +16,7 @@ package com.android.systemui.media; import android.annotation.NonNull; import android.content.Context; import android.media.session.MediaController; import android.media.session.MediaSession; Loading @@ -39,7 +40,7 @@ public class MediaControllerFactory { * * @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); } }
packages/SystemUI/src/com/android/systemui/media/MediaDataManager.kt +5 −0 Original line number Diff line number Diff line Loading @@ -509,6 +509,11 @@ class MediaDataManager( */ private fun updateState(key: String, state: PlaybackState) { 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, mediaControllerFactory.create(it.token), UserHandle(it.userId)) val data = it.copy( Loading
packages/SystemUI/src/com/android/systemui/media/MediaTimeoutListener.kt +3 −2 Original line number Diff line number Diff line Loading @@ -161,8 +161,9 @@ class MediaTimeoutListener @Inject constructor( destroyed = false mediaController?.unregisterCallback(this) field = value mediaController = if (field.token != null) { mediaControllerFactory.create(field.token) val token = field.token mediaController = if (token != null) { mediaControllerFactory.create(token) } else { null } Loading
packages/SystemUI/tests/src/com/android/systemui/media/MediaDataManagerTest.kt +20 −0 Original line number Diff line number Diff line Loading @@ -978,6 +978,26 @@ class MediaDataManagerTest : SysuiTestCase() { 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 */ Loading