Post-submit fixes for eed5d957d8.

One wrong return value, a useless assignment, unusual visibility of private
class fields and some nullability issues.

PiperOrigin-RevId: 246282995
This commit is contained in:
tonihei 2019-05-02 10:37:31 +01:00 committed by Oliver Woodman
parent 9f9cf316bd
commit 241ce2df49
2 changed files with 23 additions and 15 deletions

View File

@ -31,6 +31,7 @@ import android.os.Handler;
import android.os.HandlerThread; import android.os.HandlerThread;
import android.os.Looper; import android.os.Looper;
import android.os.Message; import android.os.Message;
import androidx.annotation.CheckResult;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import com.google.android.exoplayer2.C; import com.google.android.exoplayer2.C;
import com.google.android.exoplayer2.database.DatabaseProvider; import com.google.android.exoplayer2.database.DatabaseProvider;
@ -192,12 +193,9 @@ public final class DownloadManager {
downloads = Collections.emptyList(); downloads = Collections.emptyList();
listeners = new CopyOnWriteArraySet<>(); listeners = new CopyOnWriteArraySet<>();
requirementsListener = this::onRequirementsStateChanged; @SuppressWarnings("methodref.receiver.bound.invalid")
requirementsWatcher = Handler mainHandler = Util.createHandler(this::handleMainMessage);
new RequirementsWatcher(context, requirementsListener, DEFAULT_REQUIREMENTS); this.mainHandler = mainHandler;
notMetRequirements = requirementsWatcher.start();
mainHandler = new Handler(Util.getLooper(), this::handleMainMessage);
HandlerThread internalThread = new HandlerThread("DownloadManager file i/o"); HandlerThread internalThread = new HandlerThread("DownloadManager file i/o");
internalThread.start(); internalThread.start();
internalHandler = internalHandler =
@ -210,6 +208,13 @@ public final class DownloadManager {
minRetryCount, minRetryCount,
downloadsPaused); downloadsPaused);
@SuppressWarnings("methodref.receiver.bound.invalid")
RequirementsWatcher.Listener requirementsListener = this::onRequirementsStateChanged;
this.requirementsListener = requirementsListener;
requirementsWatcher =
new RequirementsWatcher(context, requirementsListener, DEFAULT_REQUIREMENTS);
notMetRequirements = requirementsWatcher.start();
pendingMessages = 1; pendingMessages = 1;
internalHandler internalHandler
.obtainMessage(MSG_INITIALIZE, notMetRequirements, /* unused */ 0) .obtainMessage(MSG_INITIALIZE, notMetRequirements, /* unused */ 0)
@ -822,7 +827,7 @@ public final class DownloadManager {
activeTask = syncQueuedDownload(activeTask, download); activeTask = syncQueuedDownload(activeTask, download);
break; break;
case STATE_DOWNLOADING: case STATE_DOWNLOADING:
activeTask = Assertions.checkNotNull(activeTask); Assertions.checkNotNull(activeTask);
syncDownloadingDownload(activeTask, download, accumulatingDownloadTaskCount); syncDownloadingDownload(activeTask, download, accumulatingDownloadTaskCount);
break; break;
case STATE_REMOVING: case STATE_REMOVING:
@ -848,6 +853,8 @@ public final class DownloadManager {
} }
} }
@Nullable
@CheckResult
private Task syncQueuedDownload(@Nullable Task activeTask, Download download) { private Task syncQueuedDownload(@Nullable Task activeTask, Download download) {
if (activeTask != null) { if (activeTask != null) {
// We have a task, which must be a download task. If the download state is queued we need to // We have a task, which must be a download task. If the download state is queued we need to
@ -919,7 +926,8 @@ public final class DownloadManager {
private void onContentLengthChanged(Task task) { private void onContentLengthChanged(Task task) {
String downloadId = task.request.id; String downloadId = task.request.id;
long contentLength = task.contentLength; long contentLength = task.contentLength;
Download download = getDownload(downloadId, /* loadFromIndex= */ false); Download download =
Assertions.checkNotNull(getDownload(downloadId, /* loadFromIndex= */ false));
if (contentLength == download.contentLength || contentLength == C.LENGTH_UNSET) { if (contentLength == download.contentLength || contentLength == C.LENGTH_UNSET) {
return; return;
} }
@ -1125,7 +1133,7 @@ public final class DownloadManager {
private volatile InternalHandler internalHandler; private volatile InternalHandler internalHandler;
private volatile boolean isCanceled; private volatile boolean isCanceled;
private Throwable finalError; @Nullable private Throwable finalError;
private long contentLength; private long contentLength;
@ -1145,6 +1153,7 @@ public final class DownloadManager {
contentLength = C.LENGTH_UNSET; contentLength = C.LENGTH_UNSET;
} }
@SuppressWarnings("nullness:assignment.type.incompatible")
public void cancel(boolean released) { public void cancel(boolean released) {
if (released) { if (released) {
// Download threads are GC roots for as long as they're running. The time taken for // Download threads are GC roots for as long as they're running. The time taken for
@ -1218,10 +1227,9 @@ public final class DownloadManager {
private static final class DownloadUpdate { private static final class DownloadUpdate {
private final Download download; public final Download download;
private final boolean isRemove; public final boolean isRemove;
public final List<Download> downloads;
private final List<Download> downloads;
public DownloadUpdate(Download download, boolean isRemove, List<Download> downloads) { public DownloadUpdate(Download download, boolean isRemove, List<Download> downloads) {
this.download = download; this.download = download;

View File

@ -390,7 +390,7 @@ public final class Util {
* *
* @param dataSource The {@link DataSource} to close. * @param dataSource The {@link DataSource} to close.
*/ */
public static void closeQuietly(DataSource dataSource) { public static void closeQuietly(@Nullable DataSource dataSource) {
try { try {
if (dataSource != null) { if (dataSource != null) {
dataSource.close(); dataSource.close();
@ -406,7 +406,7 @@ public final class Util {
* *
* @param closeable The {@link Closeable} to close. * @param closeable The {@link Closeable} to close.
*/ */
public static void closeQuietly(Closeable closeable) { public static void closeQuietly(@Nullable Closeable closeable) {
try { try {
if (closeable != null) { if (closeable != null) {
closeable.close(); closeable.close();