package com.baidu.cloud.videocache.sourcestorage; import android.content.ContentValues; import android.content.Context; import android.database.Cursor; import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteOpenHelper; import com.baidu.cloud.media.player.misc.IMediaFormat; import com.baidu.cloud.videocache.aa; import com.baidu.cloud.videocache.t; import com.liulishuo.filedownloader.model.FileDownloadModel; /* loaded from: classes.dex */ class a extends SQLiteOpenHelper implements SourceInfoStorage { private static final String[] a = {FileDownloadModel.ID, "url", "length", IMediaFormat.KEY_MIME}; a(Context context) { super(context, "AndroidVideoCache.db", (SQLiteDatabase.CursorFactory) null, 1); t.a(context); } private ContentValues a(aa aaVar) { ContentValues contentValues = new ContentValues(); contentValues.put("url", aaVar.a); contentValues.put("length", Long.valueOf(aaVar.b)); contentValues.put(IMediaFormat.KEY_MIME, aaVar.c); return contentValues; } private aa a(Cursor cursor) { return new aa(cursor.getString(cursor.getColumnIndexOrThrow("url")), cursor.getLong(cursor.getColumnIndexOrThrow("length")), cursor.getString(cursor.getColumnIndexOrThrow(IMediaFormat.KEY_MIME))); } @Override // com.baidu.cloud.videocache.sourcestorage.SourceInfoStorage public void a(String str, aa aaVar) { t.a(str, aaVar); boolean z = get(str) != null; ContentValues a2 = a(aaVar); if (z) { getWritableDatabase().update("SourceInfo", a2, "url=?", new String[]{str}); } else { getWritableDatabase().insert("SourceInfo", null, a2); } } @Override // com.baidu.cloud.videocache.sourcestorage.SourceInfoStorage public aa get(String str) { t.a(str); Cursor cursor = null; r0 = null; aa a2 = null; try { Cursor query = getReadableDatabase().query("SourceInfo", a, "url=?", new String[]{str}, null, null, null); if (query != null) { try { if (query.moveToFirst()) { a2 = a(query); } } catch (Throwable th) { cursor = query; th = th; if (cursor != null) { cursor.close(); } throw th; } } if (query != null) { query.close(); } return a2; } catch (Throwable th2) { th = th2; } } @Override // android.database.sqlite.SQLiteOpenHelper public void onCreate(SQLiteDatabase sQLiteDatabase) { t.a(sQLiteDatabase); sQLiteDatabase.execSQL("CREATE TABLE SourceInfo (_id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,url TEXT NOT NULL,mime TEXT,length INTEGER);"); } @Override // android.database.sqlite.SQLiteOpenHelper public void onUpgrade(SQLiteDatabase sQLiteDatabase, int i, int i2) { throw new IllegalStateException("Should not be called. There is no any migration"); } }