Revert pushing download thread interruption into the Downloader implementations

Issue: #5978
PiperOrigin-RevId: 314175257
This commit is contained in:
olly 2020-06-01 20:01:58 +01:00 committed by Oliver Woodman
parent 8b89a5ed6d
commit 2f3c7cb85f
4 changed files with 5 additions and 23 deletions

View file

@ -1284,6 +1284,7 @@ public final class DownloadManager {
if (!isCanceled) {
isCanceled = true;
downloader.cancel();
interrupt();
}
}

View file

@ -50,7 +50,10 @@ public interface Downloader {
*/
void download(@Nullable ProgressListener progressListener) throws IOException;
/** Cancels the download operation and prevents future download operations from running. */
/**
* Cancels the download operation and prevents future download operations from running. The caller
* should also interrupt the downloading thread immediately after calling this method.
*/
void cancel();
/** Removes the content. */

View file

@ -22,7 +22,6 @@ import com.google.android.exoplayer2.MediaItem;
import com.google.android.exoplayer2.upstream.DataSpec;
import com.google.android.exoplayer2.upstream.cache.CacheDataSource;
import com.google.android.exoplayer2.upstream.cache.CacheWriter;
import com.google.android.exoplayer2.upstream.cache.CacheWriter.ProgressListener;
import com.google.android.exoplayer2.util.Assertions;
import com.google.android.exoplayer2.util.PriorityTaskManager;
import com.google.android.exoplayer2.util.PriorityTaskManager.PriorityTooLowException;
@ -37,8 +36,6 @@ public final class ProgressiveDownloader implements Downloader {
private final CacheDataSource dataSource;
private final AtomicBoolean isCanceled;
@Nullable private volatile Thread downloadThread;
/** @deprecated Use {@link #ProgressiveDownloader(MediaItem, CacheDataSource.Factory)} instead. */
@SuppressWarnings("deprecation")
@Deprecated
@ -100,11 +97,6 @@ public final class ProgressiveDownloader implements Downloader {
@Override
public void download(@Nullable ProgressListener progressListener) throws IOException {
downloadThread = Thread.currentThread();
if (isCanceled.get()) {
return;
}
CacheWriter cacheWriter =
new CacheWriter(
dataSource,
@ -143,10 +135,6 @@ public final class ProgressiveDownloader implements Downloader {
@Override
public void cancel() {
isCanceled.set(true);
@Nullable Thread downloadThread = this.downloadThread;
if (downloadThread != null) {
downloadThread.interrupt();
}
}
@Override

View file

@ -80,8 +80,6 @@ public abstract class SegmentDownloader<M extends FilterableManifest<M>> impleme
private final Executor executor;
private final AtomicBoolean isCanceled;
@Nullable private volatile Thread downloadThread;
/**
* @param mediaItem The {@link MediaItem} to be downloaded.
* @param manifestParser A parser for the manifest.
@ -107,10 +105,6 @@ public abstract class SegmentDownloader<M extends FilterableManifest<M>> impleme
@Override
public final void download(@Nullable ProgressListener progressListener) throws IOException {
downloadThread = Thread.currentThread();
if (isCanceled.get()) {
return;
}
@Nullable
PriorityTaskManager priorityTaskManager =
cacheDataSourceFactory.getUpstreamPriorityTaskManager();
@ -212,10 +206,6 @@ public abstract class SegmentDownloader<M extends FilterableManifest<M>> impleme
@Override
public void cancel() {
isCanceled.set(true);
@Nullable Thread downloadThread = this.downloadThread;
if (downloadThread != null) {
downloadThread.interrupt();
}
}
@Override