Commit 230a798f by eguven Committed by Oliver Woodman

Create only one task for all DownloadActions for the same content

PiperOrigin-RevId: 225060323
parent 05bfeca5
......@@ -25,6 +25,8 @@
skippping.
* Workaround for MiTV (dangal) issue when swapping output surface
([#5169](https://github.com/google/ExoPlayer/issues/5169)).
* DownloadManager:
* Create only one task for all DownloadActions for the same content.
### 2.9.2 ###
......
......@@ -17,7 +17,6 @@ package com.google.android.exoplayer2.testutil;
import static com.google.common.truth.Truth.assertThat;
import com.google.android.exoplayer2.offline.DownloadAction;
import com.google.android.exoplayer2.offline.DownloadManager;
import java.util.HashMap;
import java.util.concurrent.ArrayBlockingQueue;
......@@ -31,7 +30,7 @@ public final class TestDownloadManagerListener implements DownloadManager.Listen
private final DownloadManager downloadManager;
private final DummyMainThread dummyMainThread;
private final HashMap<DownloadAction, ArrayBlockingQueue<Integer>> actionStates;
private final HashMap<Integer, ArrayBlockingQueue<Integer>> actionStates;
private CountDownLatch downloadFinishedCondition;
private Throwable downloadError;
......@@ -43,8 +42,8 @@ public final class TestDownloadManagerListener implements DownloadManager.Listen
actionStates = new HashMap<>();
}
public int pollStateChange(DownloadAction action, long timeoutMs) throws InterruptedException {
return getStateQueue(action).poll(timeoutMs, TimeUnit.MILLISECONDS);
public Integer pollStateChange(int taskId, long timeoutMs) throws InterruptedException {
return getStateQueue(taskId).poll(timeoutMs, TimeUnit.MILLISECONDS);
}
public void clearDownloadError() {
......@@ -62,7 +61,7 @@ public final class TestDownloadManagerListener implements DownloadManager.Listen
if (taskState.state == DownloadManager.TaskState.STATE_FAILED && downloadError == null) {
downloadError = taskState.error;
}
getStateQueue(taskState.action).add(taskState.state);
getStateQueue(taskState.taskId).add(taskState.state);
}
@Override
......@@ -77,6 +76,14 @@ public final class TestDownloadManagerListener implements DownloadManager.Listen
* error.
*/
public void blockUntilTasksCompleteAndThrowAnyDownloadError() throws Throwable {
blockUntilTasksComplete();
if (downloadError != null) {
throw new Exception(downloadError);
}
}
/** Blocks until all remove and download tasks are complete. Task errors are ignored. */
public void blockUntilTasksComplete() throws InterruptedException {
synchronized (this) {
downloadFinishedCondition = new CountDownLatch(1);
}
......@@ -87,17 +94,14 @@ public final class TestDownloadManagerListener implements DownloadManager.Listen
}
});
assertThat(downloadFinishedCondition.await(TIMEOUT, TimeUnit.MILLISECONDS)).isTrue();
if (downloadError != null) {
throw new Exception(downloadError);
}
}
private ArrayBlockingQueue<Integer> getStateQueue(DownloadAction action) {
private ArrayBlockingQueue<Integer> getStateQueue(int taskId) {
synchronized (actionStates) {
if (!actionStates.containsKey(action)) {
actionStates.put(action, new ArrayBlockingQueue<>(10));
if (!actionStates.containsKey(taskId)) {
actionStates.put(taskId, new ArrayBlockingQueue<>(10));
}
return actionStates.get(action);
return actionStates.get(taskId);
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment