Fix some Android Studio nullness warning created by new @NonNullApi.

PiperOrigin-RevId: 261888086
This commit is contained in:
tonihei 2019-08-06 12:46:39 +01:00 committed by Toni
parent 3b9288b805
commit b0330edc0b
8 changed files with 35 additions and 33 deletions

View File

@ -558,7 +558,7 @@ public final class MediaSessionConnector {
* *
* @param queueNavigator The queue navigator. * @param queueNavigator The queue navigator.
*/ */
public void setQueueNavigator(QueueNavigator queueNavigator) { public void setQueueNavigator(@Nullable QueueNavigator queueNavigator) {
if (this.queueNavigator != queueNavigator) { if (this.queueNavigator != queueNavigator) {
unregisterCommandReceiver(this.queueNavigator); unregisterCommandReceiver(this.queueNavigator);
this.queueNavigator = queueNavigator; this.queueNavigator = queueNavigator;
@ -571,7 +571,7 @@ public final class MediaSessionConnector {
* *
* @param queueEditor The queue editor. * @param queueEditor The queue editor.
*/ */
public void setQueueEditor(QueueEditor queueEditor) { public void setQueueEditor(@Nullable QueueEditor queueEditor) {
if (this.queueEditor != queueEditor) { if (this.queueEditor != queueEditor) {
unregisterCommandReceiver(this.queueEditor); unregisterCommandReceiver(this.queueEditor);
this.queueEditor = queueEditor; this.queueEditor = queueEditor;
@ -673,7 +673,7 @@ public final class MediaSessionConnector {
mediaMetadataProvider != null && player != null mediaMetadataProvider != null && player != null
? mediaMetadataProvider.getMetadata(player) ? mediaMetadataProvider.getMetadata(player)
: METADATA_EMPTY; : METADATA_EMPTY;
mediaSession.setMetadata(metadata != null ? metadata : METADATA_EMPTY); mediaSession.setMetadata(metadata);
} }
/** /**
@ -684,7 +684,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; @Nullable 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());
@ -693,6 +693,7 @@ public final class MediaSessionConnector {
Map<String, CustomActionProvider> currentActions = new HashMap<>(); Map<String, CustomActionProvider> currentActions = new HashMap<>();
for (CustomActionProvider customActionProvider : customActionProviders) { for (CustomActionProvider customActionProvider : customActionProviders) {
@Nullable
PlaybackStateCompat.CustomAction customAction = customActionProvider.getCustomAction(player); PlaybackStateCompat.CustomAction customAction = customActionProvider.getCustomAction(player);
if (customAction != null) { if (customAction != null) {
currentActions.put(customAction.getAction(), customActionProvider); currentActions.put(customAction.getAction(), customActionProvider);
@ -703,6 +704,7 @@ public final class MediaSessionConnector {
int playbackState = player.getPlaybackState(); int playbackState = player.getPlaybackState();
Bundle extras = new Bundle(); Bundle extras = new Bundle();
@Nullable
ExoPlaybackException playbackError = ExoPlaybackException playbackError =
playbackState == Player.STATE_IDLE ? player.getPlaybackError() : null; playbackState == Player.STATE_IDLE ? player.getPlaybackError() : null;
boolean reportError = playbackError != null || customError != null; boolean reportError = playbackError != null || customError != null;
@ -949,10 +951,10 @@ public final class MediaSessionConnector {
MediaSessionCompat.QueueItem queueItem = queue.get(i); MediaSessionCompat.QueueItem queueItem = queue.get(i);
if (queueItem.getQueueId() == activeQueueItemId) { if (queueItem.getQueueId() == activeQueueItemId) {
MediaDescriptionCompat description = queueItem.getDescription(); MediaDescriptionCompat description = queueItem.getDescription();
Bundle extras = description.getExtras(); @Nullable Bundle extras = description.getExtras();
if (extras != null) { if (extras != null) {
for (String key : extras.keySet()) { for (String key : extras.keySet()) {
Object value = extras.get(key); @Nullable Object value = extras.get(key);
if (value instanceof String) { if (value instanceof String) {
builder.putString(metadataExtrasPrefix + key, (String) value); builder.putString(metadataExtrasPrefix + key, (String) value);
} else if (value instanceof CharSequence) { } else if (value instanceof CharSequence) {
@ -968,37 +970,37 @@ public final class MediaSessionConnector {
} }
} }
} }
CharSequence title = description.getTitle(); @Nullable CharSequence title = description.getTitle();
if (title != null) { if (title != null) {
String titleString = String.valueOf(title); String titleString = String.valueOf(title);
builder.putString(MediaMetadataCompat.METADATA_KEY_TITLE, titleString); builder.putString(MediaMetadataCompat.METADATA_KEY_TITLE, titleString);
builder.putString(MediaMetadataCompat.METADATA_KEY_DISPLAY_TITLE, titleString); builder.putString(MediaMetadataCompat.METADATA_KEY_DISPLAY_TITLE, titleString);
} }
CharSequence subtitle = description.getSubtitle(); @Nullable CharSequence subtitle = description.getSubtitle();
if (subtitle != null) { if (subtitle != null) {
builder.putString( builder.putString(
MediaMetadataCompat.METADATA_KEY_DISPLAY_SUBTITLE, String.valueOf(subtitle)); MediaMetadataCompat.METADATA_KEY_DISPLAY_SUBTITLE, String.valueOf(subtitle));
} }
CharSequence displayDescription = description.getDescription(); @Nullable CharSequence displayDescription = description.getDescription();
if (displayDescription != null) { if (displayDescription != null) {
builder.putString( builder.putString(
MediaMetadataCompat.METADATA_KEY_DISPLAY_DESCRIPTION, MediaMetadataCompat.METADATA_KEY_DISPLAY_DESCRIPTION,
String.valueOf(displayDescription)); String.valueOf(displayDescription));
} }
Bitmap iconBitmap = description.getIconBitmap(); @Nullable Bitmap iconBitmap = description.getIconBitmap();
if (iconBitmap != null) { if (iconBitmap != null) {
builder.putBitmap(MediaMetadataCompat.METADATA_KEY_DISPLAY_ICON, iconBitmap); builder.putBitmap(MediaMetadataCompat.METADATA_KEY_DISPLAY_ICON, iconBitmap);
} }
Uri iconUri = description.getIconUri(); @Nullable Uri iconUri = description.getIconUri();
if (iconUri != null) { if (iconUri != null) {
builder.putString( builder.putString(
MediaMetadataCompat.METADATA_KEY_DISPLAY_ICON_URI, String.valueOf(iconUri)); MediaMetadataCompat.METADATA_KEY_DISPLAY_ICON_URI, String.valueOf(iconUri));
} }
String mediaId = description.getMediaId(); @Nullable String mediaId = description.getMediaId();
if (mediaId != null) { if (mediaId != null) {
builder.putString(MediaMetadataCompat.METADATA_KEY_MEDIA_ID, mediaId); builder.putString(MediaMetadataCompat.METADATA_KEY_MEDIA_ID, mediaId);
} }
Uri mediaUri = description.getMediaUri(); @Nullable Uri mediaUri = description.getMediaUri();
if (mediaUri != null) { if (mediaUri != null) {
builder.putString( builder.putString(
MediaMetadataCompat.METADATA_KEY_MEDIA_URI, String.valueOf(mediaUri)); MediaMetadataCompat.METADATA_KEY_MEDIA_URI, String.valueOf(mediaUri));

View File

@ -166,7 +166,7 @@ public final class TimelineQueueEditor
@Override @Override
public void onAddQueueItem(Player player, MediaDescriptionCompat description, int index) { public void onAddQueueItem(Player player, MediaDescriptionCompat description, int index) {
MediaSource mediaSource = sourceFactory.createMediaSource(description); @Nullable MediaSource mediaSource = sourceFactory.createMediaSource(description);
if (mediaSource != null) { if (mediaSource != null) {
queueDataAdapter.add(index, description); queueDataAdapter.add(index, description);
queueMediaSource.addMediaSource(index, mediaSource); queueMediaSource.addMediaSource(index, mediaSource);

View File

@ -68,7 +68,7 @@ import java.util.List;
if (!exists()) { if (!exists()) {
return new DownloadRequest[0]; return new DownloadRequest[0];
} }
InputStream inputStream = null; @Nullable InputStream inputStream = null;
try { try {
inputStream = atomicFile.openRead(); inputStream = atomicFile.openRead();
DataInputStream dataInputStream = new DataInputStream(inputStream); DataInputStream dataInputStream = new DataInputStream(inputStream);
@ -99,7 +99,7 @@ import java.util.List;
boolean isRemoveAction = input.readBoolean(); boolean isRemoveAction = input.readBoolean();
int dataLength = input.readInt(); int dataLength = input.readInt();
byte[] data; @Nullable byte[] data;
if (dataLength != 0) { if (dataLength != 0) {
data = new byte[dataLength]; data = new byte[dataLength];
input.readFully(data); input.readFully(data);
@ -123,7 +123,7 @@ import java.util.List;
&& (DownloadRequest.TYPE_DASH.equals(type) && (DownloadRequest.TYPE_DASH.equals(type)
|| DownloadRequest.TYPE_HLS.equals(type) || DownloadRequest.TYPE_HLS.equals(type)
|| DownloadRequest.TYPE_SS.equals(type)); || DownloadRequest.TYPE_SS.equals(type));
String customCacheKey = null; @Nullable String customCacheKey = null;
if (!isLegacySegmented) { if (!isLegacySegmented) {
customCacheKey = input.readBoolean() ? input.readUTF() : null; customCacheKey = input.readBoolean() ? input.readUTF() : null;
} }

View File

@ -97,7 +97,7 @@ public final class ActionFileUpgradeUtil {
boolean addNewDownloadAsCompleted, boolean addNewDownloadAsCompleted,
long nowMs) long nowMs)
throws IOException { throws IOException {
Download download = downloadIndex.getDownload(request.id); @Nullable Download download = downloadIndex.getDownload(request.id);
if (download != null) { if (download != null) {
download = DownloadManager.mergeRequest(download, request, download.stopReason, nowMs); download = DownloadManager.mergeRequest(download, request, download.stopReason, nowMs);
} else { } else {

View File

@ -390,7 +390,7 @@ public final class DownloadHelper {
*/ */
public static MediaSource createMediaSource( public static MediaSource createMediaSource(
DownloadRequest downloadRequest, DataSource.Factory dataSourceFactory) { DownloadRequest downloadRequest, DataSource.Factory dataSourceFactory) {
Constructor<? extends MediaSourceFactory> constructor; @Nullable Constructor<? extends MediaSourceFactory> constructor;
switch (downloadRequest.type) { switch (downloadRequest.type) {
case DownloadRequest.TYPE_DASH: case DownloadRequest.TYPE_DASH:
constructor = DASH_FACTORY_CONSTRUCTOR; constructor = DASH_FACTORY_CONSTRUCTOR;
@ -808,7 +808,7 @@ public final class DownloadHelper {
new MediaPeriodId(mediaPreparer.timeline.getUidOfPeriod(periodIndex)), new MediaPeriodId(mediaPreparer.timeline.getUidOfPeriod(periodIndex)),
mediaPreparer.timeline); mediaPreparer.timeline);
for (int i = 0; i < trackSelectorResult.length; i++) { for (int i = 0; i < trackSelectorResult.length; i++) {
TrackSelection newSelection = trackSelectorResult.selections.get(i); @Nullable TrackSelection newSelection = trackSelectorResult.selections.get(i);
if (newSelection == null) { if (newSelection == null) {
continue; continue;
} }

View File

@ -731,7 +731,7 @@ public final class DownloadManager {
Log.e(TAG, "Failed to set manual stop reason", e); Log.e(TAG, "Failed to set manual stop reason", e);
} }
} else { } else {
Download download = getDownload(id, /* loadFromIndex= */ false); @Nullable Download download = getDownload(id, /* loadFromIndex= */ false);
if (download != null) { if (download != null) {
setStopReason(download, stopReason); setStopReason(download, stopReason);
} else { } else {
@ -779,7 +779,7 @@ public final class DownloadManager {
} }
private void addDownload(DownloadRequest request, int stopReason) { private void addDownload(DownloadRequest request, int stopReason) {
Download download = getDownload(request.id, /* loadFromIndex= */ true); @Nullable Download download = getDownload(request.id, /* loadFromIndex= */ true);
long nowMs = System.currentTimeMillis(); long nowMs = System.currentTimeMillis();
if (download != null) { if (download != null) {
putDownload(mergeRequest(download, request, stopReason, nowMs)); putDownload(mergeRequest(download, request, stopReason, nowMs));
@ -798,7 +798,7 @@ public final class DownloadManager {
} }
private void removeDownload(String id) { private void removeDownload(String id) {
Download download = getDownload(id, /* loadFromIndex= */ true); @Nullable Download download = getDownload(id, /* loadFromIndex= */ true);
if (download == null) { if (download == null) {
Log.e(TAG, "Failed to remove nonexistent download: " + id); Log.e(TAG, "Failed to remove nonexistent download: " + id);
return; return;
@ -860,7 +860,7 @@ public final class DownloadManager {
int accumulatingDownloadTaskCount = 0; int accumulatingDownloadTaskCount = 0;
for (int i = 0; i < downloads.size(); i++) { for (int i = 0; i < downloads.size(); i++) {
Download download = downloads.get(i); Download download = downloads.get(i);
Task activeTask = activeTasks.get(download.request.id); @Nullable Task activeTask = activeTasks.get(download.request.id);
switch (download.state) { switch (download.state) {
case STATE_STOPPED: case STATE_STOPPED:
syncStoppedDownload(activeTask); syncStoppedDownload(activeTask);
@ -999,7 +999,7 @@ public final class DownloadManager {
return; return;
} }
Throwable finalError = task.finalError; @Nullable Throwable finalError = task.finalError;
if (finalError != null) { if (finalError != null) {
Log.e(TAG, "Task failed: " + task.request + ", " + isRemove, finalError); Log.e(TAG, "Task failed: " + task.request + ", " + isRemove, finalError);
} }
@ -1176,7 +1176,7 @@ public final class DownloadManager {
private final boolean isRemove; private final boolean isRemove;
private final int minRetryCount; private final int minRetryCount;
private volatile InternalHandler internalHandler; @Nullable private volatile InternalHandler internalHandler;
private volatile boolean isCanceled; private volatile boolean isCanceled;
@Nullable private Throwable finalError; @Nullable private Throwable finalError;
@ -1246,7 +1246,7 @@ public final class DownloadManager {
} catch (Throwable e) { } catch (Throwable e) {
finalError = e; finalError = e;
} }
Handler internalHandler = this.internalHandler; @Nullable Handler internalHandler = this.internalHandler;
if (internalHandler != null) { if (internalHandler != null) {
internalHandler.obtainMessage(MSG_TASK_STOPPED, this).sendToTarget(); internalHandler.obtainMessage(MSG_TASK_STOPPED, this).sendToTarget();
} }
@ -1258,7 +1258,7 @@ public final class DownloadManager {
downloadProgress.percentDownloaded = percentDownloaded; downloadProgress.percentDownloaded = percentDownloaded;
if (contentLength != this.contentLength) { if (contentLength != this.contentLength) {
this.contentLength = contentLength; this.contentLength = contentLength;
Handler internalHandler = this.internalHandler; @Nullable Handler internalHandler = this.internalHandler;
if (internalHandler != null) { if (internalHandler != null) {
internalHandler.obtainMessage(MSG_CONTENT_LENGTH_CHANGED, this).sendToTarget(); internalHandler.obtainMessage(MSG_CONTENT_LENGTH_CHANGED, this).sendToTarget();
} }

View File

@ -592,8 +592,8 @@ public abstract class DownloadService extends Service {
public int onStartCommand(Intent intent, int flags, int startId) { public int onStartCommand(Intent intent, int flags, int startId) {
lastStartId = startId; lastStartId = startId;
taskRemoved = false; taskRemoved = false;
String intentAction = null; @Nullable String intentAction = null;
String contentId = null; @Nullable String contentId = null;
if (intent != null) { if (intent != null) {
intentAction = intent.getAction(); intentAction = intent.getAction();
startedInForeground |= startedInForeground |=
@ -611,7 +611,7 @@ public abstract class DownloadService extends Service {
// Do nothing. // Do nothing.
break; break;
case ACTION_ADD_DOWNLOAD: case ACTION_ADD_DOWNLOAD:
DownloadRequest downloadRequest = intent.getParcelableExtra(KEY_DOWNLOAD_REQUEST); @Nullable DownloadRequest downloadRequest = intent.getParcelableExtra(KEY_DOWNLOAD_REQUEST);
if (downloadRequest == null) { if (downloadRequest == null) {
Log.e(TAG, "Ignored ADD_DOWNLOAD: Missing " + KEY_DOWNLOAD_REQUEST + " extra"); Log.e(TAG, "Ignored ADD_DOWNLOAD: Missing " + KEY_DOWNLOAD_REQUEST + " extra");
} else { } else {
@ -644,7 +644,7 @@ public abstract class DownloadService extends Service {
} }
break; break;
case ACTION_SET_REQUIREMENTS: case ACTION_SET_REQUIREMENTS:
Requirements requirements = intent.getParcelableExtra(KEY_REQUIREMENTS); @Nullable Requirements requirements = intent.getParcelableExtra(KEY_REQUIREMENTS);
if (requirements == null) { if (requirements == null) {
Log.e(TAG, "Ignored SET_REQUIREMENTS: Missing " + KEY_REQUIREMENTS + " extra"); Log.e(TAG, "Ignored SET_REQUIREMENTS: Missing " + KEY_REQUIREMENTS + " extra");
} else { } else {

View File

@ -138,7 +138,7 @@ public abstract class SegmentDownloader<M extends FilterableManifest<M>> impleme
Collections.sort(segments); Collections.sort(segments);
// Download the segments. // Download the segments.
ProgressNotifier progressNotifier = null; @Nullable ProgressNotifier progressNotifier = null;
if (progressListener != null) { if (progressListener != null) {
progressNotifier = progressNotifier =
new ProgressNotifier( new ProgressNotifier(