Small DownloadManager fixes
Fix suppressing initial "state changed to paused" listener invocations for new added tasks that are immediately started. Notify listeners for loaded actions queued state if they are not started immediately. ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=196542693
This commit is contained in:
parent
b3c3717007
commit
eb151a79e6
@ -33,6 +33,7 @@ import com.google.android.exoplayer2.offline.DownloadAction.Deserializer;
|
|||||||
import com.google.android.exoplayer2.upstream.DataSource;
|
import com.google.android.exoplayer2.upstream.DataSource;
|
||||||
import com.google.android.exoplayer2.upstream.cache.Cache;
|
import com.google.android.exoplayer2.upstream.cache.Cache;
|
||||||
import com.google.android.exoplayer2.util.Assertions;
|
import com.google.android.exoplayer2.util.Assertions;
|
||||||
|
import com.google.android.exoplayer2.util.Util;
|
||||||
import java.io.ByteArrayInputStream;
|
import java.io.ByteArrayInputStream;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
@ -250,7 +251,6 @@ public final class DownloadManager {
|
|||||||
Assertions.checkState(!released);
|
Assertions.checkState(!released);
|
||||||
Task task = addTaskForAction(action);
|
Task task = addTaskForAction(action);
|
||||||
if (initialized) {
|
if (initialized) {
|
||||||
notifyListenersTaskStateChange(task);
|
|
||||||
saveActions();
|
saveActions();
|
||||||
maybeStartTasks();
|
maybeStartTasks();
|
||||||
if (task.currentState == STATE_QUEUED) {
|
if (task.currentState == STATE_QUEUED) {
|
||||||
@ -413,7 +413,6 @@ public final class DownloadManager {
|
|||||||
if (released) {
|
if (released) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
logd("Task state is changed", task);
|
|
||||||
boolean stopped = !task.isActive();
|
boolean stopped = !task.isActive();
|
||||||
if (stopped) {
|
if (stopped) {
|
||||||
activeDownloadTasks.remove(task);
|
activeDownloadTasks.remove(task);
|
||||||
@ -430,6 +429,7 @@ public final class DownloadManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void notifyListenersTaskStateChange(Task task) {
|
private void notifyListenersTaskStateChange(Task task) {
|
||||||
|
logd("Task state is changed", task);
|
||||||
TaskState taskState = task.getDownloadState();
|
TaskState taskState = task.getDownloadState();
|
||||||
for (Listener listener : listeners) {
|
for (Listener listener : listeners) {
|
||||||
listener.onTaskStateChanged(this, taskState);
|
listener.onTaskStateChanged(this, taskState);
|
||||||
@ -468,18 +468,16 @@ public final class DownloadManager {
|
|||||||
listener.onInitialized(DownloadManager.this);
|
listener.onInitialized(DownloadManager.this);
|
||||||
}
|
}
|
||||||
if (!pendingTasks.isEmpty()) {
|
if (!pendingTasks.isEmpty()) {
|
||||||
for (int i = 0; i < pendingTasks.size(); i++) {
|
tasks.addAll(pendingTasks);
|
||||||
tasks.add(pendingTasks.get(i));
|
|
||||||
}
|
|
||||||
saveActions();
|
saveActions();
|
||||||
}
|
}
|
||||||
maybeStartTasks();
|
maybeStartTasks();
|
||||||
for (int i = 0; i < pendingTasks.size(); i++) {
|
for (int i = 0; i < tasks.size(); i++) {
|
||||||
Task pendingTask = pendingTasks.get(i);
|
Task task = tasks.get(i);
|
||||||
if (pendingTask.currentState == STATE_QUEUED) {
|
if (task.currentState == STATE_QUEUED) {
|
||||||
// Task did not change out of its initial state, and so its initial state
|
// Task did not change out of its initial state, and so its initial state
|
||||||
// won't have been reported to listeners. Do so now.
|
// won't have been reported to listeners. Do so now.
|
||||||
notifyListenersTaskStateChange(pendingTask);
|
notifyListenersTaskStateChange(task);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -699,9 +697,19 @@ public final class DownloadManager {
|
|||||||
+ ' '
|
+ ' '
|
||||||
+ (action.isRemoveAction ? "remove" : "download")
|
+ (action.isRemoveAction ? "remove" : "download")
|
||||||
+ ' '
|
+ ' '
|
||||||
|
+ toString(action.data)
|
||||||
|
+ ' '
|
||||||
+ getStateString();
|
+ getStateString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static String toString(byte[] data) {
|
||||||
|
if (data.length > 100) {
|
||||||
|
return "<data is too long>";
|
||||||
|
} else {
|
||||||
|
return '\'' + Util.fromUtf8Bytes(data) + '\'';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private String getStateString() {
|
private String getStateString() {
|
||||||
switch (currentState) {
|
switch (currentState) {
|
||||||
case STATE_QUEUED_CANCELING:
|
case STATE_QUEUED_CANCELING:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user