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