use of androidx.media3.database.DatabaseIOException in project media by androidx.
the class DefaultDownloadIndexTest method addAndGetDownload_existingId_returnsUpdatedDownload.
@Test
public void addAndGetDownload_existingId_returnsUpdatedDownload() throws DatabaseIOException {
String id = "id";
DownloadBuilder downloadBuilder = new DownloadBuilder(id);
downloadIndex.putDownload(downloadBuilder.build());
Download download = downloadBuilder.setUri("different uri").setMimeType(MimeTypes.APPLICATION_MP4).setCacheKey("different cacheKey").setState(Download.STATE_FAILED).setPercentDownloaded(50).setBytesDownloaded(200).setContentLength(400).setFailureReason(FAILURE_REASON_UNKNOWN).setStopReason(0x12345678).setStartTimeMs(10).setUpdateTimeMs(20).setStreamKeys(new StreamKey(/* periodIndex= */
0, /* groupIndex= */
1, /* trackIndex= */
2), new StreamKey(/* periodIndex= */
3, /* groupIndex= */
4, /* trackIndex= */
5)).setCustomMetadata(new byte[] { 0, 1, 2, 3, 7, 8, 9, 10 }).setKeySetId(new byte[] { 0, 1, 2, 3 }).build();
downloadIndex.putDownload(download);
Download readDownload = downloadIndex.getDownload(id);
assertThat(readDownload).isNotNull();
assertEqual(readDownload, download);
}
use of androidx.media3.database.DatabaseIOException in project media by androidx.
the class DefaultDownloadIndexTest method getDownloads_withStates_returnsAllDownloadStatusWithTheSameStates.
@Test
public void getDownloads_withStates_returnsAllDownloadStatusWithTheSameStates() throws DatabaseIOException {
Download download1 = new DownloadBuilder("id1").setStartTimeMs(0).setState(Download.STATE_REMOVING).build();
downloadIndex.putDownload(download1);
Download download2 = new DownloadBuilder("id2").setStartTimeMs(1).setState(STATE_STOPPED).build();
downloadIndex.putDownload(download2);
Download download3 = new DownloadBuilder("id3").setStartTimeMs(2).setState(Download.STATE_COMPLETED).build();
downloadIndex.putDownload(download3);
try (DownloadCursor cursor = downloadIndex.getDownloads(Download.STATE_REMOVING, Download.STATE_COMPLETED)) {
assertThat(cursor.getCount()).isEqualTo(2);
cursor.moveToNext();
assertEqual(cursor.getDownload(), download1);
cursor.moveToNext();
assertEqual(cursor.getDownload(), download3);
}
}
use of androidx.media3.database.DatabaseIOException in project media by androidx.
the class DefaultDownloadIndexTest method releaseAndRecreateDownloadIndex_returnsTheSameDownload.
@Test
public void releaseAndRecreateDownloadIndex_returnsTheSameDownload() throws DatabaseIOException {
String id = "id";
Download download = new DownloadBuilder(id).build();
downloadIndex.putDownload(download);
downloadIndex = new DefaultDownloadIndex(databaseProvider);
Download readDownload = downloadIndex.getDownload(id);
assertThat(readDownload).isNotNull();
assertEqual(readDownload, download);
}
use of androidx.media3.database.DatabaseIOException in project ExoPlayer by google.
the class DefaultDownloadIndex method setStatesToRemoving.
@Override
public void setStatesToRemoving() throws DatabaseIOException {
ensureInitialized();
try {
ContentValues values = new ContentValues();
values.put(COLUMN_STATE, Download.STATE_REMOVING);
// Only downloads in STATE_FAILED are allowed a failure reason, so we need to clear it here in
// case we're moving downloads from STATE_FAILED to STATE_REMOVING.
values.put(COLUMN_FAILURE_REASON, Download.FAILURE_REASON_NONE);
SQLiteDatabase writableDatabase = databaseProvider.getWritableDatabase();
writableDatabase.update(tableName, values, /* whereClause= */
null, /* whereArgs= */
null);
} catch (SQLException e) {
throw new DatabaseIOException(e);
}
}
use of androidx.media3.database.DatabaseIOException in project ExoPlayer by google.
the class DefaultDownloadIndex method putDownload.
@Override
public void putDownload(Download download) throws DatabaseIOException {
ensureInitialized();
try {
SQLiteDatabase writableDatabase = databaseProvider.getWritableDatabase();
putDownloadInternal(download, writableDatabase);
} catch (SQLiteException e) {
throw new DatabaseIOException(e);
}
}
Aggregations