Remove unneeded @Nullable from PlayerWrapper.legacyExtras

All values passed in via the constructor or setLegacyExtras
are guaranteed to be non-null.

PiperOrigin-RevId: 687245475
This commit is contained in:
tonihei 2024-10-18 04:01:32 -07:00 committed by Copybara-Service
parent 4d711050bb
commit 5fffe03312
2 changed files with 9 additions and 15 deletions

View File

@ -85,7 +85,7 @@ import java.util.List;
private final boolean playIfSuppressed; private final boolean playIfSuppressed;
@Nullable private LegacyError legacyError; @Nullable private LegacyError legacyError;
@Nullable private Bundle legacyExtras; private Bundle legacyExtras;
private ImmutableList<CommandButton> customLayout; private ImmutableList<CommandButton> customLayout;
private ImmutableList<CommandButton> mediaButtonPreferences; private ImmutableList<CommandButton> mediaButtonPreferences;
private SessionCommands availableSessionCommands; private SessionCommands availableSessionCommands;
@ -98,7 +98,7 @@ import java.util.List;
ImmutableList<CommandButton> mediaButtonPreferences, ImmutableList<CommandButton> mediaButtonPreferences,
SessionCommands availableSessionCommands, SessionCommands availableSessionCommands,
Commands availablePlayerCommands, Commands availablePlayerCommands,
@Nullable Bundle legacyExtras) { Bundle legacyExtras) {
super(player); super(player);
this.playIfSuppressed = playIfSuppressed; this.playIfSuppressed = playIfSuppressed;
this.customLayout = customLayout; this.customLayout = customLayout;
@ -138,15 +138,12 @@ import java.util.List;
return mediaButtonPreferences; return mediaButtonPreferences;
} }
public void setLegacyExtras(@Nullable Bundle extras) { public void setLegacyExtras(Bundle extras) {
if (extras != null) { checkArgument(!extras.containsKey(EXTRAS_KEY_PLAYBACK_SPEED_COMPAT));
checkArgument(!extras.containsKey(EXTRAS_KEY_PLAYBACK_SPEED_COMPAT)); checkArgument(!extras.containsKey(EXTRAS_KEY_MEDIA_ID_COMPAT));
checkArgument(!extras.containsKey(EXTRAS_KEY_MEDIA_ID_COMPAT));
}
this.legacyExtras = extras; this.legacyExtras = extras;
} }
@Nullable
public Bundle getLegacyExtras() { public Bundle getLegacyExtras() {
return legacyExtras; return legacyExtras;
} }
@ -1020,9 +1017,7 @@ import java.util.List;
LegacyError legacyError = this.legacyError; LegacyError legacyError = this.legacyError;
if (legacyError != null && legacyError.isFatal) { if (legacyError != null && legacyError.isFatal) {
Bundle extras = new Bundle(legacyError.extras); Bundle extras = new Bundle(legacyError.extras);
if (legacyExtras != null) { extras.putAll(legacyExtras);
extras.putAll(legacyExtras);
}
return new PlaybackStateCompat.Builder() return new PlaybackStateCompat.Builder()
.setState( .setState(
PlaybackStateCompat.STATE_ERROR, PlaybackStateCompat.STATE_ERROR,
@ -1052,9 +1047,7 @@ import java.util.List;
float playbackSpeed = getPlaybackParameters().speed; float playbackSpeed = getPlaybackParameters().speed;
float sessionPlaybackSpeed = isPlaying() ? playbackSpeed : 0f; float sessionPlaybackSpeed = isPlaying() ? playbackSpeed : 0f;
Bundle extras = legacyError != null ? new Bundle(legacyError.extras) : new Bundle(); Bundle extras = legacyError != null ? new Bundle(legacyError.extras) : new Bundle();
if (legacyExtras != null && !legacyExtras.isEmpty()) { extras.putAll(legacyExtras);
extras.putAll(legacyExtras);
}
extras.putFloat(EXTRAS_KEY_PLAYBACK_SPEED_COMPAT, playbackSpeed); extras.putFloat(EXTRAS_KEY_PLAYBACK_SPEED_COMPAT, playbackSpeed);
@Nullable MediaItem currentMediaItem = getCurrentMediaItemWithCommandCheck(); @Nullable MediaItem currentMediaItem = getCurrentMediaItemWithCommandCheck();
if (currentMediaItem != null && !MediaItem.DEFAULT_MEDIA_ID.equals(currentMediaItem.mediaId)) { if (currentMediaItem != null && !MediaItem.DEFAULT_MEDIA_ID.equals(currentMediaItem.mediaId)) {

View File

@ -19,6 +19,7 @@ import static com.google.common.truth.Truth.assertThat;
import static org.mockito.ArgumentMatchers.anyInt; import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.Mockito.when; import static org.mockito.Mockito.when;
import android.os.Bundle;
import android.os.Looper; import android.os.Looper;
import androidx.media3.common.Player; import androidx.media3.common.Player;
import androidx.test.ext.junit.runners.AndroidJUnit4; import androidx.test.ext.junit.runners.AndroidJUnit4;
@ -51,7 +52,7 @@ public class PlayerWrapperTest {
/* mediaButtonPreferences= */ ImmutableList.of(), /* mediaButtonPreferences= */ ImmutableList.of(),
SessionCommands.EMPTY, SessionCommands.EMPTY,
Player.Commands.EMPTY, Player.Commands.EMPTY,
/* legacyExtras= */ null); /* legacyExtras= */ Bundle.EMPTY);
when(player.isCommandAvailable(anyInt())).thenReturn(true); when(player.isCommandAvailable(anyInt())).thenReturn(true);
when(player.getApplicationLooper()).thenReturn(Looper.myLooper()); when(player.getApplicationLooper()).thenReturn(Looper.myLooper());
} }