package androidx.media3.database; import android.content.ContentValues; import android.database.Cursor; import android.database.SQLException; import android.database.sqlite.SQLiteDatabase; import androidx.media3.common.MediaLibraryInfo; import androidx.media3.common.util.Util; /* loaded from: classes2.dex */ public final class VersionTable { private static final String COLUMN_FEATURE = "feature"; private static final String COLUMN_INSTANCE_UID = "instance_uid"; private static final String COLUMN_VERSION = "version"; public static final int FEATURE_CACHE_CONTENT_METADATA = 1; public static final int FEATURE_CACHE_FILE_METADATA = 2; public static final int FEATURE_EXTERNAL = 1000; public static final int FEATURE_OFFLINE = 0; private static final String PRIMARY_KEY = "PRIMARY KEY (feature, instance_uid)"; private static final String SQL_CREATE_TABLE_IF_NOT_EXISTS = "CREATE TABLE IF NOT EXISTS ExoPlayerVersions (feature INTEGER NOT NULL,instance_uid TEXT NOT NULL,version INTEGER NOT NULL,PRIMARY KEY (feature, instance_uid))"; private static final String TABLE_NAME = "ExoPlayerVersions"; public static final int VERSION_UNSET = -1; private static final String WHERE_FEATURE_AND_INSTANCE_UID_EQUALS = "feature = ? AND instance_uid = ?"; static { MediaLibraryInfo.registerModule("media3.database"); } private VersionTable() { } public static void setVersion(SQLiteDatabase sQLiteDatabase, int i, String str, int i2) throws DatabaseIOException { try { sQLiteDatabase.execSQL(SQL_CREATE_TABLE_IF_NOT_EXISTS); ContentValues contentValues = new ContentValues(); contentValues.put(COLUMN_FEATURE, Integer.valueOf(i)); contentValues.put(COLUMN_INSTANCE_UID, str); contentValues.put("version", Integer.valueOf(i2)); sQLiteDatabase.replaceOrThrow(TABLE_NAME, null, contentValues); } catch (SQLException e) { throw new DatabaseIOException(e); } } public static void removeVersion(SQLiteDatabase sQLiteDatabase, int i, String str) throws DatabaseIOException { try { if (Util.tableExists(sQLiteDatabase, TABLE_NAME)) { sQLiteDatabase.delete(TABLE_NAME, WHERE_FEATURE_AND_INSTANCE_UID_EQUALS, featureAndInstanceUidArguments(i, str)); } } catch (SQLException e) { throw new DatabaseIOException(e); } } public static int getVersion(SQLiteDatabase sQLiteDatabase, int i, String str) throws DatabaseIOException { try { if (!Util.tableExists(sQLiteDatabase, TABLE_NAME)) { return -1; } Cursor query = sQLiteDatabase.query(TABLE_NAME, new String[]{"version"}, WHERE_FEATURE_AND_INSTANCE_UID_EQUALS, featureAndInstanceUidArguments(i, str), null, null, null); try { if (query.getCount() == 0) { if (query != null) { query.close(); } return -1; } query.moveToNext(); int i2 = query.getInt(0); if (query != null) { query.close(); } return i2; } finally { } } catch (SQLException e) { throw new DatabaseIOException(e); } } private static String[] featureAndInstanceUidArguments(int i, String str) { return new String[]{Integer.toString(i), str}; } }