Commit c3282c9a by sravan1213

Propagate download exception through onDownloadChanged callback

parent 226583f0
...@@ -20,6 +20,7 @@ import static com.google.android.exoplayer2.demo.DemoApplication.DOWNLOAD_NOTIFI ...@@ -20,6 +20,7 @@ import static com.google.android.exoplayer2.demo.DemoApplication.DOWNLOAD_NOTIFI
import android.app.Notification; import android.app.Notification;
import android.content.Context; import android.content.Context;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import com.google.android.exoplayer2.offline.Download; import com.google.android.exoplayer2.offline.Download;
import com.google.android.exoplayer2.offline.DownloadManager; import com.google.android.exoplayer2.offline.DownloadManager;
import com.google.android.exoplayer2.offline.DownloadService; import com.google.android.exoplayer2.offline.DownloadService;
...@@ -94,7 +95,8 @@ public class DemoDownloadService extends DownloadService { ...@@ -94,7 +95,8 @@ public class DemoDownloadService extends DownloadService {
} }
@Override @Override
public void onDownloadChanged(@NonNull DownloadManager manager, @NonNull Download download) { public void onDownloadChanged(
DownloadManager downloadManager, Download download, @Nullable Throwable error) {
Notification notification; Notification notification;
if (download.state == Download.STATE_COMPLETED) { if (download.state == Download.STATE_COMPLETED) {
notification = notification =
......
...@@ -126,7 +126,9 @@ public class DownloadTracker { ...@@ -126,7 +126,9 @@ public class DownloadTracker {
@Override @Override
public void onDownloadChanged( public void onDownloadChanged(
@NonNull DownloadManager downloadManager, @NonNull Download download) { @NonNull DownloadManager downloadManager,
@NonNull Download download,
@Nullable Throwable error) {
downloads.put(download.request.uri, download); downloads.put(download.request.uri, download);
for (Listener listener : listeners) { for (Listener listener : listeners) {
listener.onDownloadsChanged(); listener.onDownloadsChanged();
......
...@@ -93,8 +93,10 @@ public final class DownloadManager { ...@@ -93,8 +93,10 @@ public final class DownloadManager {
* *
* @param downloadManager The reporting instance. * @param downloadManager The reporting instance.
* @param download The state of the download. * @param download The state of the download.
* @param error exception occurred when a download is failed
*/ */
default void onDownloadChanged(DownloadManager downloadManager, Download download) {} default void onDownloadChanged(
DownloadManager downloadManager, Download download, @Nullable Throwable error) {}
/** /**
* Called when a download is removed. * Called when a download is removed.
...@@ -614,7 +616,7 @@ public final class DownloadManager { ...@@ -614,7 +616,7 @@ public final class DownloadManager {
} }
} else { } else {
for (Listener listener : listeners) { for (Listener listener : listeners) {
listener.onDownloadChanged(this, updatedDownload); listener.onDownloadChanged(this, updatedDownload, update.error);
} }
} }
if (waitingForRequirementsChanged) { if (waitingForRequirementsChanged) {
...@@ -906,7 +908,7 @@ public final class DownloadManager { ...@@ -906,7 +908,7 @@ public final class DownloadManager {
ArrayList<Download> updateList = new ArrayList<>(downloads); ArrayList<Download> updateList = new ArrayList<>(downloads);
for (int i = 0; i < downloads.size(); i++) { for (int i = 0; i < downloads.size(); i++) {
DownloadUpdate update = DownloadUpdate update =
new DownloadUpdate(downloads.get(i), /* isRemove= */ false, updateList); new DownloadUpdate(downloads.get(i), /* isRemove= */ false, updateList, null);
mainHandler.obtainMessage(MSG_DOWNLOAD_UPDATE, update).sendToTarget(); mainHandler.obtainMessage(MSG_DOWNLOAD_UPDATE, update).sendToTarget();
} }
syncTasks(); syncTasks();
...@@ -1121,7 +1123,11 @@ public final class DownloadManager { ...@@ -1121,7 +1123,11 @@ public final class DownloadManager {
Log.e(TAG, "Failed to update index.", e); Log.e(TAG, "Failed to update index.", e);
} }
DownloadUpdate update = DownloadUpdate update =
new DownloadUpdate(download, /* isRemove= */ false, new ArrayList<>(downloads)); new DownloadUpdate(
download,
/* isRemove= */ false,
new ArrayList<>(downloads),
finalError);
mainHandler.obtainMessage(MSG_DOWNLOAD_UPDATE, update).sendToTarget(); mainHandler.obtainMessage(MSG_DOWNLOAD_UPDATE, update).sendToTarget();
} }
...@@ -1139,7 +1145,7 @@ public final class DownloadManager { ...@@ -1139,7 +1145,7 @@ public final class DownloadManager {
Log.e(TAG, "Failed to remove from database"); Log.e(TAG, "Failed to remove from database");
} }
DownloadUpdate update = DownloadUpdate update =
new DownloadUpdate(download, /* isRemove= */ true, new ArrayList<>(downloads)); new DownloadUpdate(download, /* isRemove= */ true, new ArrayList<>(downloads), null);
mainHandler.obtainMessage(MSG_DOWNLOAD_UPDATE, update).sendToTarget(); mainHandler.obtainMessage(MSG_DOWNLOAD_UPDATE, update).sendToTarget();
} }
} }
...@@ -1194,7 +1200,7 @@ public final class DownloadManager { ...@@ -1194,7 +1200,7 @@ public final class DownloadManager {
Log.e(TAG, "Failed to update index.", e); Log.e(TAG, "Failed to update index.", e);
} }
DownloadUpdate update = DownloadUpdate update =
new DownloadUpdate(download, /* isRemove= */ false, new ArrayList<>(downloads)); new DownloadUpdate(download, /* isRemove= */ false, new ArrayList<>(downloads), null);
mainHandler.obtainMessage(MSG_DOWNLOAD_UPDATE, update).sendToTarget(); mainHandler.obtainMessage(MSG_DOWNLOAD_UPDATE, update).sendToTarget();
return download; return download;
} }
...@@ -1355,11 +1361,14 @@ public final class DownloadManager { ...@@ -1355,11 +1361,14 @@ public final class DownloadManager {
public final Download download; public final Download download;
public final boolean isRemove; public final boolean isRemove;
public final List<Download> downloads; public final List<Download> downloads;
@Nullable public final Throwable error;
public DownloadUpdate(Download download, boolean isRemove, List<Download> downloads) { public DownloadUpdate(
Download download, boolean isRemove, List<Download> downloads, @Nullable Throwable error) {
this.download = download; this.download = download;
this.isRemove = isRemove; this.isRemove = isRemove;
this.downloads = downloads; this.downloads = downloads;
this.error = error;
} }
} }
} }
...@@ -974,7 +974,8 @@ public abstract class DownloadService extends Service { ...@@ -974,7 +974,8 @@ public abstract class DownloadService extends Service {
} }
@Override @Override
public void onDownloadChanged(DownloadManager downloadManager, Download download) { public void onDownloadChanged(
DownloadManager downloadManager, Download download, @Nullable Throwable throwable) {
if (downloadService != null) { if (downloadService != null) {
downloadService.notifyDownloadChanged(download); downloadService.notifyDownloadChanged(download);
} }
......
...@@ -100,7 +100,8 @@ public final class TestDownloadManagerListener implements DownloadManager.Listen ...@@ -100,7 +100,8 @@ public final class TestDownloadManagerListener implements DownloadManager.Listen
} }
@Override @Override
public void onDownloadChanged(DownloadManager downloadManager, Download download) { public void onDownloadChanged(
DownloadManager downloadManager, Download download, @Nullable Throwable error) {
if (download.state == Download.STATE_FAILED) { if (download.state == Download.STATE_FAILED) {
failureReason = download.failureReason; failureReason = download.failureReason;
} }
......
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