mirror of
https://github.com/androidx/media.git
synced 2025-05-10 00:59:51 +08:00
DownloadManager improvements
- Do requirements TODO - Add useful helper method to retrieve not met requirements - Fix WritableDownloadIndex Javadoc PiperOrigin-RevId: 245922903
This commit is contained in:
parent
6b34ade908
commit
4a5b8e17de
@ -173,6 +173,7 @@ public final class DownloadManager {
|
||||
private boolean downloadsPaused;
|
||||
private int maxParallelDownloads;
|
||||
private int minRetryCount;
|
||||
private int notMetRequirements;
|
||||
private RequirementsWatcher requirementsWatcher;
|
||||
|
||||
/**
|
||||
@ -212,7 +213,7 @@ public final class DownloadManager {
|
||||
requirementsListener = this::onRequirementsStateChanged;
|
||||
requirementsWatcher =
|
||||
new RequirementsWatcher(context, requirementsListener, DEFAULT_REQUIREMENTS);
|
||||
int notMetRequirements = requirementsWatcher.start();
|
||||
notMetRequirements = requirementsWatcher.start();
|
||||
|
||||
mainHandler = new Handler(Util.getLooper(), this::handleMainMessage);
|
||||
HandlerThread internalThread = new HandlerThread("DownloadManager file i/o");
|
||||
@ -274,11 +275,21 @@ public final class DownloadManager {
|
||||
listeners.remove(listener);
|
||||
}
|
||||
|
||||
/** Returns the requirements needed to be met to start downloads. */
|
||||
/** Returns the requirements needed to be met to progress. */
|
||||
public Requirements getRequirements() {
|
||||
return requirementsWatcher.getRequirements();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the requirements needed for downloads to progress that are not currently met.
|
||||
*
|
||||
* @return The not met {@link Requirements.RequirementFlags}, or 0 if all requirements are met.
|
||||
*/
|
||||
@Requirements.RequirementFlags
|
||||
public int getNotMetRequirements() {
|
||||
return getRequirements().getNotMetRequirements(context);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the requirements that need to be met for downloads to progress.
|
||||
*
|
||||
@ -413,7 +424,7 @@ public final class DownloadManager {
|
||||
* @param request The download request.
|
||||
*/
|
||||
public void addDownload(DownloadRequest request) {
|
||||
addDownload(request, Download.STOP_REASON_NONE);
|
||||
addDownload(request, STOP_REASON_NONE);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -478,6 +489,10 @@ public final class DownloadManager {
|
||||
for (Listener listener : listeners) {
|
||||
listener.onRequirementsStateChanged(this, requirements, notMetRequirements);
|
||||
}
|
||||
if (this.notMetRequirements == notMetRequirements) {
|
||||
return;
|
||||
}
|
||||
this.notMetRequirements = notMetRequirements;
|
||||
pendingMessages++;
|
||||
internalHandler
|
||||
.obtainMessage(MSG_SET_NOT_MET_REQUIREMENTS, notMetRequirements, /* unused */ 0)
|
||||
@ -747,10 +762,6 @@ public final class DownloadManager {
|
||||
}
|
||||
|
||||
private void setNotMetRequirements(@Requirements.RequirementFlags int notMetRequirements) {
|
||||
// TODO: Move this deduplication check to the main thread.
|
||||
if (this.notMetRequirements == notMetRequirements) {
|
||||
return;
|
||||
}
|
||||
this.notMetRequirements = notMetRequirements;
|
||||
logdFlags("Not met requirements are changed", notMetRequirements);
|
||||
for (int i = 0; i < downloadInternals.size(); i++) {
|
||||
|
@ -17,43 +17,43 @@ package com.google.android.exoplayer2.offline;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/** An writable index of {@link Download Downloads}. */
|
||||
/** A writable index of {@link Download Downloads}. */
|
||||
public interface WritableDownloadIndex extends DownloadIndex {
|
||||
|
||||
/**
|
||||
* Adds or replaces a {@link Download}.
|
||||
*
|
||||
* @param download The {@link Download} to be added.
|
||||
* @throws throws IOException If an error occurs setting the state.
|
||||
* @throws IOException If an error occurs setting the state.
|
||||
*/
|
||||
void putDownload(Download download) throws IOException;
|
||||
|
||||
/**
|
||||
* Removes the {@link Download} with the given {@code id}.
|
||||
* Removes the download with the given ID. Does nothing if a download with the given ID does not
|
||||
* exist.
|
||||
*
|
||||
* @param id ID of a {@link Download}.
|
||||
* @throws throws IOException If an error occurs removing the state.
|
||||
* @param id The ID of the download to remove.
|
||||
* @throws IOException If an error occurs removing the state.
|
||||
*/
|
||||
void removeDownload(String id) throws IOException;
|
||||
|
||||
/**
|
||||
* Sets the stop reason of the downloads in a terminal state ({@link Download#STATE_COMPLETED},
|
||||
* {@link Download#STATE_FAILED}).
|
||||
*
|
||||
* @param stopReason The stop reason.
|
||||
* @throws throws IOException If an error occurs updating the state.
|
||||
* @throws IOException If an error occurs updating the state.
|
||||
*/
|
||||
void setStopReason(int stopReason) throws IOException;
|
||||
|
||||
/**
|
||||
* Sets the stop reason of the download with the given {@code id} in a terminal state ({@link
|
||||
* Download#STATE_COMPLETED}, {@link Download#STATE_FAILED}).
|
||||
* Sets the stop reason of the download with the given ID in a terminal state ({@link
|
||||
* Download#STATE_COMPLETED}, {@link Download#STATE_FAILED}). Does nothing if a download with the
|
||||
* given ID does not exist, or if it's not in a terminal state.
|
||||
*
|
||||
* <p>If there's no {@link Download} with the given {@code id} or it isn't in a terminal state,
|
||||
* then nothing happens.
|
||||
*
|
||||
* @param id ID of a {@link Download}.
|
||||
* @param id The ID of the download to update.
|
||||
* @param stopReason The stop reason.
|
||||
* @throws throws IOException If an error occurs updating the state.
|
||||
* @throws IOException If an error occurs updating the state.
|
||||
*/
|
||||
void setStopReason(String id, int stopReason) throws IOException;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user