diff --git a/library/core/src/main/java/com/google/android/exoplayer2/offline/DownloadManager.java b/library/core/src/main/java/com/google/android/exoplayer2/offline/DownloadManager.java index 943fb9f834..6fb8307959 100644 --- a/library/core/src/main/java/com/google/android/exoplayer2/offline/DownloadManager.java +++ b/library/core/src/main/java/com/google/android/exoplayer2/offline/DownloadManager.java @@ -178,52 +178,6 @@ public final class DownloadManager { logd("Created"); } - /** - * Stops all of the tasks and releases resources. If the action file isn't up to date, waits for - * the changes to be written. The manager must not be accessed after this method has been called. - */ - public void release() { - if (released) { - return; - } - released = true; - for (int i = 0; i < tasks.size(); i++) { - tasks.get(i).stop(); - } - final ConditionVariable fileIOFinishedCondition = new ConditionVariable(); - fileIOHandler.post(new Runnable() { - @Override - public void run() { - fileIOFinishedCondition.open(); - } - }); - fileIOFinishedCondition.block(); - fileIOThread.quit(); - logd("Released"); - } - - /** Stops all of the download tasks. Call {@link #startDownloads()} to restart tasks. */ - public void stopDownloads() { - Assertions.checkState(!released); - if (!downloadsStopped) { - downloadsStopped = true; - for (int i = 0; i < activeDownloadTasks.size(); i++) { - activeDownloadTasks.get(i).stop(); - } - logd("Downloads are stopping"); - } - } - - /** Starts the download tasks. */ - public void startDownloads() { - Assertions.checkState(!released); - if (downloadsStopped) { - downloadsStopped = false; - maybeStartTasks(); - logd("Downloads are started"); - } - } - /** * Adds a {@link Listener}. * @@ -242,6 +196,28 @@ public final class DownloadManager { listeners.remove(listener); } + /** Starts the download tasks. */ + public void startDownloads() { + Assertions.checkState(!released); + if (downloadsStopped) { + downloadsStopped = false; + maybeStartTasks(); + logd("Downloads are started"); + } + } + + /** Stops all of the download tasks. Call {@link #startDownloads()} to restart tasks. */ + public void stopDownloads() { + Assertions.checkState(!released); + if (!downloadsStopped) { + downloadsStopped = true; + for (int i = 0; i < activeDownloadTasks.size(); i++) { + activeDownloadTasks.get(i).stop(); + } + logd("Downloads are stopping"); + } + } + /** * Deserializes an action from {@code actionData}, and calls {@link * #handleAction(DownloadAction)}. @@ -275,13 +251,6 @@ public final class DownloadManager { return task.id; } - private Task addTaskForAction(DownloadAction action) { - Task task = new Task(nextTaskId++, this, action, minRetryCount); - tasks.add(task); - logd("Task is added", task); - return task; - } - /** Returns the current number of tasks. */ public int getTaskCount() { Assertions.checkState(!released); @@ -324,6 +293,37 @@ public final class DownloadManager { return true; } + /** + * Stops all of the tasks and releases resources. If the action file isn't up to date, waits for + * the changes to be written. The manager must not be accessed after this method has been called. + */ + public void release() { + if (released) { + return; + } + released = true; + for (int i = 0; i < tasks.size(); i++) { + tasks.get(i).stop(); + } + final ConditionVariable fileIOFinishedCondition = new ConditionVariable(); + fileIOHandler.post(new Runnable() { + @Override + public void run() { + fileIOFinishedCondition.open(); + } + }); + fileIOFinishedCondition.block(); + fileIOThread.quit(); + logd("Released"); + } + + private Task addTaskForAction(DownloadAction action) { + Task task = new Task(nextTaskId++, this, action, minRetryCount); + tasks.add(task); + logd("Task is added", task); + return task; + } + /** * Iterates through the task queue and starts any task if all of the following are true: *