2021-07-24 02:37:17 +00:00
package c.i.a.c.h2.y ;
import android.content.ContentValues ;
import android.database.Cursor ;
import android.database.SQLException ;
import android.database.sqlite.SQLiteDatabase ;
import androidx.annotation.WorkerThread ;
import c.i.a.c.w1.a ;
import com.airbnb.lottie.parser.AnimatableValueParser ;
import com.google.android.exoplayer2.database.DatabaseIOException ;
import java.util.HashMap ;
import java.util.Iterator ;
import java.util.Map ;
import java.util.Objects ;
import java.util.Set ;
/* compiled from: CacheFileMetadataIndex */
public final class f {
public static final String [ ] a = { " name " , " length " , " last_touch_timestamp " } ;
public final a b ;
/* renamed from: c reason: collision with root package name */
2021-07-28 07:39:21 +00:00
public String f895c ;
2021-07-24 02:37:17 +00:00
public f ( a aVar ) {
this . b = aVar ;
}
/ * JADX WARNING : Code restructure failed : missing block : B : 12 : 0x0045 , code lost :
r2 = move - exception ;
* /
/ * JADX WARNING : Code restructure failed : missing block : B : 13 : 0x0046 , code lost :
if ( r0 ! = null ) goto L_0x0048 ;
* /
/ * JADX WARNING : Code restructure failed : missing block : B : 15 : ? , code lost :
r0 . close ( ) ;
* /
/ * JADX WARNING : Code restructure failed : missing block : B : 16 : 0x004c , code lost :
r0 = move - exception ;
* /
/ * JADX WARNING : Code restructure failed : missing block : B : 17 : 0x004d , code lost :
r1 . addSuppressed ( r0 ) ;
* /
/ * JADX WARNING : Code restructure failed : missing block : B : 18 : 0x0050 , code lost :
throw r2 ;
* /
@WorkerThread
public Map < String , e > a ( ) throws DatabaseIOException {
try {
2021-07-28 07:39:21 +00:00
Objects . requireNonNull ( this . f895c ) ;
Cursor query = this . b . getReadableDatabase ( ) . query ( this . f895c , a , null , null , null , null , null ) ;
2021-07-24 02:37:17 +00:00
HashMap hashMap = new HashMap ( query . getCount ( ) ) ;
while ( query . moveToNext ( ) ) {
hashMap . put ( query . getString ( 0 ) , new e ( query . getLong ( 1 ) , query . getLong ( 2 ) ) ) ;
}
query . close ( ) ;
return hashMap ;
} catch ( SQLException e ) {
throw new DatabaseIOException ( e ) ;
}
}
@WorkerThread
public void b ( long j ) throws DatabaseIOException {
try {
String hexString = Long . toHexString ( j ) ;
2021-07-28 07:39:21 +00:00
this . f895c = " ExoPlayerCacheFileMetadata " + hexString ;
2021-07-24 02:37:17 +00:00
if ( AnimatableValueParser . Q0 ( this . b . getReadableDatabase ( ) , 2 , hexString ) ! = 1 ) {
SQLiteDatabase writableDatabase = this . b . getWritableDatabase ( ) ;
writableDatabase . beginTransactionNonExclusive ( ) ;
try {
AnimatableValueParser . A2 ( writableDatabase , 2 , hexString , 1 ) ;
2021-07-28 07:39:21 +00:00
String str = this . f895c ;
2021-07-24 02:37:17 +00:00
writableDatabase . execSQL ( " DROP TABLE IF EXISTS " + str ) ;
2021-07-28 07:39:21 +00:00
writableDatabase . execSQL ( " CREATE TABLE " + this . f895c + " (name TEXT PRIMARY KEY NOT NULL,length INTEGER NOT NULL,last_touch_timestamp INTEGER NOT NULL) " ) ;
2021-07-24 02:37:17 +00:00
writableDatabase . setTransactionSuccessful ( ) ;
} finally {
writableDatabase . endTransaction ( ) ;
}
}
} catch ( SQLException e ) {
throw new DatabaseIOException ( e ) ;
}
}
@WorkerThread
public void c ( Set < String > set ) throws DatabaseIOException {
2021-07-28 07:39:21 +00:00
Objects . requireNonNull ( this . f895c ) ;
2021-07-24 02:37:17 +00:00
try {
SQLiteDatabase writableDatabase = this . b . getWritableDatabase ( ) ;
writableDatabase . beginTransactionNonExclusive ( ) ;
try {
Iterator < String > it = set . iterator ( ) ;
while ( it . hasNext ( ) ) {
2021-07-28 07:39:21 +00:00
writableDatabase . delete ( this . f895c , " name = ? " , new String [ ] { it . next ( ) } ) ;
2021-07-24 02:37:17 +00:00
}
writableDatabase . setTransactionSuccessful ( ) ;
} finally {
writableDatabase . endTransaction ( ) ;
}
} catch ( SQLException e ) {
throw new DatabaseIOException ( e ) ;
}
}
@WorkerThread
public void d ( String str , long j , long j2 ) throws DatabaseIOException {
2021-07-28 07:39:21 +00:00
Objects . requireNonNull ( this . f895c ) ;
2021-07-24 02:37:17 +00:00
try {
SQLiteDatabase writableDatabase = this . b . getWritableDatabase ( ) ;
ContentValues contentValues = new ContentValues ( ) ;
contentValues . put ( " name " , str ) ;
contentValues . put ( " length " , Long . valueOf ( j ) ) ;
contentValues . put ( " last_touch_timestamp " , Long . valueOf ( j2 ) ) ;
2021-07-28 07:39:21 +00:00
writableDatabase . replaceOrThrow ( this . f895c , null , contentValues ) ;
2021-07-24 02:37:17 +00:00
} catch ( SQLException e ) {
throw new DatabaseIOException ( e ) ;
}
}
}