|
26 | 26 | import com.google.android.exoplayer2.database.DatabaseIOException;
|
27 | 27 | import com.google.android.exoplayer2.database.DatabaseProvider;
|
28 | 28 | import com.google.android.exoplayer2.database.VersionTable;
|
| 29 | +import com.google.android.exoplayer2.offline.Download.FailureReason; |
| 30 | +import com.google.android.exoplayer2.offline.Download.State; |
29 | 31 | import com.google.android.exoplayer2.util.Assertions;
|
30 | 32 | import com.google.android.exoplayer2.util.Util;
|
31 | 33 | import java.util.ArrayList;
|
@@ -239,6 +241,9 @@ public void setStatesToRemoving() throws DatabaseIOException {
|
239 | 241 | try {
|
240 | 242 | ContentValues values = new ContentValues();
|
241 | 243 | values.put(COLUMN_STATE, Download.STATE_REMOVING);
|
| 244 | + // Only downloads in STATE_FAILED are allowed a failure reason, so we need to clear it here in |
| 245 | + // case we're moving downloads from STATE_FAILED to STATE_REMOVING. |
| 246 | + values.put(COLUMN_FAILURE_REASON, Download.FAILURE_REASON_NONE); |
242 | 247 | SQLiteDatabase writableDatabase = databaseProvider.getWritableDatabase();
|
243 | 248 | writableDatabase.update(tableName, values, /* whereClause= */ null, /* whereArgs= */ null);
|
244 | 249 | } catch (SQLException e) {
|
@@ -351,14 +356,22 @@ private static Download getDownloadForCurrentRow(Cursor cursor) {
|
351 | 356 | DownloadProgress downloadProgress = new DownloadProgress();
|
352 | 357 | downloadProgress.bytesDownloaded = cursor.getLong(COLUMN_INDEX_BYTES_DOWNLOADED);
|
353 | 358 | downloadProgress.percentDownloaded = cursor.getFloat(COLUMN_INDEX_PERCENT_DOWNLOADED);
|
| 359 | + @State int state = cursor.getInt(COLUMN_INDEX_STATE); |
| 360 | + // It's possible the database contains failure reasons for non-failed downloads, which is |
| 361 | + // invalid. Clear them here. See https://github.com/google/ExoPlayer/issues/6785. |
| 362 | + @FailureReason |
| 363 | + int failureReason = |
| 364 | + state == Download.STATE_FAILED |
| 365 | + ? cursor.getInt(COLUMN_INDEX_FAILURE_REASON) |
| 366 | + : Download.FAILURE_REASON_NONE; |
354 | 367 | return new Download(
|
355 | 368 | request,
|
356 |
| - /* state= */ cursor.getInt(COLUMN_INDEX_STATE), |
| 369 | + state, |
357 | 370 | /* startTimeMs= */ cursor.getLong(COLUMN_INDEX_START_TIME_MS),
|
358 | 371 | /* updateTimeMs= */ cursor.getLong(COLUMN_INDEX_UPDATE_TIME_MS),
|
359 | 372 | /* contentLength= */ cursor.getLong(COLUMN_INDEX_CONTENT_LENGTH),
|
360 | 373 | /* stopReason= */ cursor.getInt(COLUMN_INDEX_STOP_REASON),
|
361 |
| - /* failureReason= */ cursor.getInt(COLUMN_INDEX_FAILURE_REASON), |
| 374 | + failureReason, |
362 | 375 | downloadProgress);
|
363 | 376 | }
|
364 | 377 |
|
|
0 commit comments