Commit b30efe96 by olly Committed by Oliver Woodman

Clean up database tables for launch

PiperOrigin-RevId: 244267255
parent 54a5d691
...@@ -107,7 +107,7 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull; ...@@ -107,7 +107,7 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
int version = int version =
VersionTable.getVersion( VersionTable.getVersion(
readableDatabase, VersionTable.FEATURE_CACHE_FILE_METADATA, hexUid); readableDatabase, VersionTable.FEATURE_CACHE_FILE_METADATA, hexUid);
if (version == VersionTable.VERSION_UNSET || version > TABLE_VERSION) { if (version != TABLE_VERSION) {
SQLiteDatabase writableDatabase = databaseProvider.getWritableDatabase(); SQLiteDatabase writableDatabase = databaseProvider.getWritableDatabase();
writableDatabase.beginTransaction(); writableDatabase.beginTransaction();
try { try {
...@@ -119,9 +119,6 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull; ...@@ -119,9 +119,6 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
} finally { } finally {
writableDatabase.endTransaction(); writableDatabase.endTransaction();
} }
} else if (version < TABLE_VERSION) {
// There is no previous version currently.
throw new IllegalStateException();
} }
} catch (SQLException e) { } catch (SQLException e) {
throw new DatabaseIOException(e); throw new DatabaseIOException(e);
......
...@@ -63,12 +63,8 @@ import org.checkerframework.checker.nullness.compatqual.NullableType; ...@@ -63,12 +63,8 @@ import org.checkerframework.checker.nullness.compatqual.NullableType;
/* package */ static final String FILE_NAME_ATOMIC = "cached_content_index.exi"; /* package */ static final String FILE_NAME_ATOMIC = "cached_content_index.exi";
private static final int VERSION = 2;
private static final int VERSION_METADATA_INTRODUCED = 2;
private static final int INCREMENTAL_METADATA_READ_LENGTH = 10 * 1024 * 1024; private static final int INCREMENTAL_METADATA_READ_LENGTH = 10 * 1024 * 1024;
private static final int FLAG_ENCRYPTED_INDEX = 1;
private final HashMap<String, CachedContent> keyToContent; private final HashMap<String, CachedContent> keyToContent;
/** /**
* Maps assigned ids to their corresponding keys. Also contains (id -> null) entries for ids that * Maps assigned ids to their corresponding keys. Also contains (id -> null) entries for ids that
...@@ -464,6 +460,10 @@ import org.checkerframework.checker.nullness.compatqual.NullableType; ...@@ -464,6 +460,10 @@ import org.checkerframework.checker.nullness.compatqual.NullableType;
/** {@link Storage} implementation that uses an {@link AtomicFile}. */ /** {@link Storage} implementation that uses an {@link AtomicFile}. */
private static class LegacyStorage implements Storage { private static class LegacyStorage implements Storage {
private static final int VERSION = 2;
private static final int VERSION_METADATA_INTRODUCED = 2;
private static final int FLAG_ENCRYPTED_INDEX = 1;
private final boolean encrypt; private final boolean encrypt;
@Nullable private final Cipher cipher; @Nullable private final Cipher cipher;
@Nullable private final SecretKeySpec secretKeySpec; @Nullable private final SecretKeySpec secretKeySpec;
...@@ -770,7 +770,7 @@ import org.checkerframework.checker.nullness.compatqual.NullableType; ...@@ -770,7 +770,7 @@ import org.checkerframework.checker.nullness.compatqual.NullableType;
databaseProvider.getReadableDatabase(), databaseProvider.getReadableDatabase(),
VersionTable.FEATURE_CACHE_CONTENT_METADATA, VersionTable.FEATURE_CACHE_CONTENT_METADATA,
hexUid); hexUid);
if (version == VersionTable.VERSION_UNSET || version > TABLE_VERSION) { if (version != TABLE_VERSION) {
SQLiteDatabase writableDatabase = databaseProvider.getWritableDatabase(); SQLiteDatabase writableDatabase = databaseProvider.getWritableDatabase();
writableDatabase.beginTransaction(); writableDatabase.beginTransaction();
try { try {
...@@ -779,9 +779,6 @@ import org.checkerframework.checker.nullness.compatqual.NullableType; ...@@ -779,9 +779,6 @@ import org.checkerframework.checker.nullness.compatqual.NullableType;
} finally { } finally {
writableDatabase.endTransaction(); writableDatabase.endTransaction();
} }
} else if (version < TABLE_VERSION) {
// There is no previous version currently.
throw new IllegalStateException();
} }
try (Cursor cursor = getCursor()) { try (Cursor cursor = getCursor()) {
......
...@@ -32,7 +32,7 @@ import org.junit.runner.RunWith; ...@@ -32,7 +32,7 @@ import org.junit.runner.RunWith;
@RunWith(AndroidJUnit4.class) @RunWith(AndroidJUnit4.class)
public class DefaultDownloadIndexTest { public class DefaultDownloadIndexTest {
private static final String EMPTY_NAME = "singleton"; private static final String EMPTY_NAME = "";
private ExoDatabaseProvider databaseProvider; private ExoDatabaseProvider databaseProvider;
private DefaultDownloadIndex downloadIndex; private DefaultDownloadIndex downloadIndex;
......
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