Fix nullness checks for addition of Cursor.getString stub
PiperOrigin-RevId: 377298145
This commit is contained in:
parent
b0a3bc5b28
commit
2b6581afe0
@ -15,12 +15,15 @@
|
|||||||
*/
|
*/
|
||||||
package com.google.android.exoplayer2.offline;
|
package com.google.android.exoplayer2.offline;
|
||||||
|
|
||||||
|
import static com.google.android.exoplayer2.util.Assertions.checkNotNull;
|
||||||
|
|
||||||
import android.content.ContentValues;
|
import android.content.ContentValues;
|
||||||
import android.database.Cursor;
|
import android.database.Cursor;
|
||||||
import android.database.SQLException;
|
import android.database.SQLException;
|
||||||
import android.database.sqlite.SQLiteDatabase;
|
import android.database.sqlite.SQLiteDatabase;
|
||||||
import android.database.sqlite.SQLiteException;
|
import android.database.sqlite.SQLiteException;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
|
import android.text.TextUtils;
|
||||||
import androidx.annotation.GuardedBy;
|
import androidx.annotation.GuardedBy;
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
import androidx.annotation.VisibleForTesting;
|
import androidx.annotation.VisibleForTesting;
|
||||||
@ -371,7 +374,7 @@ public final class DefaultDownloadIndex implements WritableDownloadIndex {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** Infers the MIME type from a v2 table row. */
|
/** Infers the MIME type from a v2 table row. */
|
||||||
private static String inferMimeType(String downloadType) {
|
private static String inferMimeType(@Nullable String downloadType) {
|
||||||
if ("dash".equals(downloadType)) {
|
if ("dash".equals(downloadType)) {
|
||||||
return MimeTypes.APPLICATION_MPD;
|
return MimeTypes.APPLICATION_MPD;
|
||||||
} else if ("hls".equals(downloadType)) {
|
} else if ("hls".equals(downloadType)) {
|
||||||
@ -441,8 +444,8 @@ public final class DefaultDownloadIndex implements WritableDownloadIndex {
|
|||||||
byte[] keySetId = cursor.getBlob(COLUMN_INDEX_KEY_SET_ID);
|
byte[] keySetId = cursor.getBlob(COLUMN_INDEX_KEY_SET_ID);
|
||||||
DownloadRequest request =
|
DownloadRequest request =
|
||||||
new DownloadRequest.Builder(
|
new DownloadRequest.Builder(
|
||||||
/* id= */ cursor.getString(COLUMN_INDEX_ID),
|
/* id= */ checkNotNull(cursor.getString(COLUMN_INDEX_ID)),
|
||||||
/* uri= */ Uri.parse(cursor.getString(COLUMN_INDEX_URI)))
|
/* uri= */ Uri.parse(checkNotNull(cursor.getString(COLUMN_INDEX_URI))))
|
||||||
.setMimeType(cursor.getString(COLUMN_INDEX_MIME_TYPE))
|
.setMimeType(cursor.getString(COLUMN_INDEX_MIME_TYPE))
|
||||||
.setStreamKeys(decodeStreamKeys(cursor.getString(COLUMN_INDEX_STREAM_KEYS)))
|
.setStreamKeys(decodeStreamKeys(cursor.getString(COLUMN_INDEX_STREAM_KEYS)))
|
||||||
.setKeySetId(keySetId.length > 0 ? keySetId : null)
|
.setKeySetId(keySetId.length > 0 ? keySetId : null)
|
||||||
@ -493,7 +496,8 @@ public final class DefaultDownloadIndex implements WritableDownloadIndex {
|
|||||||
*/
|
*/
|
||||||
DownloadRequest request =
|
DownloadRequest request =
|
||||||
new DownloadRequest.Builder(
|
new DownloadRequest.Builder(
|
||||||
/* id= */ cursor.getString(0), /* uri= */ Uri.parse(cursor.getString(2)))
|
/* id= */ checkNotNull(cursor.getString(0)),
|
||||||
|
/* uri= */ Uri.parse(checkNotNull(cursor.getString(2))))
|
||||||
.setMimeType(inferMimeType(cursor.getString(1)))
|
.setMimeType(inferMimeType(cursor.getString(1)))
|
||||||
.setStreamKeys(decodeStreamKeys(cursor.getString(3)))
|
.setStreamKeys(decodeStreamKeys(cursor.getString(3)))
|
||||||
.setCustomCacheKey(cursor.getString(4))
|
.setCustomCacheKey(cursor.getString(4))
|
||||||
@ -519,9 +523,9 @@ public final class DefaultDownloadIndex implements WritableDownloadIndex {
|
|||||||
downloadProgress);
|
downloadProgress);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static List<StreamKey> decodeStreamKeys(String encodedStreamKeys) {
|
private static List<StreamKey> decodeStreamKeys(@Nullable String encodedStreamKeys) {
|
||||||
ArrayList<StreamKey> streamKeys = new ArrayList<>();
|
ArrayList<StreamKey> streamKeys = new ArrayList<>();
|
||||||
if (encodedStreamKeys.isEmpty()) {
|
if (TextUtils.isEmpty(encodedStreamKeys)) {
|
||||||
return streamKeys;
|
return streamKeys;
|
||||||
}
|
}
|
||||||
String[] streamKeysStrings = Util.split(encodedStreamKeys, ",");
|
String[] streamKeysStrings = Util.split(encodedStreamKeys, ",");
|
||||||
|
@ -15,6 +15,8 @@
|
|||||||
*/
|
*/
|
||||||
package com.google.android.exoplayer2.upstream.cache;
|
package com.google.android.exoplayer2.upstream.cache;
|
||||||
|
|
||||||
|
import static com.google.android.exoplayer2.util.Assertions.checkNotNull;
|
||||||
|
|
||||||
import android.content.ContentValues;
|
import android.content.ContentValues;
|
||||||
import android.database.Cursor;
|
import android.database.Cursor;
|
||||||
import android.database.SQLException;
|
import android.database.SQLException;
|
||||||
@ -146,7 +148,7 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
|
|||||||
try (Cursor cursor = getCursor()) {
|
try (Cursor cursor = getCursor()) {
|
||||||
Map<String, CacheFileMetadata> fileMetadata = new HashMap<>(cursor.getCount());
|
Map<String, CacheFileMetadata> fileMetadata = new HashMap<>(cursor.getCount());
|
||||||
while (cursor.moveToNext()) {
|
while (cursor.moveToNext()) {
|
||||||
String name = cursor.getString(COLUMN_INDEX_NAME);
|
String name = checkNotNull(cursor.getString(COLUMN_INDEX_NAME));
|
||||||
long length = cursor.getLong(COLUMN_INDEX_LENGTH);
|
long length = cursor.getLong(COLUMN_INDEX_LENGTH);
|
||||||
long lastTouchTimestamp = cursor.getLong(COLUMN_INDEX_LAST_TOUCH_TIMESTAMP);
|
long lastTouchTimestamp = cursor.getLong(COLUMN_INDEX_LAST_TOUCH_TIMESTAMP);
|
||||||
fileMetadata.put(name, new CacheFileMetadata(length, lastTouchTimestamp));
|
fileMetadata.put(name, new CacheFileMetadata(length, lastTouchTimestamp));
|
||||||
|
@ -832,7 +832,7 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
|
|||||||
try (Cursor cursor = getCursor()) {
|
try (Cursor cursor = getCursor()) {
|
||||||
while (cursor.moveToNext()) {
|
while (cursor.moveToNext()) {
|
||||||
int id = cursor.getInt(COLUMN_INDEX_ID);
|
int id = cursor.getInt(COLUMN_INDEX_ID);
|
||||||
String key = cursor.getString(COLUMN_INDEX_KEY);
|
String key = checkNotNull(cursor.getString(COLUMN_INDEX_KEY));
|
||||||
byte[] metadataBytes = cursor.getBlob(COLUMN_INDEX_METADATA);
|
byte[] metadataBytes = cursor.getBlob(COLUMN_INDEX_METADATA);
|
||||||
|
|
||||||
ByteArrayInputStream inputStream = new ByteArrayInputStream(metadataBytes);
|
ByteArrayInputStream inputStream = new ByteArrayInputStream(metadataBytes);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user