mirror of
https://github.com/androidx/media.git
synced 2025-05-17 12:39:52 +08:00
Remove media-session extension nullness blacklist
PiperOrigin-RevId: 249431620
This commit is contained in:
parent
10ee7d8e86
commit
f74d2294be
@ -33,6 +33,7 @@ android {
|
||||
dependencies {
|
||||
implementation project(modulePrefix + 'library-core')
|
||||
api 'androidx.media:media:1.0.1'
|
||||
compileOnly 'org.checkerframework:checker-qual:' + checkerframeworkVersion
|
||||
}
|
||||
|
||||
ext {
|
||||
|
@ -52,6 +52,7 @@ import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import org.checkerframework.checker.nullness.qual.EnsuresNonNullIf;
|
||||
|
||||
/**
|
||||
* Connects a {@link MediaSessionCompat} to a {@link Player}.
|
||||
@ -359,7 +360,7 @@ public final class MediaSessionConnector {
|
||||
* @param extras Optional extras sent by a media controller.
|
||||
*/
|
||||
void onCustomAction(
|
||||
Player player, ControlDispatcher controlDispatcher, String action, Bundle extras);
|
||||
Player player, ControlDispatcher controlDispatcher, String action, @Nullable Bundle extras);
|
||||
|
||||
/**
|
||||
* Returns a {@link PlaybackStateCompat.CustomAction} which will be published to the media
|
||||
@ -676,6 +677,7 @@ public final class MediaSessionConnector {
|
||||
*/
|
||||
public final void invalidateMediaSessionPlaybackState() {
|
||||
PlaybackStateCompat.Builder builder = new PlaybackStateCompat.Builder();
|
||||
Player player = this.player;
|
||||
if (player == null) {
|
||||
builder.setActions(buildPrepareActions()).setState(PlaybackStateCompat.STATE_NONE, 0, 0, 0);
|
||||
mediaSession.setPlaybackState(builder.build());
|
||||
@ -749,8 +751,8 @@ public final class MediaSessionConnector {
|
||||
*
|
||||
* @param commandReceiver The command receiver to register.
|
||||
*/
|
||||
public void registerCustomCommandReceiver(CommandReceiver commandReceiver) {
|
||||
if (!customCommandReceivers.contains(commandReceiver)) {
|
||||
public void registerCustomCommandReceiver(@Nullable CommandReceiver commandReceiver) {
|
||||
if (commandReceiver != null && !customCommandReceivers.contains(commandReceiver)) {
|
||||
customCommandReceivers.add(commandReceiver);
|
||||
}
|
||||
}
|
||||
@ -760,19 +762,23 @@ public final class MediaSessionConnector {
|
||||
*
|
||||
* @param commandReceiver The command receiver to unregister.
|
||||
*/
|
||||
public void unregisterCustomCommandReceiver(CommandReceiver commandReceiver) {
|
||||
public void unregisterCustomCommandReceiver(@Nullable CommandReceiver commandReceiver) {
|
||||
if (commandReceiver != null) {
|
||||
customCommandReceivers.remove(commandReceiver);
|
||||
}
|
||||
}
|
||||
|
||||
private void registerCommandReceiver(CommandReceiver commandReceiver) {
|
||||
if (!commandReceivers.contains(commandReceiver)) {
|
||||
private void registerCommandReceiver(@Nullable CommandReceiver commandReceiver) {
|
||||
if (commandReceiver != null && !commandReceivers.contains(commandReceiver)) {
|
||||
commandReceivers.add(commandReceiver);
|
||||
}
|
||||
}
|
||||
|
||||
private void unregisterCommandReceiver(CommandReceiver commandReceiver) {
|
||||
private void unregisterCommandReceiver(@Nullable CommandReceiver commandReceiver) {
|
||||
if (commandReceiver != null) {
|
||||
commandReceivers.remove(commandReceiver);
|
||||
}
|
||||
}
|
||||
|
||||
private long buildPrepareActions() {
|
||||
return playbackPreparer == null
|
||||
@ -829,29 +835,43 @@ public final class MediaSessionConnector {
|
||||
}
|
||||
}
|
||||
|
||||
@EnsuresNonNullIf(result = true, expression = "player")
|
||||
private boolean canDispatchPlaybackAction(long action) {
|
||||
return player != null && (enabledPlaybackActions & action) != 0;
|
||||
}
|
||||
|
||||
@EnsuresNonNullIf(result = true, expression = "playbackPreparer")
|
||||
private boolean canDispatchToPlaybackPreparer(long action) {
|
||||
return playbackPreparer != null
|
||||
&& (playbackPreparer.getSupportedPrepareActions() & action) != 0;
|
||||
}
|
||||
|
||||
@EnsuresNonNullIf(
|
||||
result = true,
|
||||
expression = {"player", "queueNavigator"})
|
||||
private boolean canDispatchToQueueNavigator(long action) {
|
||||
return player != null
|
||||
&& queueNavigator != null
|
||||
&& (queueNavigator.getSupportedQueueNavigatorActions(player) & action) != 0;
|
||||
}
|
||||
|
||||
@EnsuresNonNullIf(
|
||||
result = true,
|
||||
expression = {"player", "ratingCallback"})
|
||||
private boolean canDispatchSetRating() {
|
||||
return player != null && ratingCallback != null;
|
||||
}
|
||||
|
||||
@EnsuresNonNullIf(
|
||||
result = true,
|
||||
expression = {"player", "queueEditor"})
|
||||
private boolean canDispatchQueueEdit() {
|
||||
return player != null && queueEditor != null;
|
||||
}
|
||||
|
||||
@EnsuresNonNullIf(
|
||||
result = true,
|
||||
expression = {"player", "mediaButtonEventHandler"})
|
||||
private boolean canDispatchMediaButtonEvent() {
|
||||
return player != null && mediaButtonEventHandler != null;
|
||||
}
|
||||
@ -941,38 +961,40 @@ public final class MediaSessionConnector {
|
||||
}
|
||||
}
|
||||
}
|
||||
if (description.getTitle() != null) {
|
||||
String title = String.valueOf(description.getTitle());
|
||||
builder.putString(MediaMetadataCompat.METADATA_KEY_TITLE, title);
|
||||
builder.putString(MediaMetadataCompat.METADATA_KEY_DISPLAY_TITLE, title);
|
||||
CharSequence title = description.getTitle();
|
||||
if (title != null) {
|
||||
String titleString = String.valueOf(title);
|
||||
builder.putString(MediaMetadataCompat.METADATA_KEY_TITLE, titleString);
|
||||
builder.putString(MediaMetadataCompat.METADATA_KEY_DISPLAY_TITLE, titleString);
|
||||
}
|
||||
if (description.getSubtitle() != null) {
|
||||
CharSequence subtitle = description.getSubtitle();
|
||||
if (subtitle != null) {
|
||||
builder.putString(
|
||||
MediaMetadataCompat.METADATA_KEY_DISPLAY_SUBTITLE,
|
||||
String.valueOf(description.getSubtitle()));
|
||||
MediaMetadataCompat.METADATA_KEY_DISPLAY_SUBTITLE, String.valueOf(subtitle));
|
||||
}
|
||||
if (description.getDescription() != null) {
|
||||
CharSequence displayDescription = description.getDescription();
|
||||
if (displayDescription != null) {
|
||||
builder.putString(
|
||||
MediaMetadataCompat.METADATA_KEY_DISPLAY_DESCRIPTION,
|
||||
String.valueOf(description.getDescription()));
|
||||
String.valueOf(displayDescription));
|
||||
}
|
||||
if (description.getIconBitmap() != null) {
|
||||
builder.putBitmap(
|
||||
MediaMetadataCompat.METADATA_KEY_DISPLAY_ICON, description.getIconBitmap());
|
||||
Bitmap iconBitmap = description.getIconBitmap();
|
||||
if (iconBitmap != null) {
|
||||
builder.putBitmap(MediaMetadataCompat.METADATA_KEY_DISPLAY_ICON, iconBitmap);
|
||||
}
|
||||
if (description.getIconUri() != null) {
|
||||
Uri iconUri = description.getIconUri();
|
||||
if (iconUri != null) {
|
||||
builder.putString(
|
||||
MediaMetadataCompat.METADATA_KEY_DISPLAY_ICON_URI,
|
||||
String.valueOf(description.getIconUri()));
|
||||
MediaMetadataCompat.METADATA_KEY_DISPLAY_ICON_URI, String.valueOf(iconUri));
|
||||
}
|
||||
if (description.getMediaId() != null) {
|
||||
builder.putString(
|
||||
MediaMetadataCompat.METADATA_KEY_MEDIA_ID, description.getMediaId());
|
||||
String mediaId = description.getMediaId();
|
||||
if (mediaId != null) {
|
||||
builder.putString(MediaMetadataCompat.METADATA_KEY_MEDIA_ID, mediaId);
|
||||
}
|
||||
if (description.getMediaUri() != null) {
|
||||
Uri mediaUri = description.getMediaUri();
|
||||
if (mediaUri != null) {
|
||||
builder.putString(
|
||||
MediaMetadataCompat.METADATA_KEY_MEDIA_URI,
|
||||
String.valueOf(description.getMediaUri()));
|
||||
MediaMetadataCompat.METADATA_KEY_MEDIA_URI, String.valueOf(mediaUri));
|
||||
}
|
||||
break;
|
||||
}
|
||||
@ -993,6 +1015,7 @@ public final class MediaSessionConnector {
|
||||
@Override
|
||||
public void onTimelineChanged(
|
||||
Timeline timeline, @Nullable Object manifest, @Player.TimelineChangeReason int reason) {
|
||||
Player player = Assertions.checkNotNull(MediaSessionConnector.this.player);
|
||||
int windowCount = player.getCurrentTimeline().getWindowCount();
|
||||
int windowIndex = player.getCurrentWindowIndex();
|
||||
if (queueNavigator != null) {
|
||||
@ -1035,6 +1058,7 @@ public final class MediaSessionConnector {
|
||||
|
||||
@Override
|
||||
public void onPositionDiscontinuity(@Player.DiscontinuityReason int reason) {
|
||||
Player player = Assertions.checkNotNull(MediaSessionConnector.this.player);
|
||||
if (currentWindowIndex != player.getCurrentWindowIndex()) {
|
||||
if (queueNavigator != null) {
|
||||
queueNavigator.onCurrentWindowIndexChanged(player);
|
||||
|
@ -17,6 +17,7 @@ package com.google.android.exoplayer2.ext.mediasession;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.Bundle;
|
||||
import androidx.annotation.Nullable;
|
||||
import android.support.v4.media.session.PlaybackStateCompat;
|
||||
import com.google.android.exoplayer2.ControlDispatcher;
|
||||
import com.google.android.exoplayer2.Player;
|
||||
@ -65,7 +66,7 @@ public final class RepeatModeActionProvider implements MediaSessionConnector.Cus
|
||||
|
||||
@Override
|
||||
public void onCustomAction(
|
||||
Player player, ControlDispatcher controlDispatcher, String action, Bundle extras) {
|
||||
Player player, ControlDispatcher controlDispatcher, String action, @Nullable Bundle extras) {
|
||||
int mode = player.getRepeatMode();
|
||||
int proposedMode = RepeatModeUtil.getNextRepeatMode(mode, repeatToggleModes);
|
||||
if (mode != proposedMode) {
|
||||
|
@ -60,7 +60,6 @@ android {
|
||||
dependencies {
|
||||
implementation 'androidx.annotation:annotation:1.0.2'
|
||||
compileOnly 'org.checkerframework:checker-qual:' + checkerframeworkVersion
|
||||
compileOnly 'org.checkerframework:checker-compat-qual:' + checkerframeworkVersion
|
||||
androidTestImplementation 'androidx.test:runner:' + androidXTestVersion
|
||||
androidTestImplementation 'androidx.test.ext:junit:' + androidXTestVersion
|
||||
androidTestImplementation 'com.google.truth:truth:' + truthVersion
|
||||
|
Loading…
x
Reference in New Issue
Block a user